Skip to content

Commit

Permalink
update pass
Browse files Browse the repository at this point in the history
  • Loading branch information
thuyetbn committed Aug 26, 2021
1 parent d72896c commit 2aa1965
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions Backend/Areas/Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,22 @@ public ActionResult UpdateInfo(ProfileViewModel acc)
data = errors
}, JsonRequestBehavior.AllowGet);
}


public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewModel)
{
var errors = new Dictionary<string, string>();
var user = (Accounts) Session["user"];
var user = (Accounts)Session["user"];
var userUpdate = accounts.Get(user.AccountId);

foreach (var k in ModelState.Keys)
foreach (var err in ModelState[k].Errors)
{
var key = Regex.Replace(k, @"(\w+)\.(\w+)", @"$2");
if (!errors.ContainsKey(key))
errors.Add(key, err.ErrorMessage);
}
foreach (var err in ModelState[k].Errors)
{
var key = Regex.Replace(k, @"(\w+)\.(\w+)", @"$2");
if (!errors.ContainsKey(key))
errors.Add(key, err.ErrorMessage);
}

if (!ModelState.IsValid)
return Json(new
{
Expand All @@ -194,7 +195,7 @@ public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewMod
message = "Error",
}, JsonRequestBehavior.AllowGet);

if (!changePasswordViewModel.OldPassword.Equals(userUpdate.Password))
if (!Utils.ValidatePassword(changePasswordViewModel.OldPassword, userUpdate.Password))
{
errors.Add("OldPassword", "Your password is not correct!");
return Json(new
Expand All @@ -204,7 +205,7 @@ public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewMod
message = "Error",
}, JsonRequestBehavior.AllowGet);
}

if (!changePasswordViewModel.NewPassword.Equals(changePasswordViewModel.ConfirmPassword))
{
errors.Add("ConfirmPassword", "Your confirm is not the same as your new password!");
Expand All @@ -216,7 +217,7 @@ public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewMod
}, JsonRequestBehavior.AllowGet);
}

userUpdate.Password = changePasswordViewModel.NewPassword;
userUpdate.Password = Utils.HashPassword(changePasswordViewModel.NewPassword);
if (!accounts.Edit(userUpdate))
{
return Json(new
Expand All @@ -226,7 +227,7 @@ public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewMod
message = "Error",
}, JsonRequestBehavior.AllowGet);
}

return Json(new
{
statusCode = 200,
Expand Down
2 changes: 1 addition & 1 deletion Backend/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public ActionResult ChangePassword(ChangePasswordViewModel changePasswordViewMod
statusCode = 400,
message = "Error",
}, JsonRequestBehavior.AllowGet);
//!changePasswordViewModel.OldPassword.Equals(userUpdate.Password)

if (!Utils.ValidatePassword(changePasswordViewModel.OldPassword, userUpdate.Password))
{
errors.Add("OldPassword", "Your password is not correct!");
Expand Down

0 comments on commit 2aa1965

Please sign in to comment.