public async Task<ActionResult> Login(LoginModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser user = await UserManager.FindAsync(model.Login, model.Password);
         if (user == null)
         {
             ModelState.AddModelError("", "Неверный логин или пароль.");
         }
         else
         {
             ClaimsIdentity claim = await UserManager.CreateIdentityAsync(user,
                                     DefaultAuthenticationTypes.ApplicationCookie);
             AuthenticationManager.SignOut();
             AuthenticationManager.SignIn(new AuthenticationProperties
             {
                 IsPersistent = true
             }, claim);
             if (String.IsNullOrEmpty(returnUrl))
             {
                 UserId = user.Id;
                 FullName = user.FirstName + " " + user.LastName;
                 return RedirectToAction("Index", "Main");
             }
             return Redirect(returnUrl);
         }
     }
     ViewBag.returnUrl = returnUrl;
     return View(model);
 }
        public User Login(LoginModel loginModel)
        {
            var users = _usersRepository.
                GetAll(user => user.UserName == loginModel.Login && user.Password == loginModel.Password);

            User curUser = null;
            if (users.Count() != 0)
            {
                curUser = users.First();
            }

            if (curUser != null)
            {
                CreateCookie(loginModel.Login, true);
            }
            return curUser;
        }
        public ActionResult Login(LoginModel loginModel)
        {
            if (!ModelState.IsValid) return View(loginModel);

            var user = UserController.ConvertToModel(
                _usersRepositoryHandler.GetUserByEmailPassword(loginModel.Email, loginModel.Password));

            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(loginModel.Email, false);

                HttpContext.Response.Cookies["Role"].Value = user.Role.Name;
                HttpContext.Response.Cookies["Email"].Value = user.Email;

                return user.Role.Name == "Admin" ? RedirectToAction("Roles", "Role") : RedirectToAction("Index", "Main");
            }

            ModelState.AddModelError("", "Неверный логин или пароль");

            return View(loginModel);
        }