private void CompleteAuthenticatedLogin(AuthenticationStatus status, bool mustChangePassword) { const string method = "CompleteAuthenticatedLogin"; var context = HttpContext.Current; _authenticationManager.LogIn(new HttpContextWrapper(context), _currentUser, status); EventSource.Raise(Event.Trace, method, string.Format("User logged in with Id = '{0}', Role = {1}", _currentUser.Id, _currentUser.UserType)); if (LoginPersist) { _cookieManager.CreatePersistantUserCookie(new HttpContextWrapper(context), _currentUser.UserType, new LoginCredentials { LoginId = UserId, Password = Password }, status); } else { _cookieManager.DeletePersistantUserCookie(new HttpContextWrapper(context)); } OnLoginAuthenticated(mustChangePassword); }
AuthenticationResult IAccountsManager.TryAutoLogIn(HttpContextBase context) { var credentials = _cookieManager.ParsePersistantUserCookie(context); if (string.IsNullOrEmpty(credentials.LoginId) || string.IsNullOrEmpty(credentials.Password)) { return new AuthenticationResult { Status = AuthenticationStatus.Failed } } ; // Authenticate. var result = _loginAuthenticationCommand.AuthenticateUser(new LoginCredentials { LoginId = credentials.LoginId, Password = credentials.Password }); switch (result.Status) { case AuthenticationStatus.Authenticated: // Automatically log in. result.Status = AuthenticationStatus.AuthenticatedAutomatically; _authenticationManager.LogIn(context, result.User, result.Status); break; default: // If it didn't work then ensure the cookies are removed. _cookieManager.DeletePersistantUserCookie(context); break; } return(result); } AuthenticationResult IAccountsManager.LogIn(HttpContextBase context, Login login) { // Process the post to check validations etc. login.Prepare(); login.Validate(); // Authenticate. var result = _loginAuthenticationCommand.AuthenticateUser(new LoginCredentials { LoginId = login.LoginId, PasswordHash = LoginCredentials.HashToString(login.Password) }); switch (result.Status) { case AuthenticationStatus.Authenticated: case AuthenticationStatus.AuthenticatedMustChangePassword: case AuthenticationStatus.AuthenticatedWithOverridePassword: case AuthenticationStatus.Deactivated: // Log in. _authenticationManager.LogIn(context, result.User, result.Status); // Remember me. if (login.RememberMe) { _cookieManager.CreatePersistantUserCookie(context, result.User.UserType, new LoginCredentials { LoginId = login.LoginId, Password = login.Password }, result.Status); } else { _cookieManager.DeletePersistantUserCookie(context); } // Vertical. SetVertical(result.User); break; } // Also log them in as a dev if they used the override password. if (result.Status == AuthenticationStatus.AuthenticatedWithOverridePassword) { _devAuthenticationManager.LogIn(context); } return(result); } void IAccountsManager.LogOut(HttpContextBase context) { // Maintain the vertical. Vertical vertical = null; var verticalId = ActivityContext.Current.Vertical.Id; if (verticalId != null) { vertical = _verticalsQuery.GetVertical(verticalId.Value); } // Clean out remember me and any external authentication cookie. _cookieManager.DeletePersistantUserCookie(context); _cookieManager.DeleteExternalCookie(context, vertical == null ? null : vertical.ExternalCookieDomain); // Log out. _authenticationManager.LogOut(context); // Clean up the session but don't abandon it. context.Session.Clear(); // Reset the vertical. if (vertical != null) { ActivityContext.Current.Set(vertical); } } Member IAccountsManager.Join(HttpContextBase context, MemberAccount account, AccountLoginCredentials accountCredentials, bool requiresActivation) { account.Prepare(); account.Validate(); accountCredentials.Prepare(); accountCredentials.Validate(); // Check for an existing login. if (_loginCredentialsQuery.DoCredentialsExist(new LoginCredentials { LoginId = accountCredentials.LoginId })) { throw new DuplicateUserException(); } // Create the member. var member = CreateMember(account, requiresActivation); var credentials = new LoginCredentials { LoginId = accountCredentials.LoginId, PasswordHash = LoginCredentials.HashToString(accountCredentials.Password), }; _memberAccountsCommand.CreateMember(member, credentials, GetMemberAffiliateId()); // Log the user in. _authenticationManager.LogIn(context, member, AuthenticationStatus.Authenticated); // Initialise. _referralsManager.CreateReferral(context.Request, member.Id); InitialiseMemberProfile(member.Id); return(member); } Employer IAccountsManager.Join(HttpContextBase context, EmployerAccount account, AccountLoginCredentials accountCredentials) { accountCredentials.Prepare(); accountCredentials.Validate(); // Check for an existing login. if (_loginCredentialsQuery.DoCredentialsExist(new LoginCredentials { LoginId = accountCredentials.LoginId })) { throw new DuplicateUserException(); } return(Join( context, account, e => _employerAccountsCommand.CreateEmployer(e, new LoginCredentials { LoginId = accountCredentials.LoginId, PasswordHash = LoginCredentials.HashToString(accountCredentials.Password) }))); } Employer IAccountsManager.Join(HttpContextBase context, EmployerAccount account, LinkedInProfile profile) { return(Join( context, account, e => _employerAccountsCommand.CreateEmployer(e, profile))); }