public JsonResult ApiLogon(string userName, string password)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                return(Json(new { result = false, message = "UserName is required." }));
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                return(Json(new { result = false, message = "Password is required." }));
            }

            var result = WebSignInManager.PasswordSignIn(userName, password, false, false);

            switch (result)
            {
            case SignInStatus.Success:
                UserLoggedIn();
                return(Json(new { result = true, message = "Successful" }));

            case SignInStatus.LockedOut:
                return(Json(new { result = false, message = "User is Locked Out." }));

            case SignInStatus.RequiresVerification:
                return(Json(new { result = false, message = "User Requires verification." }));

            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                return(Json(new { result = false, message = "User invalid or not found." }));
            }
        }
        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);

            if (result == SignInStatus.Failure)
            {
                result = await WebSignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
            }

            switch (result)
            {
            case SignInStatus.Success:
                UserLoggedIn();
                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));
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_userManager != null)
                {
                    _userManager.Dispose();
                    _userManager = null;
                }

                if (_signInManager != null)
                {
                    _signInManager.Dispose();
                    _signInManager = null;
                }

                if (_webSignInManager != null)
                {
                    _webSignInManager.Dispose();
                    _webSignInManager = null;
                }
            }

            base.Dispose(disposing);
        }
示例#4
0
 public AccountController(UserService userService, WebSignInManager webSignInManager)
 {
     _userservice      = userService;
     _webSignInManager = webSignInManager;
 }