Ejemplo n.º 1
0
    def clean_email(self):
        """
        Validate that the supplied email address is unique for the
        site.

        """
        user_model = get_user_model()
        if user_model.objects.filter(email__iexact=self.cleaned_data['email']):
            raise forms.ValidationError(_("This email address is already in use. "
                                          "Please supply a different email address."))
        return self.cleaned_data['email']
Ejemplo n.º 2
0
 def clean_username(self):
     """
     Validate that the username is alphanumeric and is not already
     in use.
     """
     user_model = get_user_model()
     try:
         user_model.objects.get(username__iexact=self.cleaned_data['username'])
     except user_model.DoesNotExist:
         return self.cleaned_data['username']
     raise forms.ValidationError(_("A user with that username already exists."))
Ejemplo n.º 3
0
    def create_inactive_user(self, username, email, password, first_name, last_name,
                             site, send_email=True):
        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.

        """
        user_model = get_user_model()
        new_user = user_model.objects.create_user(username, email, password)
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.is_active = False
        new_user.save()

        registration_profile = self.create_profile(new_user)

        if send_email:
            registration_profile.send_activation_email(site)

        return new_user
Ejemplo n.º 4
0
import datetime
import re

from django.conf import settings
from django.contrib.sites.models import Site
from django.core import mail
from django.core import management
from django.test import TestCase
from django.utils.hashcompat import sha_constructor

from registration.models import RegistrationProfile
from registration import get_user_model


TEST_USER_MODEL = get_user_model()


class RegistrationModelTests(TestCase):
    """
    Test the model and manager used in the default backend.

    """
    user_info = {'username': '******',
                 'password': '******',
                 'email': '*****@*****.**',
                 'first_name': 'Alice',
                 'last_name': 'Fish'}

    def setUp(self):
        self.old_activation = getattr(settings, 'ACCOUNT_ACTIVATION_DAYS', None)
        settings.ACCOUNT_ACTIVATION_DAYS = 7
Ejemplo n.º 5
0
 def testGetUserModelFromSettings(self):
     setattr(settings, 'REGISTRATION_USER_MODEL', 'registration_tests.MockUser')
     self.assertEqual(registration.get_user_model(), MockUser)
Ejemplo n.º 6
0
 def testGetUserModelFallback(self):
     self.assertEqual(registration.get_user_model(), User)