MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / SignUp

Method SignUp

internal/service/user.go:50–79  ·  view source on GitHub ↗

SignUp 用户注册

(ctx context.Context, u domain.User)

Source from the content-addressed store, hash-verified

48
49// SignUp 用户注册
50func (us *userService) SignUp(ctx context.Context, u domain.User) error {
51 if err := u.ValidateUsername(); err != nil {
52 return errors.New("用户名需要至少六位的字母数字组合")
53 }
54
55 if err := u.ValidatePassword(); err != nil {
56 return errors.New("密码需要至少8位的字母数字符号组合")
57 }
58
59 if err := u.HashPassword(); err != nil {
60 return err
61 }
62
63 // 异步更新搜索索引
64 go func() {
65 ctx := context.Background()
66 err := us.searchRepo.InputUser(ctx, domain.UserSearch{
67 Id: u.ID,
68 Nickname: u.Username,
69 // TODO 字段待协调
70 })
71 if err != nil {
72 us.l.Error("更新搜索索引失败",
73 zap.String("用户名", u.Username),
74 zap.Error(err))
75 }
76 }()
77
78 return us.repo.CreateUser(ctx, u)
79}
80
81// Login 用户登录
82func (us *userService) Login(ctx context.Context, username string, password string) (domain.User, error) {

Callers

nothing calls this directly

Calls 5

ValidateUsernameMethod · 0.80
ValidatePasswordMethod · 0.80
HashPasswordMethod · 0.80
InputUserMethod · 0.65
CreateUserMethod · 0.65

Tested by

no test coverage detected