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

Method ChangePassword

internal/repository/user.go:46–70  ·  view source on GitHub ↗

ChangePassword 修改密码

(ctx context.Context, username string, newPassword string)

Source from the content-addressed store, hash-verified

44
45// ChangePassword 修改密码
46func (ur *userRepository) ChangePassword(ctx context.Context, username string, newPassword string) error {
47 err := ur.dao.UpdatePasswordByUsername(ctx, username, newPassword)
48 if err != nil {
49 ur.l.Error("修改密码失败", zap.Error(err))
50 return err
51 }
52
53 // 重新设置缓存,避免缓存不一致
54 user, err := ur.dao.FindByUsername(ctx, username)
55 if err != nil {
56 ur.l.Error("密码修改后获取用户信息失败", zap.Error(err))
57 return err
58 }
59
60 // 异步设置缓存
61 go func() {
62 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
63 defer cancel()
64 if err := ur.cache.Set(ctx, toDomainUser(user)); err != nil {
65 ur.l.Error("密码修改后更新缓存失败", zap.Error(err))
66 }
67 }()
68
69 return nil
70}
71
72// CreateUser 创建用户
73func (ur *userRepository) CreateUser(ctx context.Context, u domain.User) error {

Callers

nothing calls this directly

Calls 4

toDomainUserFunction · 0.85
FindByUsernameMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected