Browse files

Fixed #19061 -- added is_active attribute to AbstractBaseUser

  • Loading branch information...
ptone committed Oct 4, 2012
1 parent f1cc2be commit 4ea8105120121c7ef0d3dd6eb23f2bf5f55b496a
@@ -209,10 +209,12 @@ def clean_email(self):
UserModel = get_user_model()
email = self.cleaned_data["email"]
self.users_cache = UserModel.objects.filter(email__iexact=email,
self.users_cache = UserModel.objects.filter(email__iexact=email)
if not len(self.users_cache):
raise forms.ValidationError(self.error_messages['unknown'])
if not any(user.is_active for user in self.users_cache):
# none of the filtered users are active
raise forms.ValidationError(self.error_messages['unknown'])
if any((user.password == UNUSABLE_PASSWORD)
for user in self.users_cache):
raise forms.ValidationError(self.error_messages['unusable'])
@@ -232,6 +232,8 @@ class AbstractBaseUser(models.Model):
password = models.CharField(_('password'), max_length=128)
last_login = models.DateTimeField(_('last login'),
is_active = True
class Meta:
@@ -88,3 +88,20 @@ class ExtensionUser(AbstractUser):
class Meta:
app_label = 'auth'
class IsActiveTestUser1(AbstractBaseUser):
This test user class and derivatives test the default is_active behavior
username = models.CharField(max_length=30, unique=True)
objects = BaseUserManager()
USERNAME_FIELD = 'username'
class Meta:
app_label = 'auth'
# the is_active attr is provided by AbstractBaseUser
@@ -1,4 +1,5 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
from django.contrib.auth.tests.utils import skipIfCustomUser
@@ -98,3 +99,34 @@ def test_empty_username(self):
'The given username must be set',
User.objects.create_user, username='')
class IsActiveTestCase(TestCase):
Tests the behavior of the guaranteed is_active attribute
def test_builtin_user_isactive(self):
user = User.objects.create(username='foo', email='')
# is_active is true by default
self.assertEqual(user.is_active, True)
user.is_active = False
user_fetched = User.objects.get(
# the is_active flag is saved
def test_is_active_field_default(self):
tests that the default value for is_active is provided
UserModel = get_user_model()
user = UserModel(username='foo')
self.assertEqual(user.is_active, True)
# you can set the attribute - but it will not save
user.is_active = False
# there should be no problem saving - but the attribute is not saved
user_fetched = UserModel.objects.get(
# the attribute is always true for newly retrieved instance
self.assertEqual(user_fetched.is_active, True)
@@ -1911,6 +1911,15 @@ password resets. You must then provide some key implementation details:
``REQUIRED_FIELDS`` must contain all required fields on your User
model, but should *not* contain the ``USERNAME_FIELD``.
.. attribute:: User.is_active
A boolean attribute that indicates whether the user is considered
"active". This attribute is provided as an attribute on
``AbstractBaseUser`` defaulting to ``True``. How you choose to
implement it will depend on the details of your chosen auth backends.
See the documentation of the :attr:`attribute on the builtin user model
<django.contrib.auth.models.User.is_active>` for details.
.. method:: User.get_full_name():
A longer formal identifier for the user. A common interpretation

0 comments on commit 4ea8105

Please sign in to comment.