Exemple #1
0
    def test_user_activation_token_generator(self):
        """
        Validate if user can be activated
        """
        activation_token = UserActivationTokenGenerator()
        token = activation_token.generate(self.user)
        self.assertTrue(activation_token.is_valid(self.user, token))
        self.assertFalse(activation_token.is_valid(self.user, "bad token"))

        # Invalid for different user
        user2 = test_utils.create_user()
        self.assertFalse(activation_token.is_valid(user2, token))

        # Invalid after login
        test_utils.login(self)
        user = test_utils.User.objects.get(pk=self.user.pk)
        self.assertFalse(activation_token.is_valid(user, token))
Exemple #2
0
    def test_user_activation_token_generator(self):
        """
        Validate if user can be activated
        """
        activation_token = UserActivationTokenGenerator()
        token = activation_token.generate(self.user)
        self.assertTrue(activation_token.is_valid(self.user, token))
        self.assertFalse(activation_token.is_valid(self.user, "bad token"))

        # Invalid for different user
        user2 = test_utils.create_user()
        self.assertFalse(activation_token.is_valid(user2, token))

        # Invalid after login
        test_utils.login(self)
        user = test_utils.User.objects.get(pk=self.user.pk)
        self.assertFalse(activation_token.is_valid(user, token))
Exemple #3
0
    def test_user_activation_token_generator(self):
        """
        Validate if user can be activated
        """
        self.user.is_verified = False

        activation_token = UserActivationTokenGenerator()
        token = activation_token.generate(self.user)
        self.assertTrue(activation_token.is_valid(self.user, token))
        self.assertFalse(activation_token.is_valid(self.user, "bad token"))

        # Invalid after verification
        self.user.is_verified = True
        self.assertFalse(activation_token.is_valid(self.user, token))

        # Invalid for different user
        user2 = test_utils.create_user()
        self.assertFalse(activation_token.is_valid(user2, token))
Exemple #4
0
    def test_user_activation_token_generator(self):
        """
        Validate if user can be activated
        """
        self.user.is_verified = False

        activation_token = UserActivationTokenGenerator()
        token = activation_token.generate(self.user)
        self.assertTrue(activation_token.is_valid(self.user, token))
        self.assertFalse(activation_token.is_valid(self.user, "bad token"))

        # Invalid after verification
        self.user.is_verified = True
        self.assertFalse(activation_token.is_valid(self.user, token))

        # Invalid for different user
        user2 = test_utils.create_user()
        self.assertFalse(activation_token.is_valid(user2, token))
Exemple #5
0
def registration_activation(request, pk, token):
    user = get_object_or_404(User, pk=pk)
    activation = UserActivationTokenGenerator()

    if activation.is_valid(user, token):
        user.is_active = True
        user.save()
        messages.info(request, _("Your account has been activated!"))

    return redirect(reverse('spirit:user-login'))
Exemple #6
0
def registration_activation(request, pk, token):
    user = get_object_or_404(User, pk=pk)
    activation = UserActivationTokenGenerator()

    if activation.is_valid(user, token):
        user.is_active = True
        user.save()
        messages.info(request, _("Your account has been activated!"))

    return redirect(reverse('spirit:user-login'))