File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ from django .contrib .auth import REDIRECT_FIELD_NAME
2+ from django .contrib .auth .decorators import user_passes_test
3+
4+ from trench .command .authenticate_second_factor import authenticate_second_step_command
5+
6+
7+ def mfa_login_required (
8+ function = None , redirect_field_name = REDIRECT_FIELD_NAME , login_url = None
9+ ):
10+ """
11+ Decorator for views that checks that the user is logged in, redirecting
12+ to the log-in page if necessary.
13+ """
14+
15+ def test (user ):
16+ # return user.is_verified() or (user.is_authenticated and not user_has_device(user))
17+ return authenticate_second_step_command
18+
19+ actual_decorator = user_passes_test (
20+ lambda u : u .is_authenticated ,
21+ # test,
22+ login_url = login_url ,
23+ redirect_field_name = redirect_field_name ,
24+ )
25+ if function :
26+ return actual_decorator (function )
27+ return actual_decorator
Original file line number Diff line number Diff line change 1+ from django .contrib .auth .decorators import login_required
12from django .contrib .auth .models import User
23from django .db .models import QuerySet
34from django .utils .translation import gettext_lazy as _
2425 regenerate_backup_codes_for_mfa_method_command ,
2526)
2627from trench .command .set_primary_mfa_method import set_primary_mfa_method_command
28+ from trench .decorators import mfa_login_required
2729from trench .exceptions import MFAMethodDoesNotExistError , MFAValidationError
2830from trench .query .get_mfa_config_by_name import get_mfa_config_by_name_query
2931from trench .responses import ErrorResponse
@@ -210,6 +212,7 @@ class MFAMethodRequestCodeView(APIView):
210212 permission_classes = (IsAuthenticated ,)
211213
212214 @staticmethod
215+ @login_required
213216 def post (request : Request ) -> Response :
214217 serializer = MFAMethodCodeSerializer (data = request .data )
215218 serializer .is_valid (raise_exception = True )
You can’t perform that action at this time.
0 commit comments