public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(InvalidModelStateResult(ModelState)); } var userid = User.GetUserId(); if (string.IsNullOrEmpty(userid)) { return(OtherResult(HttpStatusCode.BadRequest, "Authorized user not found.")); } var user = await _aApplicationUserRepository.GetSingleAsyncs(x => x.Id == userid); if (user == null) { return(OtherResult(HttpStatusCode.BadRequest, "Authorized user not found.")); } var result = await _aApplicationUserRepository.ChangePasswordAsync(model, user); if (result.Key == 1) { return(OKResult(result.Key, "Password successfully changed. Login successful.", result.Value)); } return(OKResult(result.Key, result.Value.ToString())); }
public async Task ChangePassword_Without_ResetToken() { ApplicationUser applicationUser = await _applicationUserRepository.FindByNameOrEmailAsync("admin"); Assert.IsNotNull(applicationUser); IdentityResult result = await _applicationUserRepository.ChangePasswordAsync(applicationUser, "ThisisaSecurePassword321*", "ThisIsMyNewPassword123."); Assert.IsTrue(result.Succeeded); }
public async Task <UpdateClientResponseModel> UpdateClientAccountAsync(string token, UpdateClientRequestModel dto) { var response = new UpdateClientResponseModel { IsSuccessful = false, Message = string.Empty }; SessionData sessionData = await sessionRepository.GetByTokenAsync(token); if (sessionData == null) { response.Message = "Unauthorized"; return(response); } UserData user = await applicationUserRepository.FindByIdAsync(sessionData.UserId); ClientData client = clientRepository.FindByUser(user); if (!await applicationUserRepository.CheckPasswordAsync(dto.Email, dto.OldPassword)) { response.Message = "You should write your current password before update"; return(response); } user.Email = dto.Email; client.Name = dto.Name; client.Surname = dto.Surname; client.Telephone = dto.Telephone; client.Passport = dto.Passport; if (dto.NewPassword != null && dto.NewPassword != string.Empty && dto.NewPassword != dto.OldPassword) { var passwordChangeResult = await applicationUserRepository.ChangePasswordAsync(dto); if (!passwordChangeResult.Succeeded) { response.Message = "Error while changing passsword"; return(response); } response.Message = "Password changed successfully"; } bool clientRes = await clientRepository.UpdateAsync(client); if (!clientRes) { response.Message = "Error while updating client information"; } else { response.IsSuccessful = true; } return(response); }
public async Task <ActionResult <ApplicationUserViewModel> > ChangePassword(string id, [FromBody] ChangePasswordModel changePasswordModel) { ApplicationUser user = await _userRepository.FindByIdAsync(id); if (user is null) { return(BadRequest($"No existe un usuario identificado con el id {id}.")); } IdentityResult changePasswordResult = await _userRepository.ChangePasswordAsync(user, changePasswordModel.OldPassword, changePasswordModel.NewPassword); if (!changePasswordResult.Succeeded) { return(this.IdentityResultErrors(changePasswordResult)); } return(_mapper.Map <ApplicationUserViewModel>(user)); }