diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-04-30 10:24:00 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-04-30 10:24:00 +0800 |
commit | a85f242030f8fa0d74c9d82485d0649926bc6db4 (patch) | |
tree | 43c7850b7c01c635d36f368c108f6305b10e13f2 /models/user.go | |
parent | cdc843f06b90acf71211a684ba32cd92c765230d (diff) | |
parent | 0d6856dbe73c8041451743946fb324663350a687 (diff) |
Merge branch 'dev' of github.com:gogits/gogs into dev
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/models/user.go b/models/user.go index df1eb985..661eff2f 100644 --- a/models/user.go +++ b/models/user.go @@ -410,21 +410,27 @@ func GetUserByEmail(email string) (*User, error) { } // LoginUserPlain validates user by raw user name and password. -func LoginUserPlain(name, passwd string) (*User, error) { - user := User{LowerName: strings.ToLower(name)} - has, err := orm.Get(&user) +func LoginUserPlain(uname, passwd string) (*User, error) { + var u *User + if strings.Contains(uname, "@") { + u = &User{Email: uname} + } else { + u = &User{LowerName: strings.ToLower(uname)} + } + + has, err := orm.Get(u) if err != nil { return nil, err } else if !has { return nil, ErrUserNotExist } - newUser := &User{Passwd: passwd, Salt: user.Salt} + newUser := &User{Passwd: passwd, Salt: u.Salt} newUser.EncodePasswd() - if user.Passwd != newUser.Passwd { + if u.Passwd != newUser.Passwd { return nil, ErrUserNotExist } - return &user, nil + return u, nil } // Follow is connection request for receiving user notifycation. |