Пример #1
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var _user = _userManager.LoginUser(model);

                if (_user != null)
                {
                    var claims = new List<Claim>();
                    claims.Add(new Claim(ClaimTypes.Email, model.Email));
                    claims.Add(new Claim(ClaimTypes.Name, _user.UserName));
                    claims.Add(new Claim(ClaimTypes.Role, _user.Role));

                    var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

                    _userManager.Authentication.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = model.RememberMe
                    }, identity);

                    return RedirectToAction("index", "home");

                }

            }

            return View();
        }
 public  ApplicationUser LoginUser(LoginModel model)
 {
     using (ProjectContext _context = new ProjectContext())
     {
         return _context.Users.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password);
     }
 }