✨ 新增几大中心功能
This commit is contained in:
31
server/service/app/auth.go
Normal file
31
server/service/app/auth.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user