File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change 11from django .contrib .auth import REDIRECT_FIELD_NAME
22from django .contrib .auth .decorators import user_passes_test
33
4- from trench .command .authenticate_second_factor import authenticate_second_step_command
5-
64
75def mfa_login_required (
86 function = None , redirect_field_name = REDIRECT_FIELD_NAME , login_url = None
@@ -12,13 +10,11 @@ def mfa_login_required(
1210 to the log-in page if necessary.
1311 """
1412
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
13+ def is_user_authenticated (user ):
14+ return user .is_authenticated
1815
1916 actual_decorator = user_passes_test (
20- lambda u : u .is_authenticated ,
21- # test,
17+ is_user_authenticated ,
2218 login_url = login_url ,
2319 redirect_field_name = redirect_field_name ,
2420 )
Original file line number Diff line number Diff line change 1- from django .contrib .auth .decorators import login_required
21from django .contrib .auth .models import User
32from django .db .models import QuerySet
3+ from django .utils .decorators import method_decorator
44from django .utils .translation import gettext_lazy as _
55
66from abc import ABC , abstractmethod
@@ -212,7 +212,6 @@ class MFAMethodRequestCodeView(APIView):
212212 permission_classes = (IsAuthenticated ,)
213213
214214 @staticmethod
215- @login_required
216215 def post (request : Request ) -> Response :
217216 serializer = MFAMethodCodeSerializer (data = request .data )
218217 serializer .is_valid (raise_exception = True )
@@ -228,6 +227,10 @@ def post(request: Request) -> Response:
228227 except MFAValidationError as cause :
229228 return ErrorResponse (error = cause )
230229
230+ @method_decorator (mfa_login_required )
231+ def dispatch (self , * args , ** kwargs ):
232+ return super ().dispatch (* args , ** kwargs )
233+
231234
232235class MFAPrimaryMethodChangeView (APIView ):
233236 permission_classes = (IsAuthenticated ,)
You can’t perform that action at this time.
0 commit comments