File tree 4 files changed +24
-7
lines changed
4 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 4
4
from django .urls import reverse
5
5
6
6
from .models import MFAKey
7
+ from .decorators import login_not_required
7
8
8
9
10
+ @login_not_required
9
11
def custom_login (self , request , extra_context = None ):
10
12
next_url = (
11
13
request .GET .get (REDIRECT_FIELD_NAME )
Original file line number Diff line number Diff line change
1
+ try :
2
+ from stronghold .decorators import public as stronghold_login_not_required
3
+ except ImportError :
4
+ def stronghold_login_not_required (view_func ):
5
+ return view_func
6
+
7
+ try :
8
+ from django .contrib .auth .decorators import login_not_required
9
+ except ImportError :
10
+ def login_not_required (view_func ):
11
+ return view_func
12
+
13
+
1
14
def public (view_func ):
2
15
view_func .mfa_public = True
3
16
return view_func
Original file line number Diff line number Diff line change 15
15
from django .views .generic import ListView
16
16
17
17
from . import settings
18
+ from .decorators import login_not_required
19
+ from .decorators import stronghold_login_not_required
18
20
from .forms import MFAAuthForm
19
21
from .forms import MFACreateForm
20
22
from .mail import send_mail
21
23
from .mixins import MFAFormView
22
24
from .models import MFAKey
23
25
24
- try :
25
- from stronghold .decorators import public as stronghold_public
26
- except ImportError :
27
- def stronghold_public (view_func ):
28
- return view_func
29
-
30
26
31
27
class LoginView (DjangoLoginView ):
32
28
def no_key_exists (self , form ):
@@ -90,7 +86,8 @@ def form_valid(self, form):
90
86
return super ().form_valid (form )
91
87
92
88
93
- @method_decorator (stronghold_public , name = 'dispatch' )
89
+ @method_decorator (login_not_required , name = 'dispatch' )
90
+ @method_decorator (stronghold_login_not_required , name = 'dispatch' )
94
91
class MFAAuthView (MFAFormView ):
95
92
form_class = MFAAuthForm
96
93
Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
3
+ import django
4
+
3
5
DATABASES = {
4
6
'default' : {
5
7
'ENGINE' : 'django.db.backends.sqlite3' ,
21
23
'mfa.middleware.MFAEnforceMiddleware' ,
22
24
]
23
25
26
+ if django .VERSION >= (5 , 1 ):
27
+ MIDDLEWARE .append ('django.contrib.auth.middleware.LoginRequiredMiddleware' )
28
+
24
29
AUTHENTICATION_BACKENDS = [
25
30
'django.contrib.auth.backends.ModelBackend' ,
26
31
]
You can’t perform that action at this time.
0 commit comments