| author | ymh <ymh.work@gmail.com> |
| Fri, 11 Mar 2016 00:03:15 +0100 | |
| changeset 20 | af79d3dd81f7 |
| parent 15 | 8004d8fc9b38 |
| child 27 | c3c6f2f85680 |
| permissions | -rw-r--r-- |
| 1 | 1 |
from django.shortcuts import redirect |
2 |
from django.conf import settings |
|
3 |
from urllib.parse import urlencode |
|
4 |
from re import compile |
|
5 |
||
6 |
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))] |
|
|
15
8004d8fc9b38
Corrected settings to support deployment in a subdirectory + protected front_list and front_delete so only staff users can access it + added version display in front_list
durandn
parents:
4
diff
changeset
|
7 |
if hasattr(settings, 'OAUTH_EXEMPT_URLS'): |
|
8004d8fc9b38
Corrected settings to support deployment in a subdirectory + protected front_list and front_delete so only staff users can access it + added version display in front_list
durandn
parents:
4
diff
changeset
|
8 |
EXEMPT_URLS += [compile(expr) for expr in settings.OAUTH_EXEMPT_URLS] |
| 1 | 9 |
|
10 |
class MtdcLoginRequiredWithContextMiddleware: |
|
11 |
""" |
|
12 |
Middleware intended to emulate login_required decorator so we can forward the context query arg |
|
13 |
""" |
|
14 |
def process_request(self, request): |
|
15 |
if not request.user.is_authenticated(): |
|
16 |
path = request.path_info.lstrip('/') |
|
17 |
if not any(m.match(path) for m in EXEMPT_URLS): |
|
18 |
if request.GET.get("context", ""): |
|
19 |
context = request.GET["context"] |
|
20 |
response = redirect(settings.LOGIN_URL) |
|
|
15
8004d8fc9b38
Corrected settings to support deployment in a subdirectory + protected front_list and front_delete so only staff users can access it + added version display in front_list
durandn
parents:
4
diff
changeset
|
21 |
print(path) |
|
8004d8fc9b38
Corrected settings to support deployment in a subdirectory + protected front_list and front_delete so only staff users can access it + added version display in front_list
durandn
parents:
4
diff
changeset
|
22 |
response["LOCATION"] += "?"+urlencode({"context": context, "next": settings.URL_SUBDIRECTORY+"/"+path}) |
| 1 | 23 |
return response |