public LoginResult( LoginAttemptResult result, AdminUser?adminUser = null, List <DelegateUser>?delegateUsers = null, List <CentreUserDetails>?availableCentres = null ) { LoginAttemptResult = result; Accounts = new UserAccountSet(adminUser, delegateUsers); AvailableCentres = availableCentres ?? new List <CentreUserDetails>(); }
public void RedirectsToLoginReturnPageInTempData_WhenLoginSucceeds() { _session.SetupGet(it => it.IsAuthenticated).Returns(false); _authService.Setup(it => it.Authenticate(_username, _password)).Returns(LoginAttemptResult.Success(_createdAccount)); var loginRedirectPage = new PageRoute("LoginRedirectPage"); var controller = new AuthenticationController(_mockSiteMap, _session.Object, _authService.Object); new AuthenticationTempData(controller.TempData).LoginReturnPage.Store(loginRedirectPage); ActionResult actionResult = controller.Login(_username.ToString(), _password.ToString()); AssertRedirectedTo(actionResult, loginRedirectPage); }
public void RedirectsToLoginPage_WhenLoginFails() { _session.SetupGet(it => it.IsAuthenticated).Returns(false); _authService.Setup(it => it.Authenticate(_username, _password)).Returns(LoginAttemptResult.UsernameNotFound()); var controller = new AuthenticationController(_mockSiteMap, _session.Object, _authService.Object); ActionResult actionResult = controller.Login(_username.ToString(), _password.ToString()); AssertRedirectedTo(actionResult, _mockSiteMap.LoginPage); var authTempData = new AuthenticationTempData(controller.TempData); Assert.That(authTempData.ErrorMessages.Get(), Is.Not.Empty); }
private string GetLoginFailureMessage(LoginAttemptResult loginAttemptResult) { switch (loginAttemptResult.FailureReason) { case LoginFailureReason.AccountLockedOut: return "Account is locked out."; case LoginFailureReason.AccountNotActivated: return "Account has not been activated."; case LoginFailureReason.IncorrectPassword: return "Username or password is invalid."; case LoginFailureReason.UsernameNotFound: return "Unknown username."; default: throw new ArgumentOutOfRangeException(); } }
public ActionResult Login(string username, string password) { if (!_session.IsAuthenticated) { LoginAttemptResult loginAttemptResult = _userAuthenticationService.Authenticate(new Username(username), new Password(password)); if (!loginAttemptResult.Succeeded) { var errorMessages = new ErrorMessages { GetLoginFailureMessage(loginAttemptResult) }; TempData.ErrorMessages.Store(errorMessages); TempData.LoginReturnPage.Keep(); return(RedirectToRoute(_siteMap.LoginPage)); } _session.BeginAuthenticatedSession(loginAttemptResult.Account); } return(RedirectToRoute(TempData.LoginReturnPage.Get() ?? _siteMap.GetLandingPage(_session.AuthenticatedAccount))); }
private string GetLoginFailureMessage(LoginAttemptResult loginAttemptResult) { switch (loginAttemptResult.FailureReason) { case LoginFailureReason.AccountLockedOut: return("Account is locked out."); case LoginFailureReason.AccountNotActivated: return("Account has not been activated."); case LoginFailureReason.IncorrectPassword: return("Username or password is invalid."); case LoginFailureReason.UsernameNotFound: return("Unknown username."); default: throw new ArgumentOutOfRangeException(); } }
public LoginAttemptResultStruct(LoginAttemptResult result, string message) { AttemptResult = result; IsAllowed = result == LoginAttemptResult.Ok; Message = message; }
public AttemptLoginResponse(LoginAttemptResult result) { Result = result; }