ChangePassword 修改密码
(ctx context.Context, username string, newPassword string)
| 44 | |
| 45 | // ChangePassword 修改密码 |
| 46 | func (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 创建用户 |
| 73 | func (ur *userRepository) CreateUser(ctx context.Context, u domain.User) error { |
nothing calls this directly
no test coverage detected