public ActionResult Login(FormCollection fc)
        {
            string email    = fc["inputEmail"];
            string password = fc["inputPassword"];

            var users = sysuserRepository.Login(email, password);

            if (users.Count() > 0)
            {
                ViewBag.LoginState = email + "login successfully!";
                var user = users.FirstOrDefault();
                if (user.IsInactive)
                {
                    ViewBag.LoginState = user.UserName + " is Inactive!";
                    return(View());
                }

                Session["username"] = user.UserName;
                Session["userId"]   = user.ID;
                Session["user"]     = user;
                if (user.UserName.Equals("Admin"))
                {
                    return(RedirectToAction("Index", "Categories"));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                ViewBag.LoginState = email + " Not exsit!";
                return(View());
            }
        }
        public async Task <IActionResult> SignIn()
        {
            var account  = Request.Form["account"][0];
            var password = Request.Form["password"][0];
            var msg      = "登录成功";
            var result   = _userRepository.Login(account, password, HttpContext.GetUserIp());

            if (result.Item2 == null)
            {
                msg = "对不起,您输入的用户名或者密码错误";
            }
            else if (!result.Item2.Activable)
            {
                msg = "对不起,该账号已停用";
            }
            else
            {
                var user = new ClaimsPrincipal(
                    new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.Sid, result.Item2.UniqueId),
                    new Claim(ClaimTypes.Name, result.Item2.SysUserName),
                },
                                       CookieAuthenticationDefaults.AuthenticationScheme));
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user,
                                              new AuthenticationProperties
                {
                    IsPersistent = true,
                    ExpiresUtc   = DateTimeOffset.Now.Add(TimeSpan.FromMinutes(30))   // 有效时间
                });
            }
            return(Json(new { success = result.Item1, msg }));
        }