Exemple #1
0
        public ActionResult Manage(LocalPasswordModel model)
        {
            ViewBag.HasLocalPassword = true;
            ViewBag.ReturnUrl        = Url.Action("Manage");
            if (ModelState.IsValid)
            {
                // ChangePassword will throw an exception rather than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    changePasswordSucceeded = _accountService.ChangePassword(_accountService.GetId(User.Identity.Name), model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    _formsAuth.SignOut();
                    return(RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }));
                }
                else
                {
                    ViewBag.ErrorMessage = "Last Operation failed. Please retry with valid data.";
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            else
            {
                // User does not have a local password so remove any validation errors caused by a missing
                // OldPassword field
                ModelState state = ModelState["OldPassword"];
                if (state != null)
                {
                    state.Errors.Clear();
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #2
0
        public ActionResult ForgetPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                if (_userAccountService.ChangePassword(model.UserAccountID, model.Password))
                {
                    _forgetPasswordRequestService.InvalidateRequest(model.UserAccountID);
                }

                return(RedirectToAction("Login"));
            }
            return(View(model));
        }
Exemple #3
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            var userid      = UserAccountHelper.GetUser(HttpContext.User.Identity.Name).UserProfileID;
            var oldpassword = _userService.HashPassword(model.OldPassword);

            if (ModelState.IsValid)
            {
                bool changePasswordSucceeded;

                if (_userService.GetUserDetail(userid).Password == oldpassword)
                {
                    try
                    {
                        changePasswordSucceeded = _userService.ChangePassword(userid, model.NewPassword);
                    }
                    catch (Exception e)
                    {
                        changePasswordSucceeded = false;
                        //ModelState.AddModelError("Errors", e.Message);
                    }
                    if (changePasswordSucceeded)
                    {
                        ModelState.AddModelError("Success", @"Password Successfully Changed.");
                    }
                    //return RedirectToAction("ChangePasswordSuccess");
                    else
                    {
                        ModelState.AddModelError("Errors", @"The new password is invalid.");
                    }
                }
                else
                {
                    ModelState.AddModelError("Errors", @"The current password is incorrect ");
                }
            }
            return(View(model));
        }
        public IHttpActionResult ChangePassword(string email, string oldPassword, string newPassword)
        {
            var response = _userAccountService.ChangePassword(email, oldPassword, newPassword);

            return(Ok(response));
        }