Beispiel #1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                //Validate new password
                if (model.newPswd != model.confirmPswd)
                {
                    ViewBag.message     = AccountResource.ResourceManager.GetString("passwordMismatch");
                    ViewBag.messageType = MessageTypes.Error;
                    return(PartialView(model));
                }

                if (UserInfoModel.UserID <= 0)
                {
                    ViewBag.message     = AccountResource.ResourceManager.GetString("error_PswdChange");
                    ViewBag.messageType = MessageTypes.Error;
                    return(PartialView(model));
                }
                else
                {
                    AccountDbAccess ADA = new AccountDbAccess();
                    string          resetError;

                    if (!ADA.UpdatePassword(UserInfoModel.UserID, model.newPswd, out resetError))
                    {
                        ViewBag.message     = resetError;
                        ViewBag.messageType = MessageTypes.Error;
                        return(PartialView(model));
                    }

                    //Clears login attempt History for specified userId
                    int rows = ADA.ClearLoginAttempts(UserInfoModel.UserID);

                    //Get user with new password to make sure that everything is OK
                    int outputValue;

                    ADA.LogInUser(model.email, model.newPswd, true, Config.clientId, out outputValue);

                    if (outputValue == 0)
                    {
                        ViewBag.message     = "Successfully changed password";
                        ViewBag.messageType = "success";

                        return(JavaScript("window.top.location.href ='" + Url.Action("Index", "Login", new { area = "Account" }) + "';"));
                    }
                    else
                    {
                        //UserInfoModel.UserInfo = SessionWrapper.Get<UserInfoModel>("UserDetail", null);
                        ViewBag.message     = AccountResource.ResourceManager.GetString("criticalError");
                        ViewBag.messageType = MessageTypes.Error;
                        return(PartialView(model));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("Login", "Password couldn't change");

                ViewBag.message     = "Password change failed";
                ViewBag.messageType = "error";
            }
            return(PartialView(model));
        }