add: user accomplished

This commit is contained in:
wwweww
2026-02-27 05:42:13 +08:00
parent 659168fe32
commit a0c720eb2f
90 changed files with 9592 additions and 1180 deletions
+9 -5
View File
@@ -3,6 +3,7 @@ package logic
import (
"context"
"errors"
"juwan-backend/app/users/rpc/internal/models/users"
"juwan-backend/app/users/rpc/internal/svc"
utils2 "juwan-backend/app/users/rpc/internal/utils"
"juwan-backend/app/users/rpc/pb"
@@ -11,6 +12,8 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
//var UserNotFound = errors.New("user not Found")
type LoginLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
@@ -26,23 +29,24 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic
}
func (l *LoginLogic) Login(in *pb.LoginReq) (*pb.LoginResp, error) {
user, err := l.svcCtx.UsersModelRO.FindOneByUsername(l.ctx, in.Username)
//user, err := l.svcCtx.UsersModelRO.FindOneByUsername(l.ctx, in.Username)
user, err := l.svcCtx.UsersModelRO.Query().Where(users.NicknameEQ(in.Username)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("LoginLogic.Login error:%v", err)
return nil, err
}
logx.Infof("user:%v", user)
if !utils.VerifyPassword(user.Passwd, in.Passwd) {
if !utils.VerifyPassword(user.PasswordHash, in.Passwd) {
logx.WithContext(l.ctx).Errorf("User %s Login failed", user.Username)
return nil, errors.New("incorrect password")
}
token, err := l.svcCtx.JwtManager.New(l.ctx, &utils2.TokenPayload{
UserId: user.UserId,
UserId: user.ID,
IsAdmin: false,
})
if err != nil {
logx.Errorf("LoginLogic.Login gen jwt for user %v error:%v", user.UserId, err)
logx.Errorf("LoginLogic.Login gen jwt for user %v error:%v", user.ID, err)
return nil, err
}
@@ -50,6 +54,6 @@ func (l *LoginLogic) Login(in *pb.LoginReq) (*pb.LoginResp, error) {
Token: token,
Username: user.Username,
Email: user.Email,
Id: user.UserId,
Id: user.ID,
}, nil
}