diff options
author | Unknwon <u@gogs.io> | 2015-03-26 17:11:47 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-03-26 17:11:47 -0400 |
commit | 698b9e2acc4daafe7d2b314e2d8c96545dde9c40 (patch) | |
tree | 8d593bb0816503494de4deb16ee0fa6b95eb3c5c /models/user.go | |
parent | d76f11c6f14b69bf981e5fc3901cc2c6445773b8 (diff) | |
download | gitea-698b9e2acc4daafe7d2b314e2d8c96545dde9c40.tar.gz gitea-698b9e2acc4daafe7d2b314e2d8c96545dde9c40.zip |
#1070 Clearer error message for illegal characters
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/models/user.go b/models/user.go index dcfd0dc5ec..bf69f97a1b 100644 --- a/models/user.go +++ b/models/user.go @@ -36,10 +36,8 @@ const ( ) var ( - ErrUserAlreadyExist = errors.New("User already exist") ErrUserNotExist = errors.New("User does not exist") ErrUserNotKeyOwner = errors.New("User does not the owner of public key") - ErrEmailAlreadyUsed = errors.New("E-mail already used") ErrEmailNotExist = errors.New("E-mail does not exist") ErrEmailNotActivated = errors.New("E-mail address has not been activated") ErrUserNameIllegal = errors.New("User name contains illegal characters") @@ -273,23 +271,23 @@ func GetUserSalt() string { } // CreateUser creates record of a new user. -func CreateUser(u *User) error { - if !IsLegalName(u.Name) { - return ErrUserNameIllegal +func CreateUser(u *User) (err error) { + if err = IsUsableName(u.Name); err != nil { + return err } isExist, err := IsUserExist(0, u.Name) if err != nil { return err } else if isExist { - return ErrUserAlreadyExist + return ErrUserAlreadyExist{u.Name} } isExist, err = IsEmailUsed(u.Email) if err != nil { return err } else if isExist { - return ErrEmailAlreadyUsed + return ErrEmailAlreadyUsed{u.Email} } u.LowerName = strings.ToLower(u.Name) @@ -392,8 +390,15 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress { // ChangeUserName changes all corresponding setting from old user name to new one. func ChangeUserName(u *User, newUserName string) (err error) { - if !IsLegalName(newUserName) { - return ErrUserNameIllegal + if err = IsUsableName(newUserName); err != nil { + return err + } + + isExist, err := IsUserExist(0, newUserName) + if err != nil { + return err + } else if isExist { + return ErrUserAlreadyExist{newUserName} } return os.Rename(UserPath(u.LowerName), UserPath(newUserName)) @@ -405,7 +410,7 @@ func UpdateUser(u *User) error { if err != nil { return err } else if has { - return ErrEmailAlreadyUsed + return ErrEmailAlreadyUsed{u.Email} } u.LowerName = strings.ToLower(u.Name) @@ -641,7 +646,7 @@ func AddEmailAddress(email *EmailAddress) error { if err != nil { return err } else if used { - return ErrEmailAlreadyUsed + return ErrEmailAlreadyUsed{email.Email} } _, err = x.Insert(email) |