diff options
author | Unknwon <u@gogs.io> | 2015-12-11 18:52:28 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-11 18:52:28 -0500 |
commit | 477b4d3b50ec58998b3b078fadbef01eaf1fbeeb (patch) | |
tree | a63576c95340c4645662fffe18a76793d2435c9c /routers/user | |
parent | 4d31eb2c0df89ebf029b62fec7e79dbb80773cc3 (diff) | |
download | gitea-477b4d3b50ec58998b3b078fadbef01eaf1fbeeb.tar.gz gitea-477b4d3b50ec58998b3b078fadbef01eaf1fbeeb.zip |
#2154 fix form submit error
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/setting.go | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/routers/user/setting.go b/routers/user/setting.go index 9a9aa57e07..3cb9f0aece 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -39,41 +39,52 @@ func Settings(ctx *middleware.Context) { ctx.HTML(200, SETTINGS_PROFILE) } -func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { - ctx.Data["Title"] = ctx.Tr("settings") - ctx.Data["PageIsSettingsProfile"] = true - - if ctx.HasError() { - ctx.HTML(200, SETTINGS_PROFILE) +func handlerUsernameChange(ctx *middleware.Context, newName string) { + if len(newName) == 0 { return } // Check if user name has been changed. - if ctx.User.LowerName != strings.ToLower(form.Name) { - if err := models.ChangeUserName(ctx.User, form.Name); err != nil { + if ctx.User.LowerName != strings.ToLower(newName) { + if err := models.ChangeUserName(ctx.User, newName); err != nil { switch { case models.IsErrUserAlreadyExist(err): - ctx.Flash.Error(ctx.Tr("form.name_been_taken")) + ctx.Flash.Error(ctx.Tr("newName_been_taken")) ctx.Redirect(setting.AppSubUrl + "/user/settings") case models.IsErrEmailAlreadyUsed(err): ctx.Flash.Error(ctx.Tr("form.email_been_used")) ctx.Redirect(setting.AppSubUrl + "/user/settings") case models.IsErrNameReserved(err): - ctx.Flash.Error(ctx.Tr("user.form.name_reserved")) + ctx.Flash.Error(ctx.Tr("user.newName_reserved")) ctx.Redirect(setting.AppSubUrl + "/user/settings") case models.IsErrNamePatternNotAllowed(err): - ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed")) + ctx.Flash.Error(ctx.Tr("user.newName_pattern_not_allowed")) ctx.Redirect(setting.AppSubUrl + "/user/settings") default: ctx.Handle(500, "ChangeUserName", err) } return } - log.Trace("User name changed: %s -> %s", ctx.User.Name, form.Name) + log.Trace("User name changed: %s -> %s", ctx.User.Name, newName) } // In case it's just a case change. - ctx.User.Name = form.Name - ctx.User.LowerName = strings.ToLower(form.Name) + ctx.User.Name = newName + ctx.User.LowerName = strings.ToLower(newName) +} + +func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { + ctx.Data["Title"] = ctx.Tr("settings") + ctx.Data["PageIsSettingsProfile"] = true + + if ctx.HasError() { + ctx.HTML(200, SETTINGS_PROFILE) + return + } + + handlerUsernameChange(ctx, form.Name) + if ctx.Written() { + return + } ctx.User.FullName = form.FullName ctx.User.Email = form.Email |