diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-26 09:56:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 20:56:16 -0500 |
commit | 371ebce2524f013986401af84732fb27bdbc4f96 (patch) | |
tree | 028d1ee76c82e8254d625cd9ba2784b372745a6a /routers/web/admin/users.go | |
parent | f23851f6906acafd5509fb0dcef9866a9aee88ce (diff) | |
download | gitea-371ebce2524f013986401af84732fb27bdbc4f96.tar.gz gitea-371ebce2524f013986401af84732fb27bdbc4f96.zip |
Fix database inconsistent when admin change user email (#17549)
Diffstat (limited to 'routers/web/admin/users.go')
-rw-r--r-- | routers/web/admin/users.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index b92c5cf01a..044efa0099 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -298,6 +298,13 @@ func EditUserPost(ctx *context.Context) { ctx.RenderWithErr(errMsg, tplUserNew, &form) return } + + if err := user_model.ValidateEmail(form.Email); err != nil { + ctx.Data["Err_Email"] = true + ctx.RenderWithErr(ctx.Tr("form.email_error"), tplUserNew, &form) + return + } + if u.Salt, err = user_model.GetUserSalt(); err != nil { ctx.ServerError("UpdateUser", err) return @@ -332,6 +339,7 @@ func EditUserPost(ctx *context.Context) { u.LoginName = form.LoginName u.FullName = form.FullName + emailChanged := !strings.EqualFold(u.Email, form.Email) u.Email = form.Email u.Website = form.Website u.Location = form.Location @@ -352,7 +360,7 @@ func EditUserPost(ctx *context.Context) { u.ProhibitLogin = form.ProhibitLogin } - if err := user_model.UpdateUser(u); err != nil { + if err := user_model.UpdateUser(u, emailChanged); err != nil { if user_model.IsErrEmailAlreadyUsed(err) { ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form) |