Example #1
0
 public ActionResult Login(Models.UserViewModels.LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         BlogSystem.IBLL.IUserManager user = new UserManager();
         Guid userId;
         if (user.Login(model.Email, password: model.LoginPwd, out userId))
         {
             if (model.Remember)
             {
                 Response.Cookies.Add(new HttpCookie(name: "loginName")
                 {
                     Value   = model.Email,
                     Expires = DateTime.Now.AddDays(7)
                 });
                 Response.Cookies.Add(new HttpCookie(name: "userId")
                 {
                     Value   = userId.ToString(),
                     Expires = DateTime.Now.AddDays(7)
                 });
             }
             else
             {
                 Session["loginName"] = model.Email;
                 Session["userId"]    = userId;
             }
             return(RedirectToAction("AritcleList2", "Article"));
         }
         else
         {
             ModelState.AddModelError(key: "", errorMessage: "用户名或密码错误!");
         }
     }
     return(View(model));
 }
        public ActionResult Login(Models.UserViewModels.LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                IBLL.IUserManage manage = new UserManager();
                Guid             userId;
                if (manage.Login(model.Email, model.Password, out userId))
                {
                    if (model.IsRemember)
                    {
                        Response.Cookies.Add(new HttpCookie("userName")
                        {
                            Value   = model.Email,
                            Expires = DateTime.Now.AddDays(10)
                        });
                        Response.Cookies.Add(new HttpCookie("userId")
                        {
                            Value   = userId.ToString(),
                            Expires = DateTime.Now.AddDays(10)
                        });
                    }
                    else
                    {
                        Session["userName"] = model.Email;
                        Session["userId"]   = userId;
                    }

                    return(RedirectToAction("main", "Home"));
                }
                else
                {
                    ModelState.AddModelError("LoginError", "您的账号或密码有误");
                }
            }

            return(View(model));
        }