Commit 80c3e389915b7684ad14fa526db285c1af180b29
1 parent
eaa21c11
Exists in
master
and in
39 other branches
Moved REMOTE_USER_DATA to ColabProxyView
Showing
3 changed files
with
18 additions
and
34 deletions
Show diff stats
colab/accounts/middleware.py
... | ... | @@ -1,33 +0,0 @@ |
1 | -from json import dumps as json_dumps | |
2 | - | |
3 | -from colab.accounts.models import User | |
4 | -from colab.proxy.utils.views import ColabProxyView | |
5 | - | |
6 | - | |
7 | -class RemoteUserMiddleware(object): | |
8 | - | |
9 | - def process_view(self, request, view_func, view_args, view_kwargs): | |
10 | - if not request.user.is_authenticated(): | |
11 | - return | |
12 | - | |
13 | - if not hasattr(view_func, 'im_class'): | |
14 | - return | |
15 | - | |
16 | - if not issubclass(view_func.im_class, ColabProxyView): | |
17 | - return | |
18 | - | |
19 | - user = User.objects.get( | |
20 | - username=request.user.get_username() | |
21 | - ) | |
22 | - | |
23 | - remote_user_data = {} | |
24 | - | |
25 | - remote_user_data['email'] = user.email | |
26 | - remote_user_data['name'] = user.username | |
27 | - | |
28 | - request.META['REMOTE_USER_DATA'] = json_dumps( | |
29 | - remote_user_data, | |
30 | - sort_keys=True, | |
31 | - ) | |
32 | - | |
33 | - return None |
colab/proxy/utils/views.py
1 | 1 | |
2 | +import json | |
3 | + | |
2 | 4 | from django.conf import settings |
3 | 5 | |
4 | 6 | from revproxy.views import ProxyView |
... | ... | @@ -17,3 +19,19 @@ class ColabProxyView(ProxyView): |
17 | 19 | @property |
18 | 20 | def app_label(self): |
19 | 21 | raise NotImplementedError('app_label attribute must be set') |
22 | + | |
23 | + def dispatch(self, request, *args, **kwargs): | |
24 | + | |
25 | + if request.user.is_authenticated(): | |
26 | + | |
27 | + remote_user_data = {} | |
28 | + | |
29 | + remote_user_data['email'] = request.user.email | |
30 | + remote_user_data['name'] = request.user.get_full_name() | |
31 | + | |
32 | + request.META['HTTP_REMOTE_USER_DATA'] = json.dumps( | |
33 | + remote_user_data, | |
34 | + sort_keys=True, | |
35 | + ) | |
36 | + | |
37 | + return super(ColabProxyView, self).dispatch(request, *args, **kwargs) | ... | ... |
colab/settings.py
... | ... | @@ -213,7 +213,6 @@ MIDDLEWARE_CLASSES = ( |
213 | 213 | 'django_mobile.middleware.MobileDetectionMiddleware', |
214 | 214 | 'django_mobile.middleware.SetFlavourMiddleware', |
215 | 215 | 'colab.tz.middleware.TimezoneMiddleware', |
216 | - 'colab.accounts.middleware.RemoteUserMiddleware', | |
217 | 216 | ) |
218 | 217 | |
219 | 218 | # Add the django_browserid authentication backend. | ... | ... |