示例#1
0
文件: user.py 项目: BigManager/Spirit
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'))
示例#2
0
文件: user.py 项目: gone/Spirit
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'))
示例#3
0
        def monkey_sender(request, subject, template_name, context, email):
            self.assertEqual(request, req)
            self.assertEqual(email, [self.user.email, ])

            activation_token = UserActivationTokenGenerator()
            token = activation_token.generate(self.user)
            self.assertDictEqual(context, {'token': token, 'user_id': self.user.pk})

            self.assertEqual(subject, _("User activation"))
            self.assertEqual(template_name, 'spirit/user/activation_email.html')

            self._monkey_sender_called = True
示例#4
0
        def monkey_sender(request, subject, template_name, context, email):
            self.assertEqual(request, req)
            self.assertEqual(email, [self.user.email, ])

            activation_token = UserActivationTokenGenerator()
            token = activation_token.generate(self.user)
            self.assertDictEqual(context, {'token': token, 'user_id': self.user.pk})

            self.assertEqual(subject, _("User activation"))
            self.assertEqual(template_name, 'spirit/user/activation_email.html')

            self._monkey_sender_called = True
示例#5
0
 def test_registration_activation(self):
     """
     registration activation
     """
     self.user.is_active = False
     self.user.save()
     token = UserActivationTokenGenerator().generate(self.user)
     response = self.client.get(
         reverse('spirit:registration-activation',
                 kwargs={
                     'pk': self.user.pk,
                     'token': token
                 }))
     expected_url = reverse("spirit:user-login")
     self.assertRedirects(response, expected_url, status_code=302)
     self.assertTrue(User.objects.get(pk=self.user.pk).is_active)
示例#6
0
 def test_registration_activation_invalid(self):
     """
     Activation token should expire after first login
     ActiveUserMiddleware required
     """
     token = UserActivationTokenGenerator().generate(self.user)
     utils.login(self)
     User.objects.filter(pk=self.user.pk).update(is_active=False)
     response = self.client.get(
         reverse('spirit:registration-activation',
                 kwargs={
                     'pk': self.user.pk,
                     'token': token
                 }))
     expected_url = reverse("spirit:user-login")
     self.assertRedirects(response, expected_url, status_code=302)
     self.assertFalse(User.objects.get(pk=self.user.pk).is_active)
示例#7
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))
示例#8
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))
示例#9
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))
示例#10
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))