public void Handle(UpdateUserPasswordCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } var existingUser = _userRepository.Get(message.UserId); if (existingUser != null && !existingUser.IsVerified) { existingUser.Password = Utils.EncryptPassword(message.Password); existingUser.IsVerified = true; existingUser.CreationDate = message.CreationDate; existingUser.CreatorUserId = message.UserId; existingUser.LastUpdateDate = message.LastUpdateDate; existingUser.LastUpdatedUserId = message.UserId; } if (Commit()) { _bus.RaiseEvent(new UserPasswordUpdatedEvent(existingUser.UserId, existingUser.Password, existingUser.IsVerified, existingUser.CreationDate, existingUser.CreatorUserId, existingUser.LastUpdateDate, existingUser.LastUpdatedUserId)); } }
public async Task <ActionResult> SetPassword(UpdateUserPasswordCommand command) { command.UserId = User.Identity.GetUserId(); await HandleCommandAsync(command); return(View(command)); }
public IActionResult UpdatePassword(int id, [FromBody] UpdateUserPasswordCommand model) { // map model to entity and set id var user = new User(); user.Iduser = id; try { if (!string.IsNullOrWhiteSpace(model.Password) && !string.IsNullOrEmpty(model.OldPassword)) { // update user _userRepository.Update(user, model.Password, model.OldPassword); return(Ok()); } else { return(BadRequest("There was a problem with passwords(Check if null or property name correctly spelled)")); } } catch (ApplicationException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> UpdateUserPassword([FromRoute] Guid id, [FromBody] UpdateUserPasswordCommand command) { command.Id = id; await _mediator.Send(command); return(Ok()); }
public void Execute_IntegrationTest_SQLite() { string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest"); using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath)) { dbContext.Initialise(); dbContext.BeginTransaction(); // create the user UserModel user = DataHelper.CreateUserModel(); IUserRepository userRepo = new UserRepository(dbContext); IUserValidator userValidator = new UserValidator(userRepo); IPasswordProvider passwordProvider = new PasswordProvider(); ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, userValidator, passwordProvider); UserModel savedUser = createUserCommand.Execute(user.UserName, user.Password, user.Role); // reset the password string newPassword = Guid.NewGuid().ToString(); IUpdateUserPasswordCommand updateCommand = new UpdateUserPasswordCommand(dbContext, userRepo, passwordProvider); updateCommand.Execute(savedUser.UserName, newPassword); // now fetch it again and check the password is good savedUser = userRepo.GetByUserName(user.UserName); Assert.IsTrue(passwordProvider.CheckPassword(newPassword, savedUser.Password)); } }
public virtual async Task <IActionResult> UpdateUserPassword( [FromBody][ModelBinder(BinderType = typeof(UserCommandModelBinder))] UpdateUserPasswordCommand passwordUpdateCommand) { await this._commandDispather.HandleAsync <UpdateUserPasswordCommand>(passwordUpdateCommand); return(NoContent()); }
public async Task<IActionResult> SetPassword([FromBody]UpdateUserPasswordDto dto, Guid id) { var cmd = new UpdateUserPasswordCommand { NewPassword = dto.Password, UserId = id }; var result = await _sagaBus.InvokeAsync<UpdateUserPasswordCommand, MessageResult>(cmd); if (result.Succeed) { return Created(Url.Action(), null); } //if user doesn't exist. return BadRequest(result.Message); }
public async Task <IActionResult> SetPassword([FromBody] UpdateUserPasswordDto dto, Guid id) { var cmd = new UpdateUserPasswordCommand { NewPassword = dto.Password, UserId = id }; var result = await _sagaBus.InvokeAsync <UpdateUserPasswordCommand, MessageResult>(cmd); if (result.Succeed) { return(Created(Url.Action(), null)); } //if user doesn't exist. return(BadRequest(result.Message)); }
public async Task HandleUpdateUserPassword(UpdateUserPasswordCommand command) { if (string.IsNullOrEmpty(command.CurrentPassword)) { command.Result = await userManager.AddPasswordAsync(command.UserId, command.NewPassword); } else { command.Result = await userManager.ChangePasswordAsync(command.UserId, command.CurrentPassword, command.NewPassword); } if (!command.Result.Succeeded) { throw new IdentityException(command.Result); } }
public async Task <IActionResult> UpdateUserPassword(string id, [FromBody] UpdateUserPasswordCommand updatedUserPassword) { try { if (!ModelState.IsValid) { return(new InvalidInputResponse(ModelState)); } var asss = await _Mediator.Send(updatedUserPassword); return(StatusCode(204)); } catch (NotFoundException e) { return(StatusCode(404, e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public async Task <bool> Handle(UpdateUserPasswordCommand message, CancellationToken cancellationToken) { if (message.Mode == "reset") { var user = await _userManager.FindByIdAsync(message.Id.ToString()); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) { throw new DomainException("The user must have confirm mail"); } //For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 //Send an email with this link var code = await _userManager.GeneratePasswordResetTokenAsync(user); await _emailSender.SendEmailResetPassword(user, code); } return(true); }
public async Task <IActionResult> UpdateUserPassword([FromBody] UpdateUserPasswordCommand passwordUpdateCommand) { await Mediator.Send(passwordUpdateCommand); return(NoContent()); }
public Task <Response <string> > UpdateUserPassword(UpdateUserPasswordCommand command) { return(_context.UpdateUserPassword(command)); }
public async Task <IActionResult> Create([FromBody] UpdateUserPasswordCommand command) { return(Created(CurrentUri, await Mediator.Send(command))); }
public async Task <IActionResult> UpdateUserPassword(string id, [FromBody] UpdateUserPasswordCommand updatedUserPassword) { var asss = await _Mediator.Send(updatedUserPassword); return(StatusCode(204)); }