-
-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds middleware to enforce 2fa #284
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Middleware to check if staff user has 2FA unabled.""" | ||
|
||
from django.shortcuts import redirect | ||
from django.urls import resolve, reverse | ||
|
||
|
||
class Enforce2FAMiddleware: | ||
"""Enforce 2FA middleware.""" | ||
def __init__(self, get_response): | ||
"""Initialize the middleware.""" | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
"""Wrap around actual Admin calls.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code won't limit itself to just the admin site as it makes no such check. Either code needs to do what the comment says or the comment needs changing. |
||
response = self.get_response(request) | ||
if resolve(request.path).app_name == 'two_factor' or ( | ||
resolve(request.path).url_name == 'logout'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we know the logout URL is called logout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @moggers87 Is there any way of knowing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I know of. |
||
return response | ||
if not request.user.is_verified(): | ||
return redirect(reverse('two_factor:profile')) | ||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package still supports Python 2.7 for Django 1.11, so that should be a subclass of
object
.