| author | durandn |
| Mon, 14 Mar 2016 15:08:25 +0100 | |
| changeset 35 | e82a0ac6cc2c |
| parent 32 | eb9e83610c99 |
| child 63 | 6bfac7c633a0 |
| permissions | -rw-r--r-- |
| 32 | 1 |
import logging |
2 |
from re import compile |
|
3 |
from urllib.parse import urlencode |
|
4 |
||
| 1 | 5 |
from django.conf import settings |
| 32 | 6 |
from django.shortcuts import redirect |
7 |
||
8 |
logger = logging.getLogger(__name__) |
|
| 1 | 9 |
|
10 |
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
|
11 |
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
|
12 |
EXEMPT_URLS += [compile(expr) for expr in settings.OAUTH_EXEMPT_URLS] |
| 1 | 13 |
|
14 |
class MtdcLoginRequiredWithContextMiddleware: |
|
15 |
""" |
|
16 |
Middleware intended to emulate login_required decorator so we can forward the context query arg |
|
17 |
""" |
|
18 |
def process_request(self, request): |
|
19 |
if not request.user.is_authenticated(): |
|
20 |
path = request.path_info.lstrip('/') |
|
21 |
if not any(m.match(path) for m in EXEMPT_URLS): |
|
| 32 | 22 |
logger.debug("LOGIN_REQUIRED: User is not logged and this request triggered Oauth redirects") |
| 1 | 23 |
if request.GET.get("context", ""): |
24 |
context = request.GET["context"] |
|
25 |
response = redirect(settings.LOGIN_URL) |
|
|
35
e82a0ac6cc2c
used '%r' and removed '+str()' in logger.debug() calls
durandn
parents:
32
diff
changeset
|
26 |
logger.debug("LOGIN_REQUIRED: will redirect to %r", settings.LOGIN_URL) |
|
e82a0ac6cc2c
used '%r' and removed '+str()' in logger.debug() calls
durandn
parents:
32
diff
changeset
|
27 |
logger.debug("LOGIN_REQUIRED: query args will be %r", {"context": context, "next": settings.BASE_URL+path}) |
| 27 | 28 |
response["LOCATION"] += "?"+urlencode({"context": context, "next": settings.BASE_URL+path}) |
| 1 | 29 |
return response |