first commit
This commit is contained in:
45
apps/admin/internal/logic/auth/loginlogic.go
Normal file
45
apps/admin/internal/logic/auth/loginlogic.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
jwtx "tianyuan-api/pkg/jwt"
|
||||
|
||||
"tianyuan-api/apps/admin/internal/svc"
|
||||
"tianyuan-api/apps/admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
||||
return &LoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(req *types.LoginReq) (token string, err error) {
|
||||
if req.Username == "" || req.Password == "" {
|
||||
return "", errors.New("用户名或密码不能为空")
|
||||
}
|
||||
|
||||
if req.Username != "SkyWalker_8273" && req.Password != "mD$9tPzQ&1kB2z%L" {
|
||||
return "", errors.New("密码错误")
|
||||
}
|
||||
|
||||
// 生成 JWT token,调用封装好的函数
|
||||
token, err = jwtx.GenerateJwtToken(1, l.svcCtx.Config.AuthJWT.AccessSecret, l.svcCtx.Config.AuthJWT.AccessExpire)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 返回成功的登录响应
|
||||
return token, nil
|
||||
}
|
||||
Reference in New Issue
Block a user