Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""
This module is no more needed. It could be useful for implementing Django-level authentication.
Now it works using DRF-level authentication -- dating.apps.mongo_auth.authentication.MongoTokenAuthentication.
So it's here JFYI.
"""
# from django.contrib import auth
from django.utils.functional import SimpleLazyObject
from .models import User, AnonymousUser
def _get_user(request):
'''FIXME: Implement real auth method is separate module'''
username = request.GET.get('username')
user = User.objects(username=username).first()
return user or AnonymousUser()
def get_user(request):
if not hasattr(request, '_cached_user'):
# request._cached_user = auth.get_user(request)
request._cached_user = _get_user(request)
return request._cached_user
class MongoAuthMiddleware(object):
def process_request(self, request):
request.user = SimpleLazyObject(lambda: get_user(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment