From 477b4d3b50ec58998b3b078fadbef01eaf1fbeeb Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 11 Dec 2015 18:52:28 -0500 Subject: [PATCH] #2154 fix form submit error --- README.md | 2 +- cmd/web.go | 2 +- modules/auth/user_form.go | 2 +- public/css/gogs.css | 2 +- public/less/_repository.less | 2 +- routers/user/setting.go | 39 +++++++++++++++++++++++------------- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 8e2079140..85ec290e0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?branch=master)](https://travis-ci.org/gogits/gogs) [![Docker Repository on Quay](https://quay.io/repository/gogs/gogs/status "Docker Repository on Quay")](https://quay.io/repository/gogs/gogs) +Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?branch=master)](https://travis-ci.org/gogits/gogs) [![Docker Repository on Quay](https://quay.io/repository/gogs/gogs/status "Docker Repository on Quay")](https://quay.io/repository/gogs/gogs) [![Crowdin](https://d322cqt584bo4o.cloudfront.net/gogs/localized.svg)](https://crowdin.com/project/gogs) ===================== [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gogits/gogs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/cmd/web.go b/cmd/web.go index 8ff912d43..ec8ccd519 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -86,7 +86,7 @@ func checkVersion() { {"github.com/go-macaron/i18n", i18n.Version, "0.2.0"}, {"github.com/go-macaron/session", session.Version, "0.1.6"}, {"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"}, - {"gopkg.in/ini.v1", ini.Version, "1.8.3"}, + {"gopkg.in/ini.v1", ini.Version, "1.8.4"}, {"gopkg.in/macaron.v1", macaron.Version, "0.8.0"}, {"github.com/gogits/git-shell", git.Version, "0.1.0"}, } diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index 2942940de..d4c2dff9c 100644 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -87,7 +87,7 @@ func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding // \/ \/ \/ \/ \/ type UpdateProfileForm struct { - Name string `binding:"Required;MaxSize(35)"` + Name string `binding:"OmitEmpty;MaxSize(35)"` FullName string `binding:"MaxSize(100)"` Email string `binding:"Required;Email;MaxSize(254)"` Website string `binding:"Url;MaxSize(100)"` diff --git a/public/css/gogs.css b/public/css/gogs.css index 96ee81209..92d10ac73 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -1773,9 +1773,9 @@ footer .container .links > *:first-child { } .repository .head .fork-flag { margin-left: 38px; + margin-top: 3px; display: block; font-size: 12px; - line-height: 10px; white-space: nowrap; } .repository .navbar .ui.label { diff --git a/public/less/_repository.less b/public/less/_repository.less index 06ce6414a..e13d04195 100644 --- a/public/less/_repository.less +++ b/public/less/_repository.less @@ -25,9 +25,9 @@ } .fork-flag { margin-left: @mega-octicon-width + 8px; + margin-top: 3px; display: block; font-size: 12px; - line-height: 10px; white-space: nowrap; } } diff --git a/routers/user/setting.go b/routers/user/setting.go index 9a9aa57e0..3cb9f0aec 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