예제 #1
0
파일: Join.aspx.cs 프로젝트: formist/LinkMe
        private void OnJoin()
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            // Try to create the member account.

            var member      = ucJoin.GetMember();
            var credentials = ucJoin.GetUserCredentials();

            Guid?communityId = null;
            var  community   = _communitiesQuery.GetCurrentCommunity();

            if (community != null && community.HasMembers)
            {
                communityId = community.Id;
            }

            try
            {
                _memberAccountsCommand.CreateMember(member, credentials, communityId);
            }
            catch (DuplicateUserException)
            {
                valDuplicateEmail.IsValid = false;
                return;
            }

            // Do all the steps needed.

            _referralsManager.CreateReferral(HttpContext.Current.Request, member.Id);
            _authenticationManager.LogIn(new HttpContextWrapper(HttpContext.Current), member, AuthenticationStatus.Authenticated);

            // Now that everything is OK redirect to the next page in the process.

            NavigationManager.Redirect(JoinRoutes.Join.GenerateUrl());
        }
예제 #2
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)));
        }