diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-27 01:54:08 -0600 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-27 01:54:08 -0600 |
commit | 62240b6bc12abfe257224bb554a75a5712803059 (patch) | |
tree | c5ab69fca3503972a4cad5f0ed9181d94ab67908 /models | |
parent | ce05a8d7b6939b4f67a8e779bcc784d1b8ef8fab (diff) | |
download | gitea-62240b6bc12abfe257224bb554a75a5712803059.tar.gz gitea-62240b6bc12abfe257224bb554a75a5712803059.zip |
Add login by email
Diffstat (limited to 'models')
-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 df1eb985c2..661eff2fdd 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. |