Esempio n. 1
0
        public ActionResult Login(BlogUsers user, bool RememberMe)
        {
            JSData json = new JSData();

            BLL.BlogUsersBLL userBLL    = new BLL.BlogUsersBLL();
            BlogUsers        userResult = userBLL.GetList(t => t.UserName == user.UserName).FirstOrDefault();

            if (userResult == null) //用户不存在
            {
                json.Message = "用户不存在!";
            }
            else if (userResult.UserPass == user.UserPass)     //登录成功
            {
                BLLSession.UserInfoSessioin = userResult;

                if (!string.IsNullOrEmpty(Request.QueryString["href"]))
                {
                    json.JSurl = Request.QueryString["href"];
                }
                else
                {
                    json.JSurl = "/";
                }
                if (RememberMe == true)
                {
                    HttpCookie cookie = CookieHelper.GetCookie("userInfo");
                    if (cookie == null)
                    {
                        cookie = new HttpCookie("userInfo");
                        cookie.Values.Add("userName", user.UserName);
                        cookie.Values.Add("userPass", user.UserPass);
                        cookie.Expires = DateTime.Now.AddMonths(6); //setting the valid time of the cookie  [6 months]
                        CookieHelper.AddCookie(cookie);
                    }
                    else
                    {
                        if (!cookie.Values["userName"].Equals(user.UserName))
                        {
                            CookieHelper.SetCookie("userInfo", "userName", user.UserName, DateTime.Now.AddMonths(6));
                        }
                        if (!cookie.Values["userPass"].Equals(user.UserPass))
                        {
                            CookieHelper.SetCookie("userInfo", "userPass", user.UserPass, DateTime.Now.AddMonths(6));
                        }
                    }
                }
                else
                {
                    CookieHelper.RemoveCookie("userInfo");
                }
            }
            else    //密码错误,登录失败
            {
                json.Message = "密码错误!";
            }
            return(Json(json));
        }
Esempio n. 2
0
 /// <summary>
 /// 获取所有用户信息
 /// </summary>
 /// <returns></returns>
 public static IQueryable <BlogUsers> GetAllUser()
 {
     BLL.BlogUsersBLL user = new BLL.BlogUsersBLL();
     return(user.GetList(t => true));
 }