diff --git a/elections/mixins.py b/elections/mixins.py index a54c583..484d7da 100644 --- a/elections/mixins.py +++ b/elections/mixins.py @@ -76,7 +76,7 @@ class CreatorOnlyEditMixin(CreatorOnlyMixin, SingleObjectMixin): return filters -class AdministratorOnlyMixin: +class AdministratorOnlyMixin(LoginRequiredMixin): """Restreint l'accès aux admins""" diff --git a/elections/models.py b/elections/models.py index 0eafee0..58befe9 100644 --- a/elections/models.py +++ b/elections/models.py @@ -34,6 +34,12 @@ class Election(models.Model): archived = models.BooleanField(_("archivée"), default=False) + @property + def preferred_method(self): + if self.restricted: + return "PWD" + return "CAS" + class Meta: ordering = ["-start_date", "-end_date"] diff --git a/shared/auth/forms.py b/shared/auth/forms.py index a4e8765..be55a01 100644 --- a/shared/auth/forms.py +++ b/shared/auth/forms.py @@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _ class ElectionAuthForm(forms.Form): - """Adapts Django's AuthenticationForm to allow for OldCAS login.""" + """Adapts Django's AuthenticationForm to allow for an election specific login.""" login = auth_forms.UsernameField(label=_("Identifiant"), max_length=255) password = forms.CharField(label=_("Mot de passe"), strip=False) @@ -17,7 +17,7 @@ class ElectionAuthForm(forms.Form): super().__init__(*args, **kwargs) def clean(self): - login = self.cleaned_data.get("cas_login") + login = self.cleaned_data.get("login") password = self.cleaned_data.get("password") election_id = self.cleaned_data.get("election_id") diff --git a/shared/auth/views.py b/shared/auth/views.py index e9b0986..831e42a 100644 --- a/shared/auth/views.py +++ b/shared/auth/views.py @@ -45,6 +45,8 @@ class LoginSelectView(NextPageMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["next"] = self.get_next_url() + context["method"] = self.request.GET.get("method", "CAS") + context["election_id"] = self.request.GET.get("election_id", None) return context @@ -82,7 +84,7 @@ class PasswordLoginView(auth_views.LoginView): authentication_form = ElectionAuthForm def get_initial(self): - return {"election_id": self.request.GET.get("election", None)} + return {"election_id": self.request.GET.get("election_id", None)} class LogoutView(auth_views.LogoutView): diff --git a/shared/templates/auth/login_select.html b/shared/templates/auth/login_select.html index 37d50df..50af8a0 100644 --- a/shared/templates/auth/login_select.html +++ b/shared/templates/auth/login_select.html @@ -1,3 +1,47 @@ {% extends "base.html" %} {% load i18n %} + +{% block content %} + +