Initial working version with minor bugs
This commit is contained in:
parent
f946e4933a
commit
71b3993326
83 changed files with 34485 additions and 173 deletions
19
django_project/middleware.py
Normal file
19
django_project/middleware.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import login
|
||||
from accounts.models import CustomUser
|
||||
from django.contrib.auth.models import User
|
||||
class AutoLoginMiddleware:
|
||||
"""
|
||||
In development, automatically logs in as a predefined user if the request is anonymous.
|
||||
"""
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
# Only perform auto-login if in DEBUG mode and user is not authenticated.
|
||||
if settings.DEBUG and not request.user.is_authenticated:
|
||||
user = CustomUser.objects.get(email='rob@badblocks.email')
|
||||
login(request, user, backend='django.contrib.auth.backends.ModelBackend')
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
Loading…
Add table
Add a link
Reference in a new issue