tianyuan-api-server/apps/admin/internal/logic/auth/loginlogic.go
2024-10-02 00:57:17 +08:00

46 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}