コード例 #1
0
        public async Task <ActionResult> Login(AdminLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                IBLL.IUserManager userManager = new BLL.UserManager();
                Guid userId;
                if (userManager.Login(model.Email, model.LoginPwd, out userId))
                {
                    var usermodel = await userManager.GetUserByEmail(model.Email);

                    if (usermodel.Type == 0)
                    {
                        ModelState.AddModelError("", "该账号没有管理权限");
                        return(View(model));
                    }
                    //跳转
                    //用session还是用cookie
                    if (model.RememberMe)
                    {
                        Response.Cookies.Add(new HttpCookie("loginAdmin")
                        {
                            Value   = model.Email,
                            Expires = DateTime.Now.AddDays(7)
                        });
                        Response.Cookies.Add(new HttpCookie("adminId")
                        {
                            Value   = userId.ToString(),
                            Expires = DateTime.Now.AddDays(7)
                        });
                    }
                    else
                    {
                        Session["loginAdmin"] = model.Email;
                        Session["adminId"]    = userId;
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "用户名密码错误");
                }
            }
            else
            {
                ModelState.AddModelError("", "您的账号密码有误");
            }
            return(View(model));
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: weqan/NewWq
 public ActionResult Login(LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         IBLL.IUserManager userManager = new BLL.UserManager();
         Guid userid;
         if (userManager.Login(model.Email, model.LoginPwd, out userid))
         {
             //跳转
             //用session还是用cookie
             if (model.RememberMe)
             {
                 Response.Cookies.Add(new HttpCookie("loginName")
                 {
                     Value   = model.Email,
                     Expires = DateTime.Now.AddDays(7)
                 });
                 Response.Cookies.Add(new HttpCookie("userId")
                 {
                     Value   = userid.ToString(),
                     Expires = DateTime.Now.AddDays(7)
                 });
             }
             else
             {
                 Session["loginName"] = model.Email;
                 Session["userId"]    = userid;
             }
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("", "用户名密码错误");
         }
     }
     else
     {
         ModelState.AddModelError("", "您的账号密码有误");
     }
     return(View(model));
 }
コード例 #3
0
ファイル: WebApiController.cs プロジェクト: weqan/NewWq
        public IHttpActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                IBLL.IUserManager userManager = new BLL.UserManager();
                if (userManager.Login(model.Email, model.LoginPwd, out Guid userid))
                {
                    return(this.SendData(JwtTools.Encoder(new Dictionary <string, object>()
                    {
                        { "username", model.Email },
                        { "userid", userid }
                    })));
                }
                else
                {
                    return(this.ErrorData("用户名密码错误"));
                }
            }

            return(this.ErrorData("输入数据不合法"));
        }