mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	#2154 fix form submit error
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
Gogs - Go Git Service [](https://travis-ci.org/gogits/gogs) [](https://quay.io/repository/gogs/gogs)
 | 
					Gogs - Go Git Service [](https://travis-ci.org/gogits/gogs) [](https://quay.io/repository/gogs/gogs) [](https://crowdin.com/project/gogs)
 | 
				
			||||||
=====================
 | 
					=====================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[](https://gitter.im/gogits/gogs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 | 
					[](https://gitter.im/gogits/gogs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,7 +86,7 @@ func checkVersion() {
 | 
				
			|||||||
		{"github.com/go-macaron/i18n", i18n.Version, "0.2.0"},
 | 
							{"github.com/go-macaron/i18n", i18n.Version, "0.2.0"},
 | 
				
			||||||
		{"github.com/go-macaron/session", session.Version, "0.1.6"},
 | 
							{"github.com/go-macaron/session", session.Version, "0.1.6"},
 | 
				
			||||||
		{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
 | 
							{"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"},
 | 
							{"gopkg.in/macaron.v1", macaron.Version, "0.8.0"},
 | 
				
			||||||
		{"github.com/gogits/git-shell", git.Version, "0.1.0"},
 | 
							{"github.com/gogits/git-shell", git.Version, "0.1.0"},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,7 +87,7 @@ func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding
 | 
				
			|||||||
//         \/         \/                                   \/        \/        \/
 | 
					//         \/         \/                                   \/        \/        \/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type UpdateProfileForm struct {
 | 
					type UpdateProfileForm struct {
 | 
				
			||||||
	Name     string `binding:"Required;MaxSize(35)"`
 | 
						Name     string `binding:"OmitEmpty;MaxSize(35)"`
 | 
				
			||||||
	FullName string `binding:"MaxSize(100)"`
 | 
						FullName string `binding:"MaxSize(100)"`
 | 
				
			||||||
	Email    string `binding:"Required;Email;MaxSize(254)"`
 | 
						Email    string `binding:"Required;Email;MaxSize(254)"`
 | 
				
			||||||
	Website  string `binding:"Url;MaxSize(100)"`
 | 
						Website  string `binding:"Url;MaxSize(100)"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1773,9 +1773,9 @@ footer .container .links > *:first-child {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
.repository .head .fork-flag {
 | 
					.repository .head .fork-flag {
 | 
				
			||||||
  margin-left: 38px;
 | 
					  margin-left: 38px;
 | 
				
			||||||
 | 
					  margin-top: 3px;
 | 
				
			||||||
  display: block;
 | 
					  display: block;
 | 
				
			||||||
  font-size: 12px;
 | 
					  font-size: 12px;
 | 
				
			||||||
  line-height: 10px;
 | 
					 | 
				
			||||||
  white-space: nowrap;
 | 
					  white-space: nowrap;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.repository .navbar .ui.label {
 | 
					.repository .navbar .ui.label {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,9 +25,9 @@
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		.fork-flag {
 | 
							.fork-flag {
 | 
				
			||||||
			margin-left: @mega-octicon-width + 8px;
 | 
								margin-left: @mega-octicon-width + 8px;
 | 
				
			||||||
 | 
								margin-top: 3px;
 | 
				
			||||||
			display: block;
 | 
								display: block;
 | 
				
			||||||
			font-size: 12px;
 | 
								font-size: 12px;
 | 
				
			||||||
			line-height: 10px;
 | 
					 | 
				
			||||||
			white-space: nowrap;
 | 
								white-space: nowrap;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,39 @@ func Settings(ctx *middleware.Context) {
 | 
				
			|||||||
	ctx.HTML(200, SETTINGS_PROFILE)
 | 
						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(newName) {
 | 
				
			||||||
 | 
							if err := models.ChangeUserName(ctx.User, newName); err != nil {
 | 
				
			||||||
 | 
								switch {
 | 
				
			||||||
 | 
								case models.IsErrUserAlreadyExist(err):
 | 
				
			||||||
 | 
									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.newName_reserved"))
 | 
				
			||||||
 | 
									ctx.Redirect(setting.AppSubUrl + "/user/settings")
 | 
				
			||||||
 | 
								case models.IsErrNamePatternNotAllowed(err):
 | 
				
			||||||
 | 
									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, newName)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// In case it's just a case change.
 | 
				
			||||||
 | 
						ctx.User.Name = newName
 | 
				
			||||||
 | 
						ctx.User.LowerName = strings.ToLower(newName)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
 | 
					func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
 | 
				
			||||||
	ctx.Data["Title"] = ctx.Tr("settings")
 | 
						ctx.Data["Title"] = ctx.Tr("settings")
 | 
				
			||||||
	ctx.Data["PageIsSettingsProfile"] = true
 | 
						ctx.Data["PageIsSettingsProfile"] = true
 | 
				
			||||||
@@ -48,32 +81,10 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if user name has been changed.
 | 
						handlerUsernameChange(ctx, form.Name)
 | 
				
			||||||
	if ctx.User.LowerName != strings.ToLower(form.Name) {
 | 
						if ctx.Written() {
 | 
				
			||||||
		if err := models.ChangeUserName(ctx.User, form.Name); err != nil {
 | 
					 | 
				
			||||||
			switch {
 | 
					 | 
				
			||||||
			case models.IsErrUserAlreadyExist(err):
 | 
					 | 
				
			||||||
				ctx.Flash.Error(ctx.Tr("form.name_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.Redirect(setting.AppSubUrl + "/user/settings")
 | 
					 | 
				
			||||||
			case models.IsErrNamePatternNotAllowed(err):
 | 
					 | 
				
			||||||
				ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed"))
 | 
					 | 
				
			||||||
				ctx.Redirect(setting.AppSubUrl + "/user/settings")
 | 
					 | 
				
			||||||
			default:
 | 
					 | 
				
			||||||
				ctx.Handle(500, "ChangeUserName", err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		log.Trace("User name changed: %s -> %s", ctx.User.Name, form.Name)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// In case it's just a case change.
 | 
					 | 
				
			||||||
	ctx.User.Name = form.Name
 | 
					 | 
				
			||||||
	ctx.User.LowerName = strings.ToLower(form.Name)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ctx.User.FullName = form.FullName
 | 
						ctx.User.FullName = form.FullName
 | 
				
			||||||
	ctx.User.Email = form.Email
 | 
						ctx.User.Email = form.Email
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user