mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-19 00:46:37 +08:00
feat: able to use email to login (close #343,#348)
This commit is contained in:
parent
e062cf32e3
commit
45b9de9df9
@ -295,10 +295,15 @@ func (user *User) ValidateAndFill() (err error) {
|
||||
// that means if your field’s value is 0, '', false or other zero values,
|
||||
// it won’t be used to build query conditions
|
||||
password := user.Password
|
||||
if user.Username == "" || password == "" {
|
||||
if (user.Username == "" && user.Email == "") || password == "" {
|
||||
return errors.New("用户名或密码为空")
|
||||
}
|
||||
DB.Where(User{Username: user.Username}).First(user)
|
||||
// find buy username or email
|
||||
if user.Username != "" {
|
||||
DB.Where(User{Username: user.Username}).First(user)
|
||||
} else if user.Email != "" {
|
||||
DB.Where(User{Email: user.Email}).First(user)
|
||||
}
|
||||
okay := common.ValidatePasswordAndHash(password, user.Password)
|
||||
if !okay || user.Status != common.UserStatusEnabled {
|
||||
return errors.New("用户名或密码错误,或用户已被封禁")
|
||||
|
Loading…
Reference in New Issue
Block a user