def check_email(request, details, user=None, *args, **kwargs):
    """Ask the user to enter the email if we don't have one yet

    The pipeline process was cut prior to this custom pipeline function, and will resume to this same function after completing
    """
    response = None
    if user is None:
        social_email = details.get('email')
        collected_email = request.session.get(SOCIAL_REGISTRATION_SETTING_EMAIL)
        if social_email:
            # email available from social auth
            user = get_user_by_email(social_email)
            if user and user.is_active:
                # a user is already associated with this email
                # TODO: there is an error with linking accounts...
                request.session[SOCIAL_REGISTRATION_SETTING_EMAIL] = social_email
                response = redirect('account_register_social_login')
        elif collected_email:
            # email provided by user
            details['email'] = collected_email
            response = { 'details' : details }
        else:
            # no email provided from social auth
            request.session[SOCIAL_REGISTRATION_SETTING_MISSING_EMAIL] = True
            response = redirect('account_register_social_email')

    return response
Пример #2
0
    def test_view_register(self):
        view_name = 'account_register'

        email = create_test_email()
        password = create_test_password()

        user = get_user_by_email(email)
        self.assertIsNone(user,
                          'The user with email [%s] should not exist before registration.' %
                          email)

        params = {
            'email' : email,
            'password1' : password,
            'password2' : password,
        }
        response = self._post(view_name, params=params, follow=True)
        redirect_chain = response.redirect_chain
        self.assertTrue(len(redirect_chain) > 0,
                        'Registration should have succeeded')

        user = get_user_by_email(email)
        self.assertIsNotNone(user,
                             'The user with email [%s] should exist after registration.' %
                             email)

        self.assertFalse(user.is_active,
                         'User should not be active until email address is confirmed')
        self.assertEqual(email,
                         user.email,
                         'User email does not match registration email')

        # should not be able to register twice
        response = self._post(view_name, params=params, follow=True)
        redirect_chain = response.redirect_chain
        self.assertTrue(len(redirect_chain) == 0,
                        'Repeat registration should have failed.')
        self.assertEqual(200,
                         response.status_code,
                         'Repeat registration should have failed.')

        
        client = Client()
        login_success = client.login(username=user.username, password=password)
        self.assertFalse(login_success,
                        'Should not be able to log in before account is activated, after registration')

        user_email = get_user_email(user, email)
        user_email.confirm_and_activate_account()

        client = Client()
        login_success = client.login(username=user.username, password=password)
        self.assertTrue(login_success,
                        'Should be able to log in after account is activated, after registration')

        # register post when already logged in
        # this can happen if someone is logged out, goes to register page
        # and then logs in in a separate tab, leaving register page open
        self._check_view_redirects_to_another(view_name,
                                              'account_home',
                                              client=client,
                                              params=params)