Skip to content

Commit

Permalink
fix: email login
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Jul 9, 2024
1 parent 0526c85 commit f55f63f
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,11 @@ 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 == "" && user.Email == "") || password == "" {
if user.Username == "" || password == "" {
return errors.New("用户名或密码为空")
}
// 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)
}
DB.Where("username = ? OR email = ?", user.Username, user.Username).First(user)
okay := common.ValidatePasswordAndHash(password, user.Password)
if !okay || user.Status != common.UserStatusEnabled {
return errors.New("用户名或密码错误,或用户已被封禁")
Expand Down

0 comments on commit f55f63f

Please sign in to comment.