Ticket #5605: lowercase-email.diff

File lowercase-email.diff, 2.3 KB (added by brodie, 7 years ago)

Updated to work with email addresses without at signs, including a test for that case

  • django/contrib/auth/models.py

     
    104104    def create_user(self, username, email, password=None):
    105105        "Creates and saves a User with the given username, e-mail and password."
    106106        now = datetime.datetime.now()
    107         user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
     107        # Make only the domain lowercase.
     108        parts = email.strip().split('@', 1)
     109        if len(parts) > 1:
     110            parts[1] = parts[1].lower()
     111        email = '@'.join(parts)
     112        user = self.model(None, username, '', '', email, 'placeholder', False, True, False, now, now)
    108113        if password:
    109114            user.set_password(password)
    110115        else:
  • tests/regressiontests/auth_backends/tests.py

     
    7575False
    7676>>> user.has_perms(['auth.test2', 'auth.test3'])
    7777False
     78
     79# bug #5605, preserve the case of the user name (before the @ in the email address)
     80# when creating a user.
     81
     82>>> user = User.objects.create_user('test2', 'tesT@EXAMple.com', 'test')
     83>>> user.email
     84'tesT@example.com'
     85>>> user = User.objects.create_user('test3', 'tesT', 'test')
     86>>> user.email
     87'tesT'
    7888"""}
  • 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
Back to Top