Merge pull request #60 from mcallistersean/master
new style middleware
Mike Grouchy authored 6 years ago
GitHub committed 6 years ago
0 | 0 | from django.contrib.auth.decorators import user_passes_test |
1 | 1 | from stronghold import conf, utils |
2 | 2 | |
3 | try: | |
4 | from django.utils.deprecation import MiddlewareMixin | |
5 | except ImportError: | |
6 | MiddlewareMixin = object | |
3 | 7 | |
4 | class LoginRequiredMiddleware(object): | |
8 | ||
9 | class LoginRequiredMiddleware(MiddlewareMixin): | |
5 | 10 | """ |
6 | 11 | Restrict access to users that for which STRONGHOLD_USER_TEST_FUNC returns |
7 | 12 | True. Default is to check if the user is authenticated. |
15 | 20 | """ |
16 | 21 | |
17 | 22 | def __init__(self, *args, **kwargs): |
23 | if MiddlewareMixin != object: | |
24 | super(LoginRequiredMiddleware, self).__init__(*args, **kwargs) | |
18 | 25 | self.public_view_urls = getattr(conf, 'STRONGHOLD_PUBLIC_URLS', ()) |
19 | 26 | |
20 | 27 | def process_view(self, request, view_func, view_args, view_kwargs): |