示例#1
0
        public IActionResult Login(LoginModel model)
        {
            User user = new UsersHandler().GetUser(model.LoginId, model.Password);

            if (user != null)
            {
                HttpContext.Session.Set(WebUtil.CURRENT_USER, user);
                if (model.RemeberMe)
                {
                    HttpContext.Response.Cookies.Append(
                        "C262",                            //name
                        $"{user.LoginId},{user.Password}", //value
                        new CookieOptions                  //options
                    {
                        IsEssential = true,
                        HttpOnly    = true,
                        MaxAge      = new TimeSpan(7, 0, 0, 0)
                    }
                        );
                }
                if (user.IsInRole(WebUtil.ADMIN))
                {
                    return(RedirectToAction("admin", "home"));
                }
                else
                {
                    return(RedirectToAction("index", "home"));
                }
            }
            return(View());
        }
示例#2
0
        public IActionResult Login()
        {
            string temp = HttpContext.Request.Cookies["C262"];

            if (temp != null)
            {
                string[] loginData = temp.Split(',');
                User     user      = new UsersHandler().GetUser(loginData[0], loginData[1]);
                if (user != null)
                {
                    HttpContext.Session.Set(WebUtil.CURRENT_USER, user);
                    if (user.IsInRole(WebUtil.ADMIN))
                    {
                        return(RedirectToAction("admin", "home"));
                    }
                    else
                    {
                        return(RedirectToAction("index", "home"));
                    }
                }
            }
            return(View());
        }