summaryrefslogtreecommitdiffstats
path: root/routers/user
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-03-26 17:11:47 -0400
committerUnknwon <u@gogs.io>2015-03-26 17:11:47 -0400
commit698b9e2acc4daafe7d2b314e2d8c96545dde9c40 (patch)
tree8d593bb0816503494de4deb16ee0fa6b95eb3c5c /routers/user
parentd76f11c6f14b69bf981e5fc3901cc2c6445773b8 (diff)
downloadgitea-698b9e2acc4daafe7d2b314e2d8c96545dde9c40.tar.gz
gitea-698b9e2acc4daafe7d2b314e2d8c96545dde9c40.zip
#1070 Clearer error message for illegal characters
Diffstat (limited to 'routers/user')
-rw-r--r--routers/user/auth.go13
-rw-r--r--routers/user/setting.go25
2 files changed, 20 insertions, 18 deletions
diff --git a/routers/user/auth.go b/routers/user/auth.go
index 5dacaf8c79..52675a777d 100644
--- a/routers/user/auth.go
+++ b/routers/user/auth.go
@@ -249,16 +249,19 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
}
if err := models.CreateUser(u); err != nil {
- switch err {
- case models.ErrUserAlreadyExist:
+ switch {
+ case models.IsErrUserAlreadyExist(err):
ctx.Data["Err_UserName"] = true
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SIGNUP, &form)
- case models.ErrEmailAlreadyUsed:
+ case models.IsErrEmailAlreadyUsed(err):
ctx.Data["Err_Email"] = true
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SIGNUP, &form)
- case models.ErrUserNameIllegal:
+ case models.IsErrNameReserved(err):
ctx.Data["Err_UserName"] = true
- ctx.RenderWithErr(ctx.Tr("form.illegal_username"), SIGNUP, &form)
+ ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), SIGNUP, &form)
+ case models.IsErrNamePatternNotAllowed(err):
+ ctx.Data["Err_UserName"] = true
+ ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), SIGNUP, &form)
default:
ctx.Handle(500, "CreateUser", err)
}
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 20e6c06035..b31e93a63f 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -50,21 +50,20 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
// Check if user name has been changed.
if ctx.User.Name != form.UserName {
- isExist, err := models.IsUserExist(ctx.User.Id, form.UserName)
- if err != nil {
- ctx.Handle(500, "IsUserExist", err)
- return
- } else if isExist {
- ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_PROFILE, &form)
- return
- } else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil {
- switch err {
- case models.ErrUserNameIllegal:
- ctx.Flash.Error(ctx.Tr("form.illegal_username"))
+ if err := models.ChangeUserName(ctx.User, form.UserName); err != nil {
+ switch {
+ case models.IsErrUserAlreadyExist(err):
+ ctx.Flash.Error(ctx.Tr("form.username_been_taken"))
ctx.Redirect(setting.AppSubUrl + "/user/settings")
- case models.ErrEmailAlreadyUsed:
+ 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)
}
@@ -204,7 +203,7 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
}
if err := models.AddEmailAddress(e); err != nil {
- if err == models.ErrEmailAlreadyUsed {
+ if models.IsErrEmailAlreadyUsed(err) {
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form)
return
}