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); }
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; }
public ActionResult ManageUserEdit(Int16 id, UserViewModel objEntity) { var objUserRepository = new UserRepository(); if (ModelState.IsValid) { objEntity.UserId = id; objEntity = objUserRepository.Update(UserFlags.UpdateStatusByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { this.Flash("Success", "User details updated successfully"); return RedirectToAction("Index"); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("Error", "User details failed to Update"); } } return View(objEntity); }