diff options
| author | Tom Christie | 2012-04-11 17:38:47 +0100 |
|---|---|---|
| committer | Tom Christie | 2012-04-11 17:38:47 +0100 |
| commit | 4739e1c012526c3ed9835d908d6d7eff5e3c48f6 (patch) | |
| tree | 800f2133bf50449e2698f562d5d1d2dd199168e3 /djangorestframework/authentication.py | |
| parent | 44df8345f3ffcba141ded3a1bd993971d7199164 (diff) | |
| parent | 1ff741d1ccc38f099a7159bdef787e5c04dc4f79 (diff) | |
| download | django-rest-framework-4739e1c012526c3ed9835d908d6d7eff5e3c48f6.tar.bz2 | |
Merge work from sebpiq
Diffstat (limited to 'djangorestframework/authentication.py')
| -rw-r--r-- | djangorestframework/authentication.py | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/djangorestframework/authentication.py b/djangorestframework/authentication.py index cb95fb81..3ddd9e45 100644 --- a/djangorestframework/authentication.py +++ b/djangorestframework/authentication.py @@ -1,10 +1,7 @@ """ The :mod:`authentication` module provides a set of pluggable authentication classes. -Authentication behavior is provided by mixing the :class:`mixins.AuthMixin` class into a :class:`View` class. - -The set of authentication methods which are used is then specified by setting the -:attr:`authentication` attribute on the :class:`View` class, and listing a set of :class:`authentication` classes. +Authentication behavior is provided by mixing the :class:`mixins.RequestMixin` class into a :class:`View` class. """ from django.contrib.auth import authenticate @@ -23,12 +20,6 @@ class BaseAuthentication(object): All authentication classes should extend BaseAuthentication. """ - def __init__(self, view): - """ - :class:`Authentication` classes are always passed the current view on creation. - """ - self.view = view - def authenticate(self, request): """ Authenticate the :obj:`request` and return a :obj:`User` or :const:`None`. [*]_ @@ -87,12 +78,14 @@ class UserLoggedInAuthentication(BaseAuthentication): Returns a :obj:`User` if the request session currently has a logged in user. Otherwise returns :const:`None`. """ - if getattr(request, 'user', None) and request.user.is_active: + user = getattr(request._request, 'user', None) + + if user and user.is_active: # Enforce CSRF validation for session based authentication. resp = CsrfViewMiddleware().process_view(request, None, (), {}) if resp is None: # csrf passed - return request.user + return user return None |
