feat: able to login via email (close #921)
This commit is contained in:
parent
8a4d6f3327
commit
f2c51a494c
@ -141,7 +141,15 @@ func (user *User) ValidateAndFill() (err error) {
|
|||||||
if user.Username == "" || password == "" {
|
if user.Username == "" || password == "" {
|
||||||
return errors.New("用户名或密码为空")
|
return errors.New("用户名或密码为空")
|
||||||
}
|
}
|
||||||
DB.Where(User{Username: user.Username}).First(user)
|
err = DB.Where("username = ?", user.Username).First(user).Error
|
||||||
|
if err != nil {
|
||||||
|
// we must make sure check username firstly
|
||||||
|
// consider this case: a malicious user set his username as other's email
|
||||||
|
err := DB.Where("email = ?", user.Username).First(user).Error
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("用户名或密码错误,或用户已被封禁")
|
||||||
|
}
|
||||||
|
}
|
||||||
okay := common.ValidatePasswordAndHash(password, user.Password)
|
okay := common.ValidatePasswordAndHash(password, user.Password)
|
||||||
if !okay || user.Status != common.UserStatusEnabled {
|
if !okay || user.Status != common.UserStatusEnabled {
|
||||||
return errors.New("用户名或密码错误,或用户已被封禁")
|
return errors.New("用户名或密码错误,或用户已被封禁")
|
||||||
|
Loading…
Reference in New Issue
Block a user