Authentification CAS par défaut, permet de choisir entre CAS et mdp lorsque la variable election
exite dans le template
This commit is contained in:
parent
fc695b9cc5
commit
416efd5267
7 changed files with 104 additions and 5 deletions
|
@ -76,7 +76,7 @@ class CreatorOnlyEditMixin(CreatorOnlyMixin, SingleObjectMixin):
|
|||
return filters
|
||||
|
||||
|
||||
class AdministratorOnlyMixin:
|
||||
class AdministratorOnlyMixin(LoginRequiredMixin):
|
||||
"""Restreint l'accès aux admins"""
|
||||
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -1,3 +1,47 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1 class="title">{% trans "Choisissez la méthode de connexion" %}</h1>
|
||||
<hr>
|
||||
|
||||
{# Indications de connexion #}
|
||||
<div class="message is-warning">
|
||||
<div class="message-body">
|
||||
{% if method == "PWD" %}
|
||||
{% trans "Pour voter lors de cette élection, vous devez vous connecter à l'aide des identifiants reçus par mail. Choisissez la connexion par mot de passe." %}
|
||||
{% else %}
|
||||
{% trans "Pour voter lors de cette élection, vous devez vous connecter à l'aide du CAS élève." %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="tile is-ancestor">
|
||||
<div class="tile is-parent">
|
||||
<a class="tile is-child notification is-primary" href="{% url "auth.cas" %}?next={{ next }}">
|
||||
<div class="subtitle has-text-centered mb-2">
|
||||
<span class="icon has-text-white">
|
||||
<i class="fas fa-school"></i>
|
||||
</span>
|
||||
<span class="ml-3">{% trans "Connexion via CAS" %}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="tile is-parent">
|
||||
<a class="tile is-child notification" href="{% url "auth.pwd" %}?next={{ next }}&election_id={{ election_id }}">
|
||||
<div class="subtitle has-text-centered mb-2">
|
||||
<span class="icon">
|
||||
<i class="fas fa-key"></i>
|
||||
</span>
|
||||
<span class="ml-3">{% trans "Connexion par mot de passe" %}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,2 +1,40 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1 class="title">{% trans "Connexion par mot de passe" %}</h1>
|
||||
<hr>
|
||||
|
||||
<div class="columns is-centered">
|
||||
<div class="column is-two-thirds">
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.errors }}
|
||||
|
||||
{% include "forms/form.html" with errors=True %}
|
||||
|
||||
<div class="field is-grouped is-centered">
|
||||
<div class="control is-expanded">
|
||||
<button class="button is-fullwidth is-outlined is-primary is-light">
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-check"></i>
|
||||
</span>
|
||||
<span>{% trans "Enregistrer" %}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<a class="button is-primary" href="{% url 'auth.select' %}?next={{ next }}&election_id={{ election_id }}&method={{ method }}">
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-undo-alt"></i>
|
||||
</span>
|
||||
<span>{% trans "Retour" %}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
<h1 class="has-text-primary-light is-size-1 is-family-secondary">Kadenios</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="level-right pr-5">
|
||||
{% if user.is_authenticated %}
|
||||
<div class="level-item mr-5">
|
||||
|
@ -49,16 +50,24 @@
|
|||
{% blocktrans with name=user.base_username connection=user.connection_method %}Connecté·e en tant que {{ name }} par {{ connection }}{% endblocktrans %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="level-item ml-3">
|
||||
<a class="icon is-size-1 has-text-white" href="{% url 'auth.logout' %}?next={{ view.get_next_url }}">
|
||||
<i class="fas fa-sign-out-alt"></i>
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
<div class="level-item">
|
||||
<a class="icon is-size-1 has-text-white" href="{% url 'auth.select' %}?next={{ request.path }}">
|
||||
{% if election %}
|
||||
<a class="icon is-size-1 has-text-white" href="{% url 'auth.select' %}?next={{ request.path }}&election_id={{ election.id }}&method={{ election.preferred_method }}">
|
||||
<i class="fas fa-sign-in-alt"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="icon is-size-1 has-text-white" href="{% url 'auth.cas' %}?next={{ request.path }}">
|
||||
<i class="fas fa-sign-in-alt"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue