示例#1
0
    def test_activation_expired(self):
        """
        Activation with a key that's expired should also make
        ``UserenaSignup.objects.activation_user`` return ``False``.

        """
        user = SignupManager.create_user(**self.user_info)

        # Set the date that the key is created a day further away than allowed
        user.date_joined -= datetime.timedelta(
            days=auth_settings.BAPH_ACTIVATION_DAYS + 1)
        session = orm.sessionmaker()
        session.add(user)
        session.commit()

        # Try to activate the user
        SignupManager.activate_user(user.signup.activation_key)

        active_user = session.query(User).filter(
            User.username == 'alice').first()

        # UserenaSignup activation should have failed
        self.failIf(active_user.is_active)

        # The activation key should still be a hash
        self.assertEqual(user.signup.activation_key,
                         active_user.signup.activation_key)
示例#2
0
文件: managers.py 项目: devhub/baph
    def test_activation_expired(self):
        """
        Activation with a key that's expired should also make
        ``UserenaSignup.objects.activation_user`` return ``False``.

        """
        user = SignupManager.create_user(**self.user_info)

        # Set the date that the key is created a day further away than allowed
        user.date_joined -= datetime.timedelta(days=auth_settings.BAPH_ACTIVATION_DAYS + 1)
        session = orm.sessionmaker()
        session.add(user)
        session.commit()

        # Try to activate the user
        SignupManager.activate_user(user.signup.activation_key)

        active_user = session.query(User).filter(User.username=='alice').first()

        # UserenaSignup activation should have failed
        self.failIf(active_user.is_active)

        # The activation key should still be a hash
        self.assertEqual(user.signup.activation_key,
                         active_user.signup.activation_key)
示例#3
0
文件: managers.py 项目: devhub/baph
    def test_activation_invalid(self):
        """
        Activation with a key that's invalid should make
        ``UserenaSignup.objects.activate_user`` return ``False``.

        """
        # Wrong key
        self.failIf(SignupManager.activate_user('wrong_key'))

        # At least the right length
        invalid_key = 10 * 'a1b2'
        self.failIf(SignupManager.activate_user(invalid_key))
示例#4
0
    def test_activation_invalid(self):
        """
        Activation with a key that's invalid should make
        ``UserenaSignup.objects.activate_user`` return ``False``.

        """
        # Wrong key
        self.failIf(SignupManager.activate_user('wrong_key'))

        # At least the right length
        invalid_key = 10 * 'a1b2'
        self.failIf(SignupManager.activate_user(invalid_key))
示例#5
0
文件: managers.py 项目: devhub/baph
    def test_activation_valid(self):
        """
        Valid activation of an user.

        Activation of an user with a valid ``activation_key`` should activate
        the user and set a new invalid ``activation_key`` that is defined in
        the setting ``USERENA_ACTIVATED``.

        """
        user = SignupManager.create_user(**self.user_info)
        active_user = SignupManager.activate_user(user.signup.activation_key)

        # The returned user should be the same as the one just created.
        self.failUnlessEqual(user, active_user)

        # The user should now be active.
        self.failUnless(active_user.is_active)

        # The user should have permission to view and change its profile
        #self.failUnless('view_profile' in get_perms(active_user, active_user.get_profile()))
        #self.failUnless('change_profile' in get_perms(active_user, active_user.get_profile()))

        # The activation key should be the same as in the settings
        self.assertEqual(active_user.signup.activation_key,
                         auth_settings.BAPH_ACTIVATED)
示例#6
0
    def test_activation_valid(self):
        """
        Valid activation of an user.

        Activation of an user with a valid ``activation_key`` should activate
        the user and set a new invalid ``activation_key`` that is defined in
        the setting ``USERENA_ACTIVATED``.

        """
        user = SignupManager.create_user(**self.user_info)
        active_user = SignupManager.activate_user(user.signup.activation_key)

        # The returned user should be the same as the one just created.
        self.failUnlessEqual(user, active_user)

        # The user should now be active.
        self.failUnless(active_user.is_active)

        # The user should have permission to view and change its profile
        #self.failUnless('view_profile' in get_perms(active_user, active_user.get_profile()))
        #self.failUnless('change_profile' in get_perms(active_user, active_user.get_profile()))

        # The activation key should be the same as in the settings
        self.assertEqual(active_user.signup.activation_key,
                         auth_settings.BAPH_ACTIVATED)
示例#7
0
def activate(request,
             activation_key,
             template_name='registration/activate_fail.html',
             retry_template_name='registration/activate_retry.html',
             success_url=django_settings.LOGIN_REDIRECT_URL,
             extra_context=None):
    session = orm.sessionmaker()
    signup = session.query(UserRegistration) \
        .filter_by(activation_key=activation_key) \
        .first()
    if not signup:
        if not extra_context: extra_context = dict()
        return render_to_response(template_name,
                                  extra_context,
                                  context_instance=RequestContext(request))
    if (not signup.activation_key_expired()
            or not settings.BAPH_ACTIVATION_RETRY):
        user = SignupManager.activate_user(activation_key)
        if user:
            auth_user = authenticate(identification=user.email,
                                     check_password=False)
            login(request, auth_user)
            messages.success(request,
                             _('Your account has been activated and '
                               'you have been signed in.'),
                             fail_silently=True)
            if success_url:
                redirect_to = success_url % {'username': user.username}
            else:
                redirect_to = reverse('userena_profile_detail',
                                      kwargs={'username': user.username})
            #TODO this is broken
            return redirect(redirect_to)
        else:
            if not extra_context: extra_context = dict()
            return render_to_response(template_name,
                                      extra_context,
                                      context_instance=RequestContext(request))
    else:
        if not extra_context: extra_context = dict()
        extra_context['activation_key'] = activation_key
        return render_to_response(retry_template_name,
                                  extra_context,
                                  context_instance=RequestContext(request))
示例#8
0
文件: views.py 项目: devhub/baph
def activate(request, activation_key,
             template_name='registration/activate_fail.html',
             retry_template_name='registration/activate_retry.html',
             success_url=django_settings.LOGIN_REDIRECT_URL,
             extra_context=None):
    session = orm.sessionmaker()
    signup = session.query(UserRegistration) \
        .filter_by(activation_key=activation_key) \
        .first()
    if not signup:
        if not extra_context: extra_context = dict()
        return render_to_response(template_name, extra_context,
            context_instance=RequestContext(request))
    if (not signup.activation_key_expired() 
        or not settings.BAPH_ACTIVATION_RETRY):
        user = SignupManager.activate_user(activation_key)
        if user:
            auth_user = authenticate(identification=user.email,
                                     check_password=False)
            login(request, auth_user)
            messages.success(request, _('Your account has been activated and '
                'you have been signed in.'), fail_silently=True)
            if success_url: redirect_to = success_url % {'username': user.username }
            else: redirect_to = reverse('userena_profile_detail', 
                                        kwargs={'username': user.username})
                                        #TODO this is broken
            return redirect(redirect_to)
        else:
            if not extra_context: extra_context = dict()
            return render_to_response(template_name, extra_context,
                context_instance=RequestContext(request))
    else:
        if not extra_context: extra_context = dict()
        extra_context['activation_key'] = activation_key
        return render_to_response(retry_template_name, extra_context,
            context_instance=RequestContext(request))