Ticket #5605: 5605_new.diff

File 5605_new.diff, 2.9 KB (added by Leo Shklovskii, 17 years ago)

more pythonic fix, along with tests and doc changes

  • django/contrib/auth/models.py

     
    108108    def create_user(self, username, email, password=None):
    109109        "Creates and saves a User with the given username, e-mail and password."
    110110        now = datetime.datetime.now()
    111         user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
     111        emailusername, emaildomain = email.strip().split('@', 1)
     112        user = self.model(None, username, '', '', emailusername + '@' + emaildomain.lower(), 'placeholder', False, True, False, now, now)
    112113        if password:
    113114            user.set_password(password)
    114115        else:
     
    226227        for backend in auth.get_backends():
    227228            if hasattr(backend, "get_all_permissions"):
    228229                permissions.update(backend.get_all_permissions(self))
    229         return permissions 
     230        return permissions
    230231
    231232    def has_perm(self, perm):
    232233        """
     
    238239        # Inactive users have no permissions.
    239240        if not self.is_active:
    240241            return False
    241        
     242
    242243        # Superusers have all permissions.
    243244        if self.is_superuser:
    244245            return True
    245            
     246
    246247        # Otherwise we need to check the backends.
    247248        for backend in auth.get_backends():
    248249            if hasattr(backend, "has_perm"):
  • docs/authentication.txt

     
    168168The ``User`` model has a custom manager that has the following helper functions:
    169169
    170170    * ``create_user(username, email, password=None)`` -- Creates, saves and
    171       returns a ``User``. The ``username``, ``email`` and ``password`` are set
    172       as given, and the ``User`` gets ``is_active=True``.
     171      returns a ``User``. The ``username`` and ``password`` are set as
     172      given, the domain portion of ``email`` gets lowercased, and the
     173      ``User`` gets ``is_active=True``.
    173174
    174175      If no password is provided, ``set_unusable_password()`` will be called.
    175176
  • tests/regressiontests/auth_backends/tests.py

     
    6969True
    7070>>> user.has_perms(['auth.test3', 'auth.test_group'])
    7171True
     72
     73# bug #5605, preserve the case of the user name (before the @ in the email address)
     74# when creating a user.
     75
     76>>> user = User.objects.create_user('testusercase2', 'tesT@EXAMple.com', 'test')
     77>>> user.email
     78'tesT@example.com'
     79>>> user = User.objects.create_user('testusercase3', u'tesT@EXAMple.com', 'test')
     80>>> user.email
     81u'tesT@example.com'
    7282"""}
Back to Top