Skip to content

Commit

Permalink
Redirect to teacher login if trying to 2FA
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Nov 6, 2024
1 parent 921f69b commit b712218
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions portal/views/two_factor/core.py
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

Check warning on line 21 in portal/views/two_factor/core.py

View check run for this annotation

Codecov / codecov/patch

portal/views/two_factor/core.py#L21

Added line #L21 was not covered by tests


# 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),)

0 comments on commit b712218

Please sign in to comment.