Commit c1aec0fe authored by Jeremy Lainé's avatar Jeremy Lainé Committed by Tim Graham
Browse files

Fixed #25847 -- Made User.is_(anonymous|authenticated) properties.

parent c16b9dd8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ answer newbie questions, and generally made Django that much better:
    Jérémie Blaser <blaserje@gmail.com>
    Jeremy Carbaugh <jcarbaugh@gmail.com>
    Jeremy Dunck <jdunck@gmail.com>
    Jeremy Lainé <jeremy.laine@m4x.org>
    Jesse Young <adunar@gmail.com>
    jhenry <jhenry@theonion.com>
    Jim Dalton <jim.dalton@gmail.com>
+1 −1
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ def logout(request):
    # Dispatch the signal before the user is logged out so the receivers have a
    # chance to find out *who* logged out.
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated():
    if hasattr(user, 'is_authenticated') and not user.is_authenticated:
        user = None
    user_logged_out.send(sender=user.__class__, request=request, user=user)

+2 −2
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ class ModelBackend(object):
        be either "group" or "user" to return permissions from
        `_get_group_permissions` or `_get_user_permissions` respectively.
        """
        if not user_obj.is_active or user_obj.is_anonymous() or obj is not None:
        if not user_obj.is_active or user_obj.is_anonymous or obj is not None:
            return set()

        perm_cache_name = '_%s_perm_cache' % from_name
@@ -73,7 +73,7 @@ class ModelBackend(object):
        return self._get_permissions(user_obj, obj, 'group')

    def get_all_permissions(self, user_obj, obj=None):
        if not user_obj.is_active or user_obj.is_anonymous() or obj is not None:
        if not user_obj.is_active or user_obj.is_anonymous or obj is not None:
            return set()
        if not hasattr(user_obj, '_perm_cache'):
            user_obj._perm_cache = self.get_user_permissions(user_obj)
+5 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ from django.contrib.auth.hashers import (
)
from django.db import models
from django.utils.crypto import get_random_string, salted_hmac
from django.utils.deprecation import CallableFalse, CallableTrue
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

@@ -79,19 +80,21 @@ class AbstractBaseUser(models.Model):
    def natural_key(self):
        return (self.get_username(),)

    @property
    def is_anonymous(self):
        """
        Always return False. This is a way of comparing User objects to
        anonymous users.
        """
        return False
        return CallableFalse

    @property
    def is_authenticated(self):
        """
        Always return True. This is a way to tell if the user has been
        authenticated in templates.
        """
        return True
        return CallableTrue

    def set_password(self, raw_password):
        self.password = make_password(raw_password)
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_authenticated(),
        lambda u: u.is_authenticated,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
Loading