예제 #1
0
    def test_view_login_post(self):
        view_name = 'account_login'

        (user, email, password,) = create_test_user_with_email_and_password()
        user_email = associate_user_email(user, email)

        # login with unconfirmed email
        params = {
            'email' : email,
            'password' : password,
        }
        response = self._post(view_name, params=params, follow=True)
        redirect_chain = response.redirect_chain
        self.assertEqual(200,
                         response.status_code,
                         'Should not be able to log in with an unconfirmed email.')
        self.assertEqual(0,
                         len(redirect_chain),
                         'Should not be able to log in with an unconfirmed email.')

        # login with confirmed email
        user_email.is_confirmed = True
        user_email.save()
#        self._check_view_redirects_to_another(view_name,
#                                              'account_home',
#                                              params=params,
#                                              method='post')

        # login with incorrect password
        params['password'] = '******'
        response = self._post(view_name, params=params, follow=True)
        redirect_chain = response.redirect_chain
        self.assertEqual(200,
                         response.status_code,
                         'Should not be able to log in with an incorrect password.')
        self.assertEqual(0,
                         len(redirect_chain),
                         'Should not be able to log in with an incorrect password.')

        # login post when already logged in
        # this can happen if someone is logged out, goes to login page
        # and then logs in in a separate tab, leaving login page open
        client = Client()
        client.login(username=user.username, password=password)
        self._check_view_redirects_to_another(view_name,
                                              'account_home',
                                              client=client,
                                              params=params)
예제 #2
0
    def test_view_confirm_email(self):
        view_name = 'account_confirm_email'
        # invalid confirmation code
        args = ('asdf1234',)
        response = self._get(view_name, view_args = args)
        self.assertEqual(404,
                         response.status_code,
                         'Should not be able to confirm with invalid code')

        # valid confirmation code
        (user, email, password,) = create_test_user_with_email_and_password()
        user_email = associate_user_email(user, email)
        args = (user_email.activation_key,)
        response = self._get(view_name, view_args = args)
        self.assertEqual(200,
                         response.status_code,
                         'Should able to confirm with valid code')
def associate_email(request, details, user, social, *args, **kwargs):
    """Associate email with the user
    """
    if not user or not social:
        return None

    response = None

    email = details.get('email')
    domain = request.get_host()
    # automatically confirm if the email was provided by the social auth provider
    confirmed = not(request.session.get(SOCIAL_REGISTRATION_SETTING_MISSING_EMAIL, False))
    user_email = associate_user_email(user, email, domain, confirmed=confirmed)

    if user_email:
        # need to update the User with the activated one, so that it doesn't get overwritten later on
        response = { 'user': user_email.user }
    return response