Added LoginView401

This commit is contained in:
Peter 2024-03-23 19:00:50 +01:00 committed by GitHub
parent 01dabf7c05
commit a614708fe7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -49,6 +49,7 @@ from paperless.views import GroupViewSet
from paperless.views import ProfileView from paperless.views import ProfileView
from paperless.views import SocialAccountProvidersView from paperless.views import SocialAccountProvidersView
from paperless.views import UserViewSet from paperless.views import UserViewSet
from paperless.views import LoginView401
from paperless_mail.views import MailAccountTestView from paperless_mail.views import MailAccountTestView
from paperless_mail.views import MailAccountViewSet from paperless_mail.views import MailAccountViewSet
from paperless_mail.views import MailRuleViewSet from paperless_mail.views import MailRuleViewSet
@ -215,6 +216,7 @@ urlpatterns = [
login_required(ensure_csrf_cookie(IndexView.as_view())), login_required(ensure_csrf_cookie(IndexView.as_view())),
name="base", name="base",
), ),
path("accounts/login/", LoginView401.as_view(), name="login")
] ]

View File

@ -5,6 +5,7 @@ from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.models import SocialAccount from allauth.socialaccount.models import SocialAccount
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.views import LoginView
from django.db.models.functions import Lower from django.db.models.functions import Lower
from django.http import HttpResponse from django.http import HttpResponse
from django.http import HttpResponseBadRequest from django.http import HttpResponseBadRequest
@ -223,3 +224,7 @@ class SocialAccountProvidersView(APIView):
] ]
return Response(sorted(resp, key=lambda p: p["name"])) return Response(sorted(resp, key=lambda p: p["name"]))
class LoginView401(LoginView):
def form_invalid(self, form):
return self.render_to_response(self.get_context_data(form=form), status=401)