Merge "Revert "Add is_authenticated and is_anonymous properties"" into stable/newton

This commit is contained in:
Jenkins 2016-09-27 16:40:18 +00:00 committed by Gerrit Code Review
commit 55ebf6b792
1 changed files with 23 additions and 40 deletions

View File

@ -14,11 +14,9 @@
import hashlib import hashlib
import logging import logging
import django
from django.conf import settings from django.conf import settings
from django.contrib.auth import models from django.contrib.auth import models
from django.db import models as db_models from django.db import models as db_models
from django.utils import deprecation
from keystoneauth1 import exceptions as keystone_exceptions from keystoneauth1 import exceptions as keystone_exceptions
from keystoneclient.common import cms as keystone_cms from keystoneclient.common import cms as keystone_cms
import six import six
@ -263,50 +261,35 @@ class User(models.AbstractBaseUser, models.AnonymousUser):
return None return None
return not utils.is_token_valid(self.token, margin) return not utils.is_token_valid(self.token, margin)
if django.VERSION >= (1, 10): def is_authenticated(self, margin=None):
@property """Checks for a valid authentication.
def is_authenticated(self):
"""Checks for a valid authentication."""
if (self.token is not None and utils.is_token_valid(self.token)):
return deprecation.CallableTrue
else:
return deprecation.CallableFalse
@property :param margin:
def is_anonymous(self): A security time margin in seconds before end of authentication.
"""Return if the user is not authenticated. Will return ``False`` if authentication ends in less than ``margin``
seconds of time.
A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
django settings.
Returns ``True`` if not authenticated,``False`` otherwise. """
""" return (self.token is not None and
return deprecation.CallableBool(not self.is_authenticated) utils.is_token_valid(self.token, margin))
else:
def is_authenticated(self, margin=None):
"""Checks for a valid authentication.
:param margin: def is_anonymous(self, margin=None):
A security time margin in seconds before end of authentication. """Return if the user is not authenticated.
Will return ``False`` if authentication ends in less than
``margin`` seconds of time.
A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
django settings.
"""
return (self.token is not None and
utils.is_token_valid(self.token, margin))
def is_anonymous(self, margin=None): Returns ``True`` if not authenticated,``False`` otherwise.
"""Return if the user is not authenticated.
Returns ``True`` if not authenticated,``False`` otherwise. :param margin:
A security time margin in seconds before end of an eventual
authentication.
Will return ``True`` even if authenticated but that authentication
ends in less than ``margin`` seconds of time.
A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
django settings.
:param margin: """
A security time margin in seconds before end of an eventual return not self.is_authenticated(margin)
authentication.
Will return ``True`` even if authenticated but that
authentication ends in less than ``margin`` seconds of time.
A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
django settings.
"""
return not self.is_authenticated(margin)
@property @property
def is_active(self): def is_active(self):