mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #26951 -- Allowed AuthenticationForm to work with a username of 0.
This commit is contained in:
committed by
Tim Graham
parent
74bb013cc1
commit
975a76a964
23
tests/auth_tests/models/with_integer_username.py
Normal file
23
tests/auth_tests/models/with_integer_username.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
|
||||
from django.db import models
|
||||
|
||||
|
||||
class IntegerUsernameUserManager(BaseUserManager):
|
||||
def create_user(self, username, password):
|
||||
user = self.model(username=username)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def get_by_natural_key(self, username):
|
||||
return self.get(username=username)
|
||||
|
||||
|
||||
class IntegerUsernameUser(AbstractBaseUser):
|
||||
username = models.IntegerField()
|
||||
password = models.CharField(max_length=255)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
REQUIRED_FIELDS = ['username', 'password']
|
||||
|
||||
objects = IntegerUsernameUserManager()
|
||||
Reference in New Issue
Block a user