From 3e7234e2a6fc9a4f4f544b0e3e6a94f03627c890 Mon Sep 17 00:00:00 2001 From: Guillim Date: Tue, 18 Jun 2019 15:47:33 +0200 Subject: [PATCH] We go on with authentification: - we set up python restriction related to the environment variable "allow_signup" - we clean a bit html code in base_auth.html - we allow switch between signin and signup --- app/authentification/templates/base_auth.html | 15 ++------------ app/authentification/templates/signup.html | 20 ++++++++++++++++--- app/authentification/views.py | 8 +++++++- app/server/templates/login.html | 9 ++++++++- app/server/views.py | 1 + 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/authentification/templates/base_auth.html b/app/authentification/templates/base_auth.html index 2d1b6c75..2fd0f41c 100644 --- a/app/authentification/templates/base_auth.html +++ b/app/authentification/templates/base_auth.html @@ -2,20 +2,9 @@ {% block content %}
-
-
+
+
{% block content_auth %}{% endblock %} -
diff --git a/app/authentification/templates/signup.html b/app/authentification/templates/signup.html index 74d65be0..c8b4c752 100644 --- a/app/authentification/templates/signup.html +++ b/app/authentification/templates/signup.html @@ -2,10 +2,11 @@ {% load utils_templating %} {% block content_auth %} +{% if allow_signup %}
-
+
{% csrf_token %} {% for field in form %} @@ -24,8 +25,21 @@ {% endfor %}
- + +
+
+ + Already registered ? login +
+ +{% else %} +
+
+ You can't signup yourself, please contact the admin in order to get your username and your password! +
+
+{% endif %} {% endblock %} diff --git a/app/authentification/views.py b/app/authentification/views.py index 49564d9b..78c8108a 100644 --- a/app/authentification/views.py +++ b/app/authentification/views.py @@ -8,16 +8,22 @@ from .tokens import account_activation_token from django.core.mail import EmailMessage from django.views.generic import TemplateView +from app import settings + class SignupView(TemplateView): template_name = 'signup.html' form_class = SignupForm def get(self, request, *args, **kwargs): form = self.form_class() - return render(request, self.template_name, {'form': form}) + return render(request, self.template_name, {'form': form, 'allow_signup': bool(settings.ALLOW_SIGNUP)}) def post(self, request, *args, **kwargs): form = self.form_class(request.POST) + + # here we make sure that a post request won't trigger a subscription in case allow_signup is False + if not bool(settings.ALLOW_SIGNUP): + return redirect('signup') if form.is_valid(): user = form.save(commit=False) diff --git a/app/server/templates/login.html b/app/server/templates/login.html index cc018e2e..558e8410 100644 --- a/app/server/templates/login.html +++ b/app/server/templates/login.html @@ -47,6 +47,13 @@
+ {% if allow_signup %} +
+ + Not registered yet ? Sign up + +
+ {% endif %} {% if social_login_enabled %} @@ -68,4 +75,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/server/views.py b/app/server/views.py index a2df38e3..8d520ccc 100644 --- a/app/server/views.py +++ b/app/server/views.py @@ -90,6 +90,7 @@ class LoginView(BaseLoginView): extra_context = { 'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY), 'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID), + 'allow_signup' : bool(settings.ALLOW_SIGNUP), } def get_context_data(self, **kwargs):