예제 #1
0
        public ActionResult LoginCheck()
        {
            var userBll = new UserBll();

            if (!string.IsNullOrEmpty(Request.Params["username"]))
            {
                string username = Request.Params["username"].ToString();
                string password = Request.Params["password"].ToString();
                var    user     = userBll.CheckUserPassword(username, password);
                if (user != null)
                {
                    Session["username"] = user.user_name;
                    UserLoginLog ull = new UserLoginLog()
                    {
                        user_id = user.user_id, browser = Request.Browser.Browser, kdate = DateTime.Now, ip = Request.UserHostAddress
                    };
                    HttpCookie cookie = new HttpCookie("UserInfoRemember");
                    if (cookie != null)
                    {
                        Session["username"] = cookie["username"] = user.user_name;
                        Session["password"] = cookie["password"] = user.user_password;
                        Session["mobile"]   = cookie["mobile"] = user.user_telephone;
                        Session["user_id"]  = cookie["user_id"] = user.user_id.ToString();;
                        return(Redirect("Index"));
                    }
                    userBll.AddUserLoginLog(ull);
                    return(Redirect("index"));
                }
                else
                {
                    return(Redirect("login"));
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Request.Params["mobile"]))
                {
                    string mobile        = Request.Params["mobile"].ToString();
                    string generate_code = Request.Params["generate_code"].ToString();
                    var    user          = userBll.CheckUserGenerateCode(Session["generate_code"].ToString(), generate_code, mobile);
                    if (user != null)
                    {
                        Session["username"] = user.user_name;
                        UserLoginLog ull = new UserLoginLog()
                        {
                            user_id = user.user_id, browser = Request.Browser.Browser, kdate = DateTime.Now, ip = Request.UserHostAddress
                        }; HttpCookie cookie = new HttpCookie("UserInfoRemember");
                        if (cookie != null)
                        {
                            Session["username"] = cookie["username"] = user.user_name;
                            Session["password"] = cookie["password"] = user.user_password;
                            Session["mobile"]   = cookie["mobile"] = user.user_telephone;
                            Session["user_id"]  = cookie["user_id"] = user.user_id.ToString();;
                            return(Redirect("Index"));
                        }
                        userBll.AddUserLoginLog(ull);
                        return(Redirect("index"));
                    }
                    else
                    {
                        return(Redirect("login"));
                    }
                }
            }
            return(View("login"));
            // return View();
        }