Пример #1
0
        public IActionResult ResetPass([FromForm] VMPwdReset formData)
        {
            UserInfo dt = null;

            switch (Convert.ToInt32(formData.Step))
            {
            case 1:
                dt = _dbAccess.SpCheckUser(formData.txtUserName.Trim().ToUpper());
                if (dt != null)
                {
                    Session["UserCheck"] = dt;
                    ViewBag.SQ           = dt.User_SQ.ToString().ToUpper();
                    ViewBag.Step         = 2;
                }
                else
                {
                    ViewBag.Step = 1;
                    ViewBag.Msg  = "No user exists with this user name.";
                }
                break;

            case 2:
                dt = Session.Get <UserInfo>("UserCheck");
                if (dt.User_SA.ToString().ToUpper() == formData.txtSA.Trim().ToUpper())
                {
                    ViewBag.Step = 3;
                }
                else
                {
                    ViewBag.SQ   = dt.User_SQ.ToString().ToUpper();
                    ViewBag.Step = 2;
                    ViewBag.Msg  = "Security answer is wrong.";
                }
                break;

            case 3:
                dt = Session.Get <UserInfo>("UserCheck");
                dt.User_LoginPassword = formData.txtRePass.Trim();
                if (_dbAccess.SpChangePassword(dt))
                {
                    ViewBag.Msg  = "Password reset successfully.";
                    ViewBag.Step = 1;
                }
                else
                {
                    ViewBag.Step = 3;
                    ViewBag.Msg  = "Error .## Oops some problems occured !";
                }

                break;

            default:
                ViewBag.Step = 1;
                break;
            }
            return(View());
        }
 public IActionResult ChangePassword([FromForm] VMPwdReset obj)
 {
     try
     {
         if (Session["UserInfo"] != null)
         {
             var user_info = Session.Get <UserInfo>("UserInfo");
             if (user_info.User_LoginPassword.ToString() == obj.txtCurrentPass.Trim())
             {
                 user_info.User_LoginPassword = obj.txtNewRePass.Trim();
                 if (_dbAccess.SpChangePassword(user_info))
                 {
                     TempData["Msg"] = "Password Changed Successfully.";
                     return(RedirectToAction("ChangePassword"));
                 }
                 else
                 {
                     throw new Exception("Oops some problems occured !");
                 }
             }
             else
             {
                 throw new Exception("Current password is not correct !");
             }
         }
         else
         {
             throw new Exception("No user is logged in !");
         }
     }
     catch (Exception ex)
     {
         TempData["Msg"] = "Error. ## " + ex.Message;
         return(RedirectToAction("ChangePassword"));
     }
 }