示例#1
0
        /// <summary>
        /// Logs in the current user.
        /// </summary>
        public ActionResult Login()
        {
            string login   = Request["login"];
            string passwd  = Request["password"];
            string returl  = Request["returnurl"];
            string failurl = Request["failureurl"];
            bool   persist = Request["remeberme"] == "1";

            if (!SysUser.LoginUser(login, passwd, persist) && !String.IsNullOrEmpty(failurl))
            {
                return(Redirect(failurl));
            }

            if (!String.IsNullOrEmpty(returl))
            {
                return(Redirect(returl));
            }
            return(Redirect("~/"));
        }
示例#2
0
        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        public void HandleRequest(HttpContext context, params string[] args)
        {
            if (args != null && args.Length > 0)
            {
                if (args[0].ToLower() == "login")
                {
                    string login   = context.Request["login"];
                    string passwd  = context.Request["password"];
                    string returl  = context.Request["returnurl"];
                    bool   persist = context.Request["remeberme"] == "1";

                    SysUser.LoginUser(login, passwd, persist);
                    if (!String.IsNullOrEmpty(returl))
                    {
                        context.Response.Redirect(returl);
                    }
                    else
                    {
                        context.Response.Redirect("~/");
                    }
                }
                else if (args[0].ToLower() == "logout")
                {
                    string returl = context.Request["returnurl"];

                    FormsAuthentication.SignOut();
                    if (!String.IsNullOrEmpty(returl))
                    {
                        context.Response.Redirect(returl);
                    }
                    else
                    {
                        context.Response.Redirect("~/");
                    }
                }
            }
        }