Browse Source

#2154 fix form submit error

Unknwon 9 years ago
parent
commit
477b4d3b50
6 changed files with 30 additions and 19 deletions
  1. 1 1
      README.md
  2. 1 1
      cmd/web.go
  3. 1 1
      modules/auth/user_form.go
  4. 1 1
      public/css/gogs.css
  5. 1 1
      public/less/_repository.less
  6. 25 14
      routers/user/setting.go

+ 1 - 1
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)

+ 1 - 1
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"},
 	}

+ 1 - 1
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)"`

+ 1 - 1
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 {

+ 1 - 1
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;
 		}
 	}

+ 25 - 14
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