Commit ea72b9c9 by CalciumIon

feat: able to use email to login (close #343,#348)

parent ccd0ac8d
......@@ -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("用户名或密码错误,或用户已被封禁")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment