Django1.11-style MiddleWares
The design of middlewares has changed in Django 1.11
This commit is contained in:
parent
8b905f66dc
commit
69f748acbd
2 changed files with 11 additions and 12 deletions
|
@ -50,18 +50,18 @@ INSTALLED_APPS = (
|
||||||
'kfet.apps.KFetConfig',
|
'kfet.apps.KFetConfig',
|
||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE = [
|
||||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
||||||
'kfet.middleware.KFetAuthenticationMiddleware',
|
'kfet.middleware.kfet_auth_middleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
)
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'gestioCOF.urls'
|
ROOT_URLCONF = 'gestioCOF.urls'
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import (absolute_import, division,
|
|
||||||
print_function, unicode_literals)
|
|
||||||
from builtins import *
|
|
||||||
|
|
||||||
from django.http import HttpResponseForbidden
|
|
||||||
from kfet.backends import KFetBackend
|
from kfet.backends import KFetBackend
|
||||||
from kfet.models import Account
|
|
||||||
|
|
||||||
class KFetAuthenticationMiddleware(object):
|
|
||||||
def process_request(self, request):
|
def kfet_auth_middleware(get_response):
|
||||||
kfet_backend = KFetBackend()
|
kfet_backend = KFetBackend()
|
||||||
|
|
||||||
|
def middleware(request):
|
||||||
temp_request_user = kfet_backend.authenticate(request)
|
temp_request_user = kfet_backend.authenticate(request)
|
||||||
if temp_request_user:
|
if temp_request_user:
|
||||||
request.real_user = request.user
|
request.real_user = request.user
|
||||||
request.user = temp_request_user
|
request.user = temp_request_user
|
||||||
|
return get_response(request)
|
||||||
|
|
||||||
|
return middleware
|
||||||
|
|
Loading…
Reference in a new issue