Merge branch 'Aufinal/oldcas_option' into 'master'

Rend l'auth vieilleux optionnelle

See merge request klub-dev-ens/authens!18
This commit is contained in:
Martin Pepin 2020-07-30 11:23:20 +02:00
commit 788924b942
5 changed files with 24 additions and 6 deletions

View file

@ -1,2 +1,3 @@
LDAP_SERVER_URL = "ldaps://ldap.spi.ens.fr:636"
AUTHENS_USE_OLDCAS = True
# TODO: CAS_SERVER_URL

View file

@ -13,8 +13,10 @@
<a class="big-button exte" href="{% url "authens:login.pwd" %}?next={{ next| urlencode }}">
{% trans "Mot de passe" %}
</a>
<a class="big-button oldcas" href="{% url "authens:login.oldcas" %}?next={{ next| urlencode }}">
{% trans "Vieilleux" %}
</a>
{% if oldcas %}
<a class="big-button oldcas" href="{% url "authens:login.oldcas" %}?next={{ next| urlencode }}">
{% trans "Vieilleux" %}
</a>
{% endif %}
</div>
{% endblock %}

View file

@ -1,13 +1,13 @@
from django.conf import settings
from django.urls import path
from authens import views
from authens import conf as default_conf, views
app_name = "authens"
urlpatterns = [
path("login/choose", views.LoginSwitchView.as_view(), name="login"),
path("login/cas", views.CASLoginView.as_view(), name="login.cas"),
path("login/pwd", views.PasswordLoginView.as_view(), name="login.pwd"),
path("login/oldcas", views.OldCASLoginView.as_view(), name="login.oldcas"),
path("logout", views.LogoutView.as_view(), name="logout"),
path("reset/pwd", views.PasswordResetView.as_view(), name="reset.pwd"),
path(
@ -16,3 +16,8 @@ urlpatterns = [
name="reset.pwd.confirm",
),
]
if getattr(settings, "AUTHENS_USE_OLDCAS", default_conf.AUTHENS_USE_OLDCAS):
urlpatterns += (
path("login/oldcas", views.OldCASLoginView.as_view(), name="login.oldcas"),
)

View file

@ -11,6 +11,7 @@ from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView, View
from authens import conf as default_conf
from authens.forms import OldCASAuthForm
from authens.utils import get_cas_client
@ -47,7 +48,15 @@ class LoginSwitchView(NextPageMixin, TemplateView):
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx["next"] = self.get_next_url()
ctx.update(
{
"next": self.get_next_url(),
"oldcas": getattr(
settings, "AUTHENS_USE_OLDCAS", default_conf.AUTHENS_USE_OLDCAS
),
}
)
return ctx

View file

@ -130,6 +130,7 @@ AUTHENTICATION_BACKENDS = [
LOGIN_URL = reverse_lazy("authens:login")
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
AUTHENS_USE_OLDCAS = False
# This is cosmetic
LOGIN_REDIRECT_URL = reverse_lazy("home")