public async Task <IActionResult> ChangePassword(string id) { var user = await this.GetUserById(id); var model = new AdminChangePasswordModel { Email = user.Email }; return(View(model)); }
public async Task <ResponseModel> ChangeAdminPasswordAsync(Guid id, AdminChangePasswordModel adminChangePasswordModel) { var admin = await GetAll().FirstOrDefaultAsync(x => x.Id == id); if (admin == null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.NotFound, Message = "Student is not exist. Please try again!" }); } else { var result = PasswordUtilities.ValidatePass(admin.Password, adminChangePasswordModel.CurrentPassword, admin.PasswordSalt); if (result) { if (adminChangePasswordModel.RepeatPassword.Equals(adminChangePasswordModel.NewPassword)) { adminChangePasswordModel.NewPassword.GeneratePassword(out string saltKey, out string hashPass); admin.Password = hashPass; admin.PasswordSalt = saltKey; await _userRepository.UpdateAsync(admin); admin = await GetAll().FirstOrDefaultAsync(x => x.Id == id); return(new ResponseModel { StatusCode = System.Net.HttpStatusCode.OK, Data = new UserViewModel(admin) }); } else { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.NotFound, Message = "RepeatPassword and NewPassword are not the same!" }); } } else { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.NotFound, Message = "Current password is not correct!" }); } } }
public async Task <IActionResult> ChangePassword(AdminChangePasswordModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await this.GetUserByEmail(model.Email); var token = await this.userManager.GeneratePasswordResetTokenAsync(user); var result = await this.userManager.ResetPasswordAsync(user, token, model.NewPassword); if (!result.Succeeded) { this.AddErrors(result); return(View(model)); } TempData[TempDataSuccessMessageKey] = $"The password was reset successfully for user {user.Email}"; return(RedirectToAction(nameof(Index))); }
public Response <object> ChangePassword(AdminChangePasswordModel _) { var user = _repository.GetUserById(_.IdUser); var userBefore = CloneObject.Clone(user); //if (user.IdUserAuthorizationType != (int)UserAuthorizationTypeIds.SystemAccount) //{ // _saveLog.LogInformation("User with Active Directory cannot change password from this system!"); // return new Response<object>(PublicResultStatusCodes.NotAllowedOperation); //} var hashHelper = new HashHelper(_.NewPassword); user.Password = hashHelper.Hash; user.SaltedPassword = hashHelper.Salt; user.LatestPasswordChangeDate = DateTime.Now; var serials = ConvertToBinaryHelper <User> .SerializeAndConvert(userBefore, user); _generalUpdateService.UpdateAddLogDataChange(user, serials.Item1, serials.Item2); return(new Response <object>(PublicResultStatusCodes.Done)); }
public async Task <IActionResult> ChangePassword(Guid id, [FromBody] AdminChangePasswordModel adminChangePasswordModel) { var responseModel = await _userService.ChangeAdminPasswordAsync(id, adminChangePasswordModel); return(new CustomActionResult(responseModel)); }