コード例 #1
0
        public ActionResult ChangePwd(string oldPassword, string newPassword, string reNewPassword)
        {
            WebUserData userData = User.GetUserData();
            string      email    = Convert.ToString(userData.Email);

            if (string.IsNullOrEmpty(oldPassword))
            {
                ModelState.AddModelError("OldPassword", "OldPassword is required");
            }
            else
            {
                if (!AccountBLL.Account_CheckPass(oldPassword, email))
                {
                    ModelState.AddModelError("OldPassword", "Old password incorrect");
                }
                ViewBag.OldPassword = oldPassword;
            }
            if (string.IsNullOrEmpty(newPassword))
            {
                ModelState.AddModelError("NewPassword", "NewPassword is required");
            }
            else
            {
                if (newPassword.Length < 6)
                {
                    ModelState.AddModelError("NewPassword", "Password must over 6 characters");
                }
                ViewBag.NewPassword = newPassword;
            }
            if (string.IsNullOrEmpty(reNewPassword))
            {
                ModelState.AddModelError("ReNewPassword", "ReNewPassword is required");
            }
            else
            {
                if (!newPassword.Equals(reNewPassword))
                {
                    ModelState.AddModelError("ReNewPassword", "The new password does not match the old password");
                }
                ViewBag.ReNewPassword = reNewPassword;
            }
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if (UserAccountBLL.Account_ChangePwd(newPassword, email))
            {
                ModelState.AddModelError("success", "Cập nhật thành công");
                ViewBag.OldPassword   = "";
                ViewBag.NewPassword   = "";
                ViewBag.ReNewPassword = "";
                return(View());
            }
            ModelState.AddModelError("error", "Cập nhật không thành công");
            return(RedirectToAction("ChangePwd"));
        }
コード例 #2
0
        public ActionResult ChangePwd(string oldPassword, string newPassword, string reNewPassword)
        {
            HttpCookie requestCookie = Request.Cookies["userInfo"];
            int        id            = Convert.ToInt32(requestCookie["AccountID"]);

            if (string.IsNullOrEmpty(oldPassword))
            {
                ModelState.AddModelError("OldPassword", "OldPassword is required");
            }
            else
            {
                if (!AccountBLL.Account_CheckPass(oldPassword, id))
                {
                    ModelState.AddModelError("OldPassword", "Old password incorrect");
                }
                ViewBag.OldPassword = oldPassword;
            }
            if (string.IsNullOrEmpty(newPassword))
            {
                ModelState.AddModelError("NewPassword", "NewPassword is required");
            }
            else
            {
                if (newPassword.Length < 6)
                {
                    ModelState.AddModelError("NewPassword", "Password must over 6 characters");
                }
                ViewBag.NewPassword = newPassword;
            }
            if (string.IsNullOrEmpty(reNewPassword))
            {
                ModelState.AddModelError("ReNewPassword", "ReNewPassword is required");
            }
            else
            {
                if (!newPassword.Equals(reNewPassword))
                {
                    ModelState.AddModelError("ReNewPassword", "The new password does not match the old password");
                }
                ViewBag.ReNewPassword = reNewPassword;
            }
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if (AccountBLL.Account_ChangePwd(newPassword, id))
            {
                return(RedirectToAction("SignOut"));
            }
            ModelState.AddModelError("error", "Cập nhật không thành công");
            return(RedirectToAction("ChangePwd"));
        }