Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserManager(models.Manager):
- def create_user(self, username, email, password=None):
- """
- Creates and saves a User with the given username, e-mail and password.
- """
- now = datetime.datetime.now()
- # Normalize the address by lowercasing the domain part of the email
- # address.
- try:
- email_name, domain_part = email.strip().split('@', 1)
- except ValueError:
- pass
- else:
- email = '@'.join([email_name, domain_part.lower()])
- user = self.model(username=username, email=email, is_staff=False,
- is_active=True, is_superuser=False, last_login=now,
- date_joined=now)
- if password:
- user.set_password(password)
- else:
- user.set_unusable_password()
- user.save(using=self._db)
- return user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement