#25392: Allow contrib.auth to work without sessions
------------------------------+--------------------------------------
Reporter: rdaysky | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Comment (by rdaysky):
Doing this would not be complex because the middleware in question isn’t
complex. In my project, I work around the issues with just the code below.
And maybe the problem of the session DB backend making a write query upon
first attempt to read something from it (the insanity of this rivals the
invention of atime) should be separated into a standalone issue.
{{{
class
FastSessionMiddleware(django.contrib.sessions.middleware.SessionMiddleware):
def process_request(self, request):
if is_api_request(request) and settings.SESSION_COOKIE_NAME not in
request.COOKIES:
return
super(FastSessionMiddleware, self).process_request(request)
def process_response(self, request, response):
if is_api_request(request):
return response
return super(FastSessionMiddleware,
self).process_response(request, response)
class
FastAuthenticationMiddleware(django.contrib.auth.middleware.AuthenticationMiddleware):
def process_request(self, request):
if hasattr(request, "session"):
return super(FastAuthenticationMiddleware,
self).process_request(request)
request.user = django.contrib.auth.models.AnonymousUser()
assert not
hasattr(django.contrib.auth.middleware.AuthenticationMiddleware,
"process_response")
def fast_login(request, user, remember=False):
if not hasattr(request, "session"):
assert not remember
request.user = user
return
auth.login(request, user)
request.session.set_expiry(None if remember else 0)
# also related, would appreciate this controlled by a settings item:
django.contrib.auth.signals.user_logged_in.disconnect(django.contrib.auth.models.update_last_login)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25392#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.d4231aa187f28352a42be37283808318%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.