From 698b9e2acc4daafe7d2b314e2d8c96545dde9c40 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 26 Mar 2015 17:11:47 -0400 Subject: #1070 Clearer error message for illegal characters --- routers/admin/users.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'routers/admin/users.go') diff --git a/routers/admin/users.go b/routers/admin/users.go index ddd12a8b22..ddcca6390e 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -106,16 +106,19 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { } 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"), USER_NEW, &form) - case models.ErrEmailAlreadyUsed: + case models.IsErrEmailAlreadyUsed(err): ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_NEW, &form) - case models.ErrUserNameIllegal: + case models.IsErrNameReserved(err): + ctx.Data["Err_UserName"] = true + ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), USER_NEW, &form) + case models.IsErrNamePatternNotAllowed(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("form.illegal_username"), USER_NEW, &form) + ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), USER_NEW, &form) default: ctx.Handle(500, "CreateUser", err) } @@ -195,7 +198,7 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) { u.AllowGitHook = form.AllowGitHook if err := models.UpdateUser(u); err != nil { - if err == models.ErrEmailAlreadyUsed { + if models.IsErrEmailAlreadyUsed(err) { ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_EDIT, &form) } else { -- cgit v1.2.3