Esempio n. 1
0
        public ActionResult ChangePassword(UserChangePasswordViewModel objEntity)
        {
            int result = 0;
            UserRepository objUserRepository = new UserRepository();
            if (ModelState.IsValid)
            {

                objEntity.NewPassword = objEntity.NewPassword.Trim();
                objEntity.OldPassword = objEntity.OldPassword.Trim();
                objEntity.UserEmail = SessionWrapper.UserAccount.UserEmail;

                result = ValidateUserChangePassword(objEntity);

                if (result == ResultFlags.Success.GetHashCode())
                {
                    this.Flash("success", "Password updated successfully");

                    AccountRepository.Logout();
                    return RedirectToAction("Login", "Admin");

                }
                else if (result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("Error", "Password failed to update");

                }
                else if (result == ResultFlags.OldPasswordMismatch.GetHashCode())
                {
                    this.Flash("Warning", "Old password and new password cannot be same");

                }

            }
            return View(objEntity);
        }
        public ActionResult ChangePassword(UserChangePasswordViewModel objEntity)
        {
            var objUserRepository = new UserRepository();
            if (ModelState.IsValid)
            {

                objEntity.NewPassword = objEntity.NewPassword.Trim();
                objEntity.OldPassword = objEntity.OldPassword.Trim();

                var objUserViewModel = objUserRepository.Update(UserFlags.UpdatePasswordByID.GetHashCode(),

                    new UserViewModel()
                    {
                        UserId = SessionWrapper.UserAccount.UserID,
                        UserEmail = SessionWrapper.UserAccount.UserEmail,
                        OldPassword = objEntity.OldPassword,
                        Password = objEntity.NewPassword
                    }
                    );
                if (objUserViewModel.Result == ResultFlags.Success.GetHashCode())
                {
                    this.Flash("success", "Password updated successfully ");

                    return RedirectToAction("Dashboard", "Admin");
                }
                else if (objUserViewModel.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("error", "Password failed to update");

                }
                else if (objUserViewModel.Result == ResultFlags.OldPasswordMismatch.GetHashCode())
                {
                    this.Flash("warning", "Old Password mismatch");

                }

            }
            return View(objEntity);
        }
Esempio n. 3
0
        public int ValidateUserChangePassword(UserChangePasswordViewModel objEntity)
        {
            int result = 0;
            AccountRepository objAccountRepository = new AccountRepository();
            var objUserRepository = new UserRepository();
            var objLoginUserViewModel = objAccountRepository.GetUserDetailsforLogin(UserFlags.UserSignIn.GetHashCode(), new UserLoginViewModel() { UserEmail = objEntity.UserEmail });

            if (objLoginUserViewModel != null)
            {
                if (PasswordHelpers.Validate(objLoginUserViewModel.Password, objLoginUserViewModel.PasswordSalt, objEntity.NewPassword))
                {
                    result = ResultFlags.OldPasswordMismatch.GetHashCode();

                }
                else
                {
                    PasswordHelpers.HashedPassword objHashedPassword = PasswordHelpers.Generate(objEntity.NewPassword);
                    var objNewUserViewModel = new UserViewModel()
                    {
                        UserId = SessionWrapper.UserAccount.UserId,
                        UserEmail = SessionWrapper.UserAccount.UserEmail,
                        PasswordSalt = objHashedPassword.Salt,
                        Password = objHashedPassword.Password
                    };

                    objNewUserViewModel = objUserRepository.Update(UserFlags.UpdatePasswordByID.GetHashCode(), objNewUserViewModel);
                    result = objNewUserViewModel.Result;

                }

            }

            return result;
        }