xf 2 years ago
parent
commit
b56f928f97

+ 27 - 26
src/Hotline.Api/Controllers/UserController.cs

@@ -175,27 +175,27 @@ public class UserController : BaseController
         }
         else
         {
-            if (_accountDomainService.IsLockedOut(account))
-                throw UserFriendlyException.SameMessage("该账号已被锁定,请联系管理员");
-
-            //set roles
-            await _accountRepository.SetAccountRolesAsync(account.Id, dto.RoleIds, HttpContext.RequestAborted);
-
-            var user = await _userRepository.GetAsync(account.Id, HttpContext.RequestAborted);
-            if (user is null)
-            {
-                user = _mapper.Map<User>(dto);
-                user.Id = account.Id;
-                return await _userRepository.AddAsync(user, HttpContext.RequestAborted);
-            }
-
-            if (user.IsDeleted)
-            {
-                user.Recover();
-                _mapper.Map(dto, user);
-                await _userRepository.UpdateAsync(user);
-                return user.Id;
-            }
+            //if (_accountDomainService.IsLockedOut(account))
+            //    throw UserFriendlyException.SameMessage("该账号已被锁定,请联系管理员");
+
+            ////set roles
+            //await _accountRepository.SetAccountRolesAsync(account.Id, dto.RoleIds, HttpContext.RequestAborted);
+
+            //var user = await _userRepository.GetAsync(account.Id, HttpContext.RequestAborted);
+            //if (user is null)
+            //{
+            //    user = _mapper.Map<User>(dto);
+            //    user.Id = account.Id;
+            //    return await _userRepository.AddAsync(user, HttpContext.RequestAborted);
+            //}
+
+            //if (user.IsDeleted)
+            //{
+            //    user.Recover();
+            //    _mapper.Map(dto, user);
+            //    await _userRepository.UpdateAsync(user);
+            //    return user.Id;
+            //}
 
             throw UserFriendlyException.SameMessage("该用户已存在");
         }
@@ -215,10 +215,11 @@ public class UserController : BaseController
             throw UserFriendlyException.SameMessage("用户正在工作中,请下班以后再删除");
 
         var account = await _accountRepository.GetAsync(id, HttpContext.RequestAborted);
-        if (account is null)
-            throw UserFriendlyException.SameMessage("账号不存在");
-        await _accountDomainService.UnRegisterAsync(account, HttpContext.RequestAborted);
-        await _userRepository.RemoveAsync(id, true, HttpContext.RequestAborted);
+        if (account is not null)
+        {
+            await _accountDomainService.UnRegisterAsync(account, HttpContext.RequestAborted);
+            await _userRepository.RemoveAsync(id, true, HttpContext.RequestAborted);
+        }
     }
 
     /// <summary>
@@ -311,7 +312,7 @@ public class UserController : BaseController
     {
         var account = await _accountRepository.GetAsync(userId, HttpContext.RequestAborted);
         CheckAccountStatus(account);
-         await _accountDomainService.InitialPasswordAsync(account, HttpContext.RequestAborted);
+        await _accountDomainService.InitialPasswordAsync(account, HttpContext.RequestAborted);
     }
 
     /// <summary>

+ 14 - 0
src/Hotline.Application.Contracts/Validators/User/ChangePasswordDtoValidator.cs

@@ -0,0 +1,14 @@
+using FluentValidation;
+using Hotline.Share.Dtos.Users;
+
+namespace Hotline.Application.Contracts.Validators.User;
+
+public class ChangePasswordDtoValidator : AbstractValidator<ChangePasswordDto>
+{
+    public ChangePasswordDtoValidator()
+    {
+        RuleFor(d => d.CurrentPassword).NotEmpty();
+        RuleFor(d => d.NewPassword).NotEmpty();
+        RuleFor(d => d.CurrentPassword).NotEqual(d => d.NewPassword);
+    }
+}