Commit 941bd506d6ba1e610a850b4ea987469bee12e92a
Exists in
master
and in
39 other branches
Merge branch 'middleware' into 'master'
Middleware
Showing
1 changed file
with
33 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,33 @@ |
| 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 | ... | ... |