add: user auth accomplished

This commit is contained in:
wwweww
2026-02-26 02:17:07 +08:00
parent 300058ad01
commit 60b6f40f9f
54 changed files with 1601 additions and 2303 deletions
@@ -5,9 +5,11 @@ package user
import (
"context"
"errors"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
"juwan-backend/app/users/rpc/usercenter"
"time"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -28,6 +30,24 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic
}
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
if len(req.Username) < 3 || len(req.Password) > 20 || len(req.Password) < 8 || len(req.Password) > 20 {
return nil, errors.New("the information is illegal")
}
return &types.LoginResp{}, nil
res, err := l.svcCtx.UserRpc.Login(l.ctx, &usercenter.LoginReq{
Username: req.Username,
Passwd: req.Password,
})
if err != nil {
logx.Errorf("rpc login err: %v", err)
return nil, errors.New("login fail")
}
return &types.LoginResp{
UserId: res.Id,
Username: res.Username,
Email: res.Email,
Token: res.Token,
Expires: int64((7 * 24 * time.Hour).Seconds()),
}, nil
}