32 lines
826 B
Go
32 lines
826 B
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.echol.cn/loser/Go-Web-Template/server/global"
|
|
appModel "git.echol.cn/loser/Go-Web-Template/server/model/app"
|
|
"git.echol.cn/loser/Go-Web-Template/server/utils"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type AppAuthService struct{}
|
|
|
|
var AppAuthServiceApp = new(AppAuthService)
|
|
|
|
func (s *AppAuthService) Login(username, password string) (*appModel.AppUser, error) {
|
|
var user appModel.AppUser
|
|
if err := global.GVA_DB.Where("username = ?", username).First(&user).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, errors.New("用户名或密码错误")
|
|
}
|
|
return nil, err
|
|
}
|
|
if user.Enable != 1 {
|
|
return nil, errors.New("用户被禁止登录")
|
|
}
|
|
if !utils.BcryptCheck(password, user.Password) {
|
|
return nil, errors.New("用户名或密码错误")
|
|
}
|
|
return &user, nil
|
|
}
|