Example #1
0
        public ActionResult Login(string token = "")
        {
            string uName       = Request.Form["userName"];
            string uPwd        = Request.Form["userPassword"];
            string uValidate   = Request.Form["validate"];
            string serviceCode = Session["ValidateCode"] as string;//服务器端验证码

            if (!string.IsNullOrEmpty(uName) && !string.IsNullOrEmpty(uPwd) && uValidate.Equals(serviceCode))
            {
                try
                {
                    if (ScanDataBaseManager.IsUser(uName, uPwd))
                    {
                        Guid guid = Guid.NewGuid();

                        CookieTools.AddCookie("token", guid.ToString(), "");
                        CookieTools.AddCookie("uName", uName, "");

                        CacheTools.CacheInsert(uName, guid.ToString(), DateTime.Now.AddDays(1));

                        TempData["LoginState"] = 1;

                        return(Redirect("Index"));
                    }
                }
                catch (Exception e)
                {
                }
            }

            return(View("Login"));
        }