-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect to teacher login if trying to 2FA
- Loading branch information
1 parent
921f69b
commit b712218
Showing
1 changed file
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import common.permissions as permissions | ||
from django.contrib.auth.decorators import user_passes_test | ||
from django.urls import reverse_lazy | ||
from django.utils.decorators import method_decorator | ||
from django.views.decorators.cache import never_cache | ||
from two_factor.forms import MethodForm | ||
from two_factor.views.core import SetupView | ||
|
||
|
||
def login_required(function=None): | ||
""" | ||
Decorator for views that checks that the user is logged in, redirecting | ||
to the log-in page if necessary. | ||
""" | ||
actual_decorator = user_passes_test( | ||
permissions.logged_in_as_teacher, | ||
login_url=reverse_lazy("teacher_login"), | ||
) | ||
if function: | ||
return actual_decorator(function) | ||
return actual_decorator | ||
|
||
|
||
# This custom class gets rid of the 'welcome' step of 2FA | ||
# which the new design not needs any more | ||
@method_decorator([never_cache, login_required], name="dispatch") | ||
class CustomSetupView(SetupView): | ||
form_list = ( | ||
("method", MethodForm), | ||
) | ||
form_list = (("method", MethodForm),) |