修复冻结用户强制下线
This commit is contained in:
@@ -27,6 +27,26 @@ func (r *UserRepository) FindByID(ctx context.Context, id uint64) (*model.User,
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
// FindActiveForToken 校验用户仍可用且令牌版本未被撤销。
|
||||
func (r *UserRepository) FindActiveForToken(ctx context.Context, id uint64, tokenVersion int64) (*model.User, error) {
|
||||
if r == nil || r.db == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
var user model.User
|
||||
if err := r.db.WithContext(ctx).
|
||||
Select("id, phone, status, token_version").
|
||||
First(&user, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Status != "active" {
|
||||
return nil, ErrUserDisabled
|
||||
}
|
||||
if user.TokenVersion != tokenVersion {
|
||||
return nil, ErrTokenVersionMismatch
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (r *UserRepository) UpdateProfile(ctx context.Context, id uint64, nickname string, avatarURL string) (*model.User, error) {
|
||||
if err := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", id).Updates(map[string]any{
|
||||
"nickname": nickname,
|
||||
|
||||
Reference in New Issue
Block a user