diff options
author | Unknwon <u@gogs.io> | 2015-02-22 22:51:25 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-02-22 22:51:25 -0500 |
commit | 7ccab9cd09eca8fa60fdd519c97c259d4b521abd (patch) | |
tree | 914ea87da32fd27d889b2145f559c0fdad8c62af /models/user.go | |
parent | 25f5a8d7986a710cef01d02725071d2de0a6b143 (diff) | |
parent | 2369881808a906f3072c935ab0575f08bd358821 (diff) | |
download | gitea-7ccab9cd09eca8fa60fdd519c97c259d4b521abd.tar.gz gitea-7ccab9cd09eca8fa60fdd519c97c259d4b521abd.zip |
Merge branch 'dev' of github.com:gogits/gogs into access
Conflicts:
gogs.go
models/models.go
models/user.go
templates/.VERSION
templates/org/home.tmpl
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/models/user.go b/models/user.go index 37e77dd3ba..387ab6555b 100644 --- a/models/user.go +++ b/models/user.go @@ -249,11 +249,13 @@ func (u *User) GetFullNameFallback() string { // IsUserExist checks if given user name exist, // the user name should be noncased unique. -func IsUserExist(name string) (bool, error) { +// If uid is presented, then check will rule out that one, +// it is used when update a user name in settings page. +func IsUserExist(uid int64, name string) (bool, error) { if len(name) == 0 { return false, nil } - return x.Get(&User{LowerName: strings.ToLower(name)}) + return x.Where("id!=?", uid).Get(&User{LowerName: strings.ToLower(name)}) } // IsEmailUsed returns true if the e-mail has been used. @@ -278,7 +280,7 @@ func CreateUser(u *User) error { return ErrUserNameIllegal } - isExist, err := IsUserExist(u.Name) + isExist, err := IsUserExist(0, u.Name) if err != nil { return err } else if isExist { @@ -401,7 +403,7 @@ func ChangeUserName(u *User, newUserName string) (err error) { // UpdateUser updates user's information. func UpdateUser(u *User) error { - has, err := x.Where("id!=?", u.Id).And("type=?", INDIVIDUAL).And("email=?", u.Email).Get(new(User)) + has, err := x.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User)) if err != nil { return err } else if has { @@ -578,7 +580,7 @@ func GetUserIdsByNames(names []string) []int64 { return ids } -// Get all email addresses +// GetEmailAddresses returns all e-mail addresses belongs to given user. func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { emails := make([]*EmailAddress, 0, 5) err := x.Where("uid=?", uid).Find(&emails) @@ -592,7 +594,6 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { } isPrimaryFound := false - for _, email := range emails { if email.Email == u.Email { isPrimaryFound = true @@ -605,7 +606,11 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) { // We alway want the primary email address displayed, even if it's not in // the emailaddress table (yet) if !isPrimaryFound { - emails = append(emails, &EmailAddress{Email: u.Email, IsActivated: true, IsPrimary: true}) + emails = append(emails, &EmailAddress{ + Email: u.Email, + IsActivated: true, + IsPrimary: true, + }) } return emails, nil } |