#2154 fix form submit error

This commit is contained in:
Unknwon 2015-12-11 18:52:28 -05:00
parent 4d31eb2c0d
commit 477b4d3b50
6 changed files with 41 additions and 30 deletions

View File

@ -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) [![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)

View File

@ -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"},
} }

View File

@ -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)"`

View File

@ -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 {

View File

@ -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;
} }
} }

View File

@ -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 { return
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
}
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