magic-removal: fixed #1410. The UserSource class will eventually be replaced with the muti-auth stuff.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2431 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
64330d7355
commit
36bfffccc4
|
@ -1,5 +1,6 @@
|
|||
class RequestUserMiddleware:
|
||||
def process_request(self, request):
|
||||
# TODO: this will be replaced by the muti-auth stuff
|
||||
class UserSource:
|
||||
def get_user(self, request):
|
||||
from django.contrib.auth.models import User, SESSION_KEY
|
||||
try:
|
||||
user_id = request.session[SESSION_KEY]
|
||||
|
@ -9,5 +10,9 @@ class RequestUserMiddleware:
|
|||
except (AttributeError, KeyError, ValueError, User.DoesNotExist):
|
||||
from django.parts.auth import anonymoususers
|
||||
user = anonymoususers.AnonymousUser()
|
||||
request.user = user
|
||||
return user
|
||||
|
||||
class RequestUserMiddleware:
|
||||
def process_request(self, request):
|
||||
request._user_source = UserSource()
|
||||
return None
|
||||
|
|
|
@ -98,6 +98,14 @@ class ModPythonRequest(http.HttpRequest):
|
|||
self._raw_post_data = self._req.read()
|
||||
return self._raw_post_data
|
||||
|
||||
def _get_user(self):
|
||||
if not hasattr(self, '_user'):
|
||||
self._user = self._user_source.get_user(self)
|
||||
return self._user
|
||||
|
||||
def _set_user(self, value):
|
||||
self._user = value
|
||||
|
||||
GET = property(_get_get, _set_get)
|
||||
POST = property(_get_post, _set_post)
|
||||
COOKIES = property(_get_cookies, _set_cookies)
|
||||
|
@ -105,6 +113,7 @@ class ModPythonRequest(http.HttpRequest):
|
|||
META = property(_get_meta)
|
||||
REQUEST = property(_get_request)
|
||||
raw_post_data = property(_get_raw_post_data)
|
||||
user = property(_get_user, _set_user)
|
||||
|
||||
class ModPythonHandler(BaseHandler):
|
||||
def __call__(self, req):
|
||||
|
|
|
@ -119,12 +119,21 @@ class WSGIRequest(http.HttpRequest):
|
|||
self._raw_post_data = self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
|
||||
return self._raw_post_data
|
||||
|
||||
def _get_user(self):
|
||||
if not hasattr(self, '_user'):
|
||||
self._user = self._user_source.get_user(self)
|
||||
return self._user
|
||||
|
||||
def _set_user(self, value):
|
||||
self._user = value
|
||||
|
||||
GET = property(_get_get, _set_get)
|
||||
POST = property(_get_post, _set_post)
|
||||
COOKIES = property(_get_cookies, _set_cookies)
|
||||
FILES = property(_get_files)
|
||||
REQUEST = property(_get_request)
|
||||
raw_post_data = property(_get_raw_post_data)
|
||||
user = property(_get_user, _set_user)
|
||||
|
||||
class WSGIHandler(BaseHandler):
|
||||
def __call__(self, environ, start_response):
|
||||
|
|
Loading…
Reference in New Issue