public async Task <IActionResult> ChangePassword(Guid id, string pass, string newPass) { try { var data = await account.ChangePassword(id, pass, newPass); return(StatusCode(StatusCodes.Status200OK, data)); } catch (Exception ex) { // Log exception code goes here return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public IActionResult ChangePassword(ChangePassword password) { IGernalResult result = new GernalResult(); if (ModelState.IsValid) { try { var userId = HttpContext.Request.Cookies["user_id"]; result = _iAccount.ChangePassword(Convert.ToInt32(userId), password.ConfirmPassword); ViewBag.msg = result.Succsefully ? "Your password has been changed" : "your password did not change"; } catch { ViewBag.msg = "Server error"; } } return(View()); }
public async Task <ActionResult> ChangePassword([FromBody] ChangePasswordViewModel changePasswordViewModel) { if (!ModelState.IsValid) //model is not valid { return(BadRequest(ModelState)); } //confirn new password and new password is not the same if (changePasswordViewModel.ConfirmNewPassword != changePasswordViewModel.NewPassword) { ModelState.AddModelError("PasswordUnmatched", "The new password does not match the confirm password"); return(BadRequest(ModelState)); } //get the sign in user var user = await _accountRepository.GetUser(User); //user is null if (user == null || user.Email != changePasswordViewModel.Email) { return(Unauthorized()); } //method call to change the user password var result = await _accountRepository.ChangePassword(changePasswordViewModel); //result succeeded if (result.Succeeded) { return(new JsonResult(Ok("Password change successfully"))); } //result did not succceed foreach (var err in result.Errors) { ModelState.AddModelError(err.Code, err.Description); } return(BadRequest(ModelState)); }