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
+15 -21
View File
@@ -6,13 +6,12 @@ import (
"encoding/hex"
"errors"
"fmt"
"strconv"
"strings"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/users/rpc/internal/models"
"juwan-backend/app/users/rpc/internal/svc"
"juwan-backend/app/users/rpc/pb"
"juwan-backend/common/redisx"
"strconv"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -44,13 +43,12 @@ func mustNewRandomNickname() string {
}
func (l *RegisterLogic) Register(in *pb.RegisterReq) (*pb.RegisterResp, error) {
// todo: add your logic here and delete this line
if in.Phone == "" || in.Username == "" || in.Passwd == "" {
if in.Username == "" || in.Passwd == "" {
logx.Error("invalid input")
return nil, errors.New("invalid input")
}
redisKey := fmt.Sprintf("vcode:%s:%s:%s", in.RequestId, "register", in.Email)
redisKey := fmt.Sprintf(redisx.VCODE_KEY_PREFIX, in.RequestId, redisx.SCENE_REG, in.Email)
vcode, err := l.svcCtx.RedisCluster.Get(l.ctx, redisKey).Result()
logx.Infof("vcode:%s, err:%v", vcode, err)
if err != nil {
@@ -69,21 +67,17 @@ func (l *RegisterLogic) Register(in *pb.RegisterReq) (*pb.RegisterResp, error) {
return nil, errors.New("generate user ID failed")
}
user := models.Users{
UserId: resp.Id,
Username: in.Username,
Nickname: mustNewRandomNickname(),
Passwd: in.Passwd,
Phone: in.Phone,
Email: in.Email,
RoleType: 0,
IsVerified: false,
}
_, err = l.svcCtx.UsersModelRW.Insert(l.ctx, &user)
_, err = l.svcCtx.UsersModelRW.Create().
SetID(resp.Id).
SetUsername(in.Username).
SetPasswordHash(in.Passwd).
SetPhone(in.Phone).
SetEmail(in.Email).
SetNickname(mustNewRandomNickname()).
Save(l.ctx)
if err != nil {
logx.Error("failed to create user: ", err)
return nil, errors.New("failed to create user")
logx.Errorf("create user err:%v", err)
return nil, err
}
return &pb.RegisterResp{