Esempio n. 1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            _logger.Info("Change password");

            if (ModelState.IsValid)
            {
                Customer customer = _customerAccountService.GetCustomer((int)Session["AccountId"]);
                if (!customer.IsCorrectPassword(model.OldPassword))
                {
                    var errMessage = "wrong old password";
                    _logger.Info(errMessage);

                    ModelState.AddModelError("", errMessage);
                    return(View(model));
                }
                if (!model.IsNewPasswordNew())
                {
                    var errMessage = "New password is the same as old one";
                    _logger.Info(errMessage);

                    ModelState.AddModelError("", errMessage + "! Pick a new password");
                    return(View(model));
                }
                _customerAccountService.UpdatePassword(customer.Id, model.NewPassword);

                _logger.Info("Password change was successful");

                return(Redirect("Index"));
            }
            return(View(model));
        }