8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

New signup form

This commit is contained in:
Yohann D'ANELLO 2021-02-01 01:32:26 +01:00
parent c2a4b7dd66
commit 71a08a4b19
No known key found for this signature in database
GPG key ID: 3A75C55819C8CF85
7 changed files with 186 additions and 0 deletions

0
portail/__init__.py Normal file
View file

36
portail/apps.py Normal file
View file

@ -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'

51
portail/forms.py Normal file
View file

@ -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
},
),
}

View file

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% load bootstrap3 i18n %}
{% block custom_js %}
{{ form.media }}
{% endblock %}
{% block content %}
<h3>{% trans "Sign up" %}</h3>
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% trans "Confirm" as tr_confirm %}
{% bootstrap_button tr_confirm button_type="submit" icon='ok' button_class='btn-success' %}
</form>
{% endblock %}

3
portail/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

34
portail/urls.py Normal file
View file

@ -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"),
]

45
portail/views.py Normal file
View file

@ -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,))