public ActionResult Login(LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         ApplicationUserDTO userDto = new ApplicationUserDTO { UserName = model.Email, Password = model.Password };
         ClaimsIdentity claim = _userService.Authenticate(userDto);
         if (claim == null)
         {
             ModelState.AddModelError("", "Неверный логин или пароль.");
         }
         else
         {
             AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
             AuthenticationManager.SignIn(new AuthenticationProperties
             {
                 IsPersistent = model.IsPersistent
             }, claim);
             return RedirectToAction("Index", "Home");
         }
     }
     return View(model);
 }
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
示例#3
0
        public virtual async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindAsync(model.UserName, model.Password);
                if (user != null)
                {
                    await SignInAsync(user, model.RememberMe);

                    return RedirectToLocal(returnUrl);
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid username or password.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
示例#4
0
 public virtual ActionResult LoginForm()
 {
     var model = new LoginViewModel();
     return View(MVC.Account.Views.LoginForm, model);
 }