mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-20 20:07:03 +01:00
fix #676
This commit is contained in:
parent
82da024a4d
commit
5338808600
2 changed files with 17 additions and 4 deletions
|
@ -417,6 +417,13 @@ func ChangeUserName(u *User, newUserName string) (err error) {
|
|||
|
||||
// UpdateUser updates user's information.
|
||||
func UpdateUser(u *User) error {
|
||||
has, err := x.Where("id != ?", u.Id).And("email = ?", u.Email).Get(new(User))
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
return ErrEmailAlreadyUsed
|
||||
}
|
||||
|
||||
u.LowerName = strings.ToLower(u.Name)
|
||||
|
||||
if len(u.Location) > 255 {
|
||||
|
@ -429,7 +436,7 @@ func UpdateUser(u *User) error {
|
|||
u.Description = u.Description[:255]
|
||||
}
|
||||
|
||||
_, err := x.Id(u.Id).AllCols().Update(u)
|
||||
_, err = x.Id(u.Id).AllCols().Update(u)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -192,13 +192,19 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) {
|
|||
u.IsActive = form.Active
|
||||
u.IsAdmin = form.Admin
|
||||
u.AllowGitHook = form.AllowGitHook
|
||||
|
||||
ctx.Data["User"] = u
|
||||
|
||||
if err := models.UpdateUser(u); err != nil {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
if err == models.ErrEmailAlreadyUsed {
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_EDIT, &form)
|
||||
} else {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("Account profile updated by admin(%s): %s", ctx.User.Name, u.Name)
|
||||
|
||||
ctx.Data["User"] = u
|
||||
ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success"))
|
||||
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue