diff --git a/portail/__init__.py b/portail/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/portail/apps.py b/portail/apps.py new file mode 100644 index 00000000..2b06c908 --- /dev/null +++ b/portail/apps.py @@ -0,0 +1,36 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017-2020 Gabriel Détraz +# Copyright © 2017-2020 Lara Kermarec +# Copyright © 2017-2020 Augustin Lemesle +# Copyright © 2017-2020 Hugo Levy--Falk +# Copyright © 2017-2020 Jean-Romain Garnier +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +This app provides a clean way to make a subscription, +to make a captive portal. + +This is only sugar, this does not provide any model. +""" + +from django.apps import AppConfig + + +class PortailConfig(AppConfig): + name = 'portail' diff --git a/portail/forms.py b/portail/forms.py new file mode 100644 index 00000000..f144d756 --- /dev/null +++ b/portail/forms.py @@ -0,0 +1,51 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2019 Gabriel Détraz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.utils.translation import gettext_lazy as _ +from re2o.widgets import AutocompleteModelWidget +from users.models import Adherent + + +class AdherentForm(UserCreationForm): + # Champ permettant d'éviter au maximum les doublons d'utilisateurs + former_user_check = forms.BooleanField( + label=_("I certify that I have not had an account before."), + required=True, + help_text=_("If you already have an account, please use it. If your lost access to " + "it, please consider using the forgotten password button on the " + "login page or contacting support.") + ) + + class Meta: + model = Adherent + fields = ("name", "surname", "pseudo", "email", "telephone", "password1", "password2", "room", "school", + "former_user_check",) + widgets = { + "school": AutocompleteModelWidget(url="/users/school-autocomplete"), + "room": AutocompleteModelWidget( + url="/topologie/room-autocomplete", + attrs={ + "data-minimum-input-length": 3 # Only trigger autocompletion after 3 characters have been typed + }, + ), + } diff --git a/portail/templates/portail/signup.html b/portail/templates/portail/signup.html new file mode 100644 index 00000000..db939352 --- /dev/null +++ b/portail/templates/portail/signup.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + +{% load bootstrap3 i18n %} + +{% block custom_js %} + {{ form.media }} +{% endblock %} + +{% block content %} +

{% trans "Sign up" %}

+
+ {% csrf_token %} + {% bootstrap_form form %} + {% trans "Confirm" as tr_confirm %} + {% bootstrap_button tr_confirm button_type="submit" icon='ok' button_class='btn-success' %} +
+{% endblock %} diff --git a/portail/tests.py b/portail/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/portail/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/portail/urls.py b/portail/urls.py new file mode 100644 index 00000000..06601cdf --- /dev/null +++ b/portail/urls.py @@ -0,0 +1,34 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2019 Gabriel Détraz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +This app provides a clean way to make a subscription, +to make a captive portal. + +This is only sugar, this does not provide any model. +""" + +from django.conf.urls import url + +from .views import SignUpView + +urlpatterns = [ + url(r"^signup/$", SignUpView.as_view(), name="signup"), +] diff --git a/portail/views.py b/portail/views.py new file mode 100644 index 00000000..f81b2fe2 --- /dev/null +++ b/portail/views.py @@ -0,0 +1,45 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2019 Gabriel Détraz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django.contrib.auth import login +from django.db import transaction +from django.urls import reverse_lazy +from django.views.generic import CreateView + +from .forms import AdherentForm + + +class SignUpView(CreateView): + form_class = AdherentForm + template_name = "portail/signup.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + return context + + @transaction.atomic + def form_valid(self, form): + ret = super().form_valid(form) + login(self.request, form.instance) + return ret + + def get_success_url(self): + return reverse_lazy("users:profil", args=(self.object.pk,))