Apply lstephan's suggestions

This commit is contained in:
Martin Pépin 2020-05-13 13:25:47 +02:00
parent e3c3513a21
commit 8bf8700b36

View file

@ -1,7 +1,7 @@
from django.conf import settings from django.conf import settings
from django.contrib import auth from django.contrib import auth
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.views.generic import RedirectView, TemplateView from django.views.generic import TemplateView, View
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -44,7 +44,7 @@ class LoginSwitchView(NextPageMixin, TemplateView):
return ctx return ctx
class CASLoginView(NextPageMixin, RedirectView): class CASLoginView(NextPageMixin, View):
"""CAS authentication view. """CAS authentication view.
Implement the CAS authentication scheme: Implement the CAS authentication scheme:
@ -57,20 +57,19 @@ class CASLoginView(NextPageMixin, RedirectView):
http_method_names = ["get"] http_method_names = ["get"]
def get_redirect_url(self, *args, **kwargs): def get(self, request, *args, **kwargs):
request = self.request
ticket = request.GET.get("ticket") ticket = request.GET.get("ticket")
if not ticket: if not ticket:
request.session["CASNEXT"] = self.next_page_url() request.session["CASNEXT"] = self.next_page_url()
cas_client = get_cas_client(request) cas_client = get_cas_client(request)
return cas_client.get_login_url() return redirect(cas_client.get_login_url())
user = auth.authenticate(request, ticket=ticket) user = auth.authenticate(request, ticket=ticket)
if user is None: if user is None:
raise PermissionDenied(_("Connection échouée !")) raise PermissionDenied(_("Connection échouée !"))
auth.login(request, user) auth.login(request, user)
return self.next_page_url() return redirect(self.next_page_url())
class PasswordLoginView(auth.views.LoginView): class PasswordLoginView(auth.views.LoginView):