Repository navigation
Expand file tree
/
Copy pathauth.py
More file actions
49 lines (39 loc) · 1.49 KB
/
Copy pathauth.py
File metadata and controls
49 lines (39 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from django.conf import settings
from django.contrib.auth import views as auth_views
from bookmarks.widgets import FormErrorList
class LinkdingLoginView(auth_views.LoginView):
"""
Custom login view to lazily add additional context data
Allows to override settings in tests
"""
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.error_class = FormErrorList
return form
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["enable_oidc"] = settings.LD_ENABLE_OIDC
context["disable_login"] = settings.LD_DISABLE_LOGIN_FORM
return context
def form_invalid(self, form):
"""
Return 401 status code on failed login. Should allow integrating with
tools like Fail2Ban. Also, Hotwired Turbo requires a non 2xx status
code to handle failed form submissions.
"""
response = super().form_invalid(form)
response.status_code = 401
return response
class LinkdingPasswordChangeView(auth_views.PasswordChangeView):
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.error_class = FormErrorList
return form
def form_invalid(self, form):
"""
Hotwired Turbo requires a non 2xx status code to handle failed form
submissions.
"""
response = super().form_invalid(form)
response.status_code = 422
return response