public async Task <Unit> Handle(ModifyPasswordCommand command, CancellationToken cancellationToken) { var userId = command.UserId; var password = command.Password; var newPassword = command.NewPassword; var user = await _userDomainService.Get(userId); if (user == null) { await _bus.RaiseEvent(new DomainNotification("用户不存在")); return(Unit.Value); } if (user.Password != password.ToMd5()) { await _bus.RaiseEvent(new DomainNotification("密码错误")); return(Unit.Value); } user.Password = newPassword.ToMd5(); await _userDomainService.Update(user); if (await Commit()) { await _bus.RaiseEvent(new ModifiedPasswordEvent(user)).ConfigureAwait(false); } return(Unit.Value); }
public async Task <IActionResult> OnPostAsync([FromBody] ModifyPasswordDto dto) { if (!ModelState.IsValid) { return(await Task.FromResult(new JsonResult(new { Status = false, ErrorMessage = ModelState.Where(e => e.Value.Errors.Count > 0).Select(e => e.Value.Errors.First().ErrorMessage).First() }))); } var userId = _accountContext.UserId; var command = new ModifyPasswordCommand(userId, dto.Password, dto.NewPassword); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = string.Join(";", _notifications.GetNotifications().Select(x => x.Content)); return(await Task.FromResult(new JsonResult(new { status = false, errorMessage }))); } return(await Task.FromResult(new JsonResult(new { status = true }))); }
public async Task <IActionResult> OnPostAsync([FromBody] ModifyPasswordDto dto) { var userId = _accountContext.UserId; var command = new ModifyPasswordCommand(userId, dto.Password, dto.NewPassword); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = string.Join(";", _notifications.GetNotifications().Select(x => x.Content)); return(await Task.FromResult(new JsonResult(new { status = false, errorMessage }))); } return(await Task.FromResult(new JsonResult(new { status = true }))); }