Skip to content

Commit

Permalink
Fix incorrect/Improve error handle in edit user page (#23805)
Browse files Browse the repository at this point in the history
Changes:
- `RenderWithErr` should render `tplUserEdit` not `tplUserNew` in edit
page
- If error occurred in `HandleUsernameChange` redirect to original edit
page instead of user list page
  • Loading branch information
yp05327 authored Mar 30, 2023
1 parent ffd2269 commit 06d9d9e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions routers/web/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ func EditUserPost(ctx *context.Context) {
log.Error(err.Error())
errMsg = ctx.Tr("auth.password_pwned_err")
}
ctx.RenderWithErr(errMsg, tplUserNew, &form)
ctx.RenderWithErr(errMsg, tplUserEdit, &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)
ctx.RenderWithErr(ctx.Tr("form.email_error"), tplUserEdit, &form)
return
}

Expand All @@ -338,7 +338,10 @@ func EditUserPost(ctx *context.Context) {

if len(form.UserName) != 0 && u.Name != form.UserName {
if err := user_setting.HandleUsernameChange(ctx, u, form.UserName); err != nil {
ctx.Redirect(setting.AppSubURL + "/admin/users")
if ctx.Written() {
return
}
ctx.RenderWithErr(ctx.Flash.ErrorMsg, tplUserEdit, &form)
return
}
u.Name = form.UserName
Expand Down

0 comments on commit 06d9d9e

Please sign in to comment.