コード例 #1
0
        public async Task <RedirectResult> Post([IoCModelBinder(typeof(LoginModelModelBinder))] LoginModel loginModel)
        {
            if (loginModel != null && ModelState.IsValid)
            {
                var result = _loginService.AuthenticateUser(loginModel);
                switch (result.Status)
                {
                case LoginStatus.Success:
                    await _logUserIn.Login(result.User, loginModel.RememberMe);

                    return(Redirect(result.ReturnUrl));

                case LoginStatus.TwoFactorRequired:
                    // if the page doesn't exist, do the standard login
                    if (_uniquePageService.GetUniquePage <TwoFactorCodePage>() == null)
                    {
                        await _logUserIn.Login(result.User, loginModel.RememberMe);

                        return(Redirect(result.ReturnUrl));
                    }

                    _setVerifiedUserData.SetUserData(result.User);
                    return(_uniquePageService.RedirectTo <TwoFactorCodePage>(new { result.ReturnUrl }));

                case LoginStatus.Failure:
                    EventContext.Instance.Publish <IOnFailedLogin, UserFailedLoginEventArgs>(
                        new UserFailedLoginEventArgs(result.User, loginModel.Email));
                    break;

                case LoginStatus.LockedOut:
                    EventContext.Instance.Publish <IOnLockedOutUserAuthed, UserLockedOutEventArgs>(
                        new UserLockedOutEventArgs(result.User));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                loginModel.Message = result.Message;
            }
            TempData["login-model"] = loginModel;

            return(_uniquePageService.RedirectTo <LoginPage>());
        }
コード例 #2
0
        public ActionResult Post(TwoFactorAuthModel model)
        {
            var result = _confirmationService.TryAndConfirmCode(model);

            if (result.Success)
            {
                _logUserIn.Login(result.User, false); //TODO: pass this over
                return(Redirect(result.ReturnUrl));
            }
            return(_uniquePageService.RedirectTo <TwoFactorCodePage>(new { result.ReturnUrl }));
        }