36 lines
789 B
Go
36 lines
789 B
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"tianyuan-api/apps/gateway/internal/svc"
|
|
"tianyuan-api/apps/gateway/internal/types"
|
|
"tianyuan-api/apps/user/user"
|
|
)
|
|
|
|
type LoginUserLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewLoginUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginUserLogic {
|
|
return &LoginUserLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *LoginUserLogic) LoginUser(req *types.LoginReq) (token string, err error) {
|
|
loginResp, err := l.svcCtx.AuthRpc.LoginUser(l.ctx, &user.LoginReq{
|
|
Username: req.Username,
|
|
Password: req.Password,
|
|
})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
// 返回成功的登录响应
|
|
return loginResp.Token, nil
|
|
}
|