private Employer CreateEmployer(string linkedInId)
        {
            var employer = new Employer
            {
                EmailAddress = new EmailAddress {
                    Address = EmailAddress
                },
                IsActivated = true,
                IsEnabled   = true,
                PhoneNumber = new PhoneNumber {
                    Number = PhoneNumber, Type = PhoneNumberType.Mobile
                },
                FirstName    = FirstName,
                LastName     = LastName,
                Organisation = _organisationsCommand.CreateTestOrganisation(0),
                JobTitle     = "Archeologist",
                SubRole      = EmployerSubRole.Employer,
            };

            var profile = new LinkedInProfile {
                Id = linkedInId
            };

            _employerAccountsCommand.CreateEmployer(employer, profile);
            return(employer);
        }
Exemple #2
0
        private void CreateEmployer(IOrganisation organisation, CreateEmployerModel model)
        {
            var employer = new Employer
            {
                Organisation = organisation,
                SubRole      = model.SubRole,
                EmailAddress = new EmailAddress {
                    Address = model.EmailAddress, IsVerified = true
                },
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                JobTitle    = model.JobTitle,
                PhoneNumber = _phoneNumbersQuery.GetPhoneNumber(model.PhoneNumber, ActivityContext.Location.Country),
            };

            if (model.IndustryId != null)
            {
                employer.Industries = new List <Industry> {
                    _industriesQuery.GetIndustry(model.IndustryId.Value)
                }
            }
            ;

            // Create the account, where the password must be changed at next login.

            var credentials = new LoginCredentials
            {
                LoginId            = model.LoginId,
                Password           = model.Password,
                PasswordHash       = LoginCredentials.HashToString(model.Password),
                MustChangePassword = true,
            };

            _employerAccountsCommand.CreateEmployer(employer, credentials);

            var members = _accountReportsQuery.GetUsers(UserType.Member, DateTime.Now);

            _emailsCommand.TrySend(new NewEmployerWelcomeEmail(employer, model.LoginId, model.Password, members));
        }
Exemple #3
0
        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)));
        }
Exemple #4
0
 private static void CreateTestEmployer(this IEmployerAccountsCommand employersCommand, Employer employer, string loginId)
 {
     employersCommand.CreateEmployer(employer, new LoginCredentials {
         LoginId = loginId, PasswordHash = LoginCredentials.HashToString(DefaultPassword)
     });
 }