Ejemplo n.º 1
0
        public ActionResult Login()
        {
            string title = "Login";
            Load(title);
            bool simple = ids != null && ids.ContainsKey("simple") && Convert.ToBoolean(ids["simple"]) == true;
            if (user != null)
            {
                return RedirectToAction("Settings");
            }
            if (postData != null)
            {
                try
                {
                    string username = postData["username"];
                    string password = postData["password"];
                    user = new SLUser(-1, username, password, ip, null);
                    if (user.sessionToken != null)
                    {
                        if (simple)
                        {
                            return Content(user.userID + "|" + user.sessionToken);
                        }
                        HttpCookie userIDCookie = new HttpCookie("userID", Convert.ToString(user.userID));
                        userIDCookie.Path = "/";
                        userIDCookie.Domain = ".UnsolvedCrime.ca";
                        HttpCookie sessionTokenCookie = new HttpCookie("sessionToken", Convert.ToString(user.sessionToken));
                        sessionTokenCookie.Path = "/";
                        sessionTokenCookie.Domain = ".UnsolvedCrime.ca";

                        Response.Cookies.Add(userIDCookie);
                        Response.Cookies.Add(sessionTokenCookie);

                        if (ids != null && ids.ContainsKey("preURL"))
                        {
                            return Redirect(ids["preURL"]);
                        }
                        else
                        {
                            return RedirectToAction("Settings");
                        }
                    }
                    else
                    {
                        if (simple)
                        {
                            return Content("false");
                        }
                        else
                        {
                            this.user = null;
                            ViewBag.LoginFailed = true;
                        }
                    }
                }
                catch
                {
                    if (simple)
                    {
                        return Content("false");
                    }
                    else
                    {
                        this.user = null;
                        ViewBag.LoginFailed = true;
                    }
                }
            }
            if (simple)
            {
                return Content("");
            }
            return View(title);
        }
Ejemplo n.º 2
0
        public void LoadUser()
        {
            if (Request.Cookies["userID"] == null)
            {
                return;
            }
            if (Request.Cookies["sessionToken"] == null)
            {
                return;
            }
            try
            {
                int userID = Convert.ToInt32(Request.Cookies["userID"].Value);
                string sessionToken = Convert.ToString(Request.Cookies["sessionToken"].Value);
                this.user = new SLUser(userID, null, null, Request.UserHostAddress, sessionToken);
            }
            catch(Exception e)
            {
                ViewBag.userError = e.Message;
                this.user = null;
            }

            if (this.user != null && this.user.sessionToken == null)
            {
                this.user = null;
            }
            ViewBag.user = this.user;
        }