Skip to content

Commit

Permalink
feat(user): 创建用户逻辑调整
Browse files Browse the repository at this point in the history
  • Loading branch information
vaebe committed Jul 21, 2024
1 parent 12da64c commit f49425a
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions internal/logic/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,33 @@ func (s *sUser) Create(ctx context.Context, in entity.User) (string, error) {
in.Avatar = fmt.Sprintf("https://api.dicebear.com/7.x/bottts-neutral/svg?seed=%s&size=64", in.NickName)
}

// 生成随机盐值
in.Salt = grand.S(10)

userId := guid.S()

// Email、WxId 只会存在一个且不可为空
data := g.Map{
"Id": userId,
"Id": in.Id,
"Email": nil,
"WxId": nil,
"Password": utility.EncryptPassword(in.Password, in.Salt),
"Password": nil,
"NickName": in.NickName,
"AccountType": nil,
"AccountType": in.AccountType,
"Role": in.Role,
"Salt": in.Salt,
"Salt": nil,
"Avatar": in.Avatar,
}

if in.WxId != "" {
data["WxId"] = in.WxId
data["AccountType"] = "02"
data["Password"] = ""
data["Salt"] = ""
}
if data["AccountType"] == "01" {
// 生成随机盐值
salt := grand.S(10)

if in.Email != "" {
data["Email"] = in.Email
data["AccountType"] = "01"
data["Id"] = guid.S()
data["Salt"] = salt
data["Password"] = utility.EncryptPassword(in.Password, salt)
}

_, err := dao.User.Ctx(ctx).Data(data).InsertAndGetId()
if err != nil {
return "", err
}
return userId, nil

return data["Id"].(string), nil
}

// Detail 获取用户详情
Expand Down

0 comments on commit f49425a

Please sign in to comment.