예제 #1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {

                var client = Request.Browser.Browser;
                var response = HttpRequest.GetHttpRequest("jsonLoginCheck/" + model.UserName + "-" + model.Password+"-" +client);
                var res = JsonConvert.DeserializeAnonymousType(response, new {JsonLoginCheckResult = ""});

                if (res.JsonLoginCheckResult!=null)
                {

                    // check if cookie exists and if yes update
                    HttpCookie existingCookie = Request.Cookies["JsonLoginCheckResult"];
                    if (existingCookie != null)
                    {
                        // force to expire it
                        existingCookie.Value = res.JsonLoginCheckResult;
                        existingCookie.Expires = DateTime.Now.AddHours(-20);
                    }

                    // create a cookie
                    var newCookie = new HttpCookie("JsonLoginCheckResult", res.JsonLoginCheckResult);

                    Response.Cookies.Add(newCookie);

               //         Session.Add("JsonLoginCheckResult", res.JsonLoginCheckResult);
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    return RedirectToAction("Index", "CurrentUser");
                }
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {

                var res = HttpRequest.GetHttpRequest("JsonLoginCheck/" + model.UserName + "-" + model.Password);

                if (res!=null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    return RedirectToAction("Index", "LeaderBoard");
                }
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }