public ActionResult ChangePassword(AccountChangePasswordModel model) { if (string.IsNullOrEmpty(model.OldPassword)) { if (!_currentUser.IsAdmin) { ModelState.AddModelError("OldPassword", "The Current password field is required."); } else { model.OldPassword = "******"; } } if (ModelState.IsValid) { if (_membershipService.ChangePassword(model.Email, model.OldPassword, model.NewPassword)) { return(RedirectTo <AccountController>(c => c.ChangePasswordSuccess())); } ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } // If we got this far, something failed, redisplay form return(View(model)); }
public HttpResponseMessage ChangePassword(HttpRequestMessage request, [FromBody] AccountChangePasswordModel passwordModel) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; var loginName = User.Identity.Name; passwordModel.LoginID = loginName; ValidateAuthorizedUser(passwordModel.LoginID); _SecurityAdapter.Initialize(); //_SecurityAdapter.LogOut(); bool success = _SecurityAdapter.ChangePassword(passwordModel.LoginID, passwordModel.OldPassword, passwordModel.NewPassword); //bool success = _SecurityAdapter.ChangePassword(loginName, passwordModel.OldPassword, passwordModel.NewPassword); if (success) { response = request.CreateResponse(HttpStatusCode.OK); } else { response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to change password."); } //_SecurityAdapter.LogOut(); return response; })); }
public ActionResult ChangePassword() { AccountChangePasswordModel model = new AccountChangePasswordModel { Input = new AccountChangePasswordInputModel() }; return(View(model)); }
public HttpResponseMessage ChangePassword(HttpRequestMessage request, [FromBody] AccountChangePasswordModel changePasswordModel) { return(GetHttpResponse(request, () => { var loginID = User.Identity.Name; _SecurityAdapter.Initialize(); var status = _SecurityAdapter.ChangePassword(loginID, changePasswordModel.OldPassword, changePasswordModel.NewPassword); return request.CreateResponse <bool>(HttpStatusCode.OK, status); })); }
public ActionResult AccountChangePassword(AccountChangePasswordModel model) { if (ModelState.IsValid) { var user = _userService.GetById(model.Id); user.Password = Crypto.Encrypt(model.Password); if (_userService.Update(user) != null) { return(Json("1", JsonRequestBehavior.AllowGet)); } return(Json("-1", JsonRequestBehavior.AllowGet)); } return(PartialView("_AccountChangePassword", model)); }
public void ChangePassword_Post_ReturnsViewIfChangePasswordFails() { // Arrange var model = new AccountChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; // Act ActionResult result = _accountController.ChangePassword(model); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); var viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("The current password is incorrect or the new password is invalid.", _accountController.ModelState[""].Errors[0].ErrorMessage); }
public void ChangePassword_Post_ReturnsRedirectOnSuccess() { // Arrange var model = new AccountChangePasswordModel { Email = "*****@*****.**", OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; // Act ActionResult result = _accountController.ChangePassword(model); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); var redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]); }
public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange var model = new AccountChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; _accountController.ModelState.AddModelError("", "Dummy error message."); // Act ActionResult result = _accountController.ChangePassword(model); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); var viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); }
public HttpResponseMessage ChangePassword(HttpRequestMessage request, [FromBody] AccountChangePasswordModel passwordModel) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; ValidateAuthorizedUser(passwordModel.LoginEmail); bool success = _SecurityAdapter.ChangePassword(passwordModel.LoginEmail, passwordModel.OldPassword, passwordModel.NewPassword); if (success) { response = request.CreateResponse(HttpStatusCode.OK); } else { response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to change password."); } return response; })); }
public ActionResult ChangePassword(AccountChangePasswordModel model) { var currentUser = _userService.GetLoginSessionUser(User.Id); if (!currentUser.ValidatePassword(model.CurrentPassword)) { ModelState.AddModelError("", "Your current password is incorrect."); return(View()); } if (currentUser.ValidatePassword(model.NewPassword)) { ModelState.AddModelError("", "Your new password cannot be the same as your old password."); return(View()); } currentUser.SetPassword(model.NewPassword); _userService.SetPassword(currentUser.Id, model.NewPassword); return(RedirectToAction("changepassword").AndAlert(AlertType.Success, "Success.", "Your password was updated successfully.")); }
public void T01_ChangePassword() { var authController = new AuthController(Container.GetInstance <IUserService>(), Container.GetInstance <ILoginManager>(), Container.GetInstance <IEmailTemplatesRepository>()); authController.ControllerContext = Controller.ControllerContext; authController.Login(new AuthLogInModel { Email = User.Email, Password = "******" }); var result = Controller.ChangePassword() as ViewResult; Assert.IsNotNull(result, "Change password view result is null"); var model = new AccountChangePasswordModel { CurrentPassword = "", NewPassword = "******", ConfirmNewPassword = "******" }; // Check validation Validate(model); Assert.AreNotEqual(0, Validate(model).Count, "Change password model validation failed"); // Wrong current password model.CurrentPassword = "******"; var wrongResult = Controller.ChangePassword(model) as ViewResult; Assert.IsNotNull(wrongResult, "Change password view result with wrong password return null"); Assert.IsFalse(wrongResult.ViewData.ModelState.IsValid, "Change password model with wrong password has incorrect validation"); //Correct password model.CurrentPassword = "******"; Controller.ModelState.Clear(); var postResult = Controller.ChangePassword(model); Assert.IsNotNull(postResult, "Change password model with correct password has incorrect validation"); }
public void T01_ChangePassword() { var authController = new AuthController(ObjectFactory.GetInstance <IUserService>(), ObjectFactory.GetInstance <ILoginManager>(), ObjectFactory.GetInstance <IEmailService>()); InitControllerContext(authController, _user); authController.Login(new AuthLogInModel { Email = _user.Email, Password = "******" }); var result = _controller.ChangePassword() as ViewResult; Assert.IsNotNull(result); var model = new AccountChangePasswordModel { CurrentPassword = "", NewPassword = "******", ConfirmNewPassword = "******" }; // Check validation Validate(model); Assert.AreNotEqual(0, Validate(model).Count, "Change password model validation failed"); // Wrong current password model.CurrentPassword = "******"; var wrongResult = _controller.ChangePassword(model) as ViewResult; Assert.IsNotNull(wrongResult); Assert.IsFalse(wrongResult.ViewData.ModelState.IsValid); //Correct password model.CurrentPassword = "******"; _controller.ModelState.Clear(); var postResult = _controller.ChangePassword(model); Assert.IsNotNull(postResult); }
public async Task <ActionResult> ResetPassword(string code, AccountChangePasswordModel model) { if (!ModelState.IsValid) { ViewBag.Code = code; ViewBag.Email = model.Email; return(View(model)); } var result = await _membershipService.ResetPasswordAsync(new AccountResetPasswordModel { Code = WebUtility.UrlEncode(code), Password = model.Password, Email = model.Email }); if (result.Code != 200) { ShowMessage(new Models.GenericMessageViewModel { Type = MessageTypes.warning, Message = result.Error }); return(View(model)); } ShowMessage(new Models.GenericMessageViewModel { Type = MessageTypes.success, Message = $"Password was successfully changed" }); return(RedirectToAction(nameof(Login))); }
public async Task ChangePasswordAsync([FromBody] AccountChangePasswordModel model) { var id = int.Parse(HttpContext.User.FindFirst(c => c.Type == ClaimTypes.Sid).Value); await _authService.ChangePasswordAsync(id, model.PasswordOld, model.PasswordNew, _configuration["ServerSecret"]); }
public ActionResult AccountChangePassword() { var model = new AccountChangePasswordModel(); return(PartialView("_AccountChangePassword", model)); }