L'inscription de {{ member.first_name }} {{ member.last_name }} ({{ member.username }}) a été enregistrée avec succès.
- {% if member.profile.is_cof %}Il est désormais membre du COF n°{{ member.profile.num }} !{% endif %}
- {% endif %}
-
- {% include "cof/registration_form.html" %}
-
-{% endblock %}
diff --git a/gestion/forms.py b/gestion/forms.py
index 7584d29e..44e5c778 100644
--- a/gestion/forms.py
+++ b/gestion/forms.py
@@ -4,6 +4,10 @@ from django.contrib.auth.models import User
from .models import Profile
+# ---
+# Profile edition
+# ---
+
class UserForm(forms.ModelForm):
class Meta:
model = User
@@ -14,3 +18,48 @@ class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = ["phone", "departement"]
+
+
+# ---
+# Registration
+# ---
+
+class UserRegistrationForm(forms.ModelForm):
+ passwd1 = forms.CharField(
+ label="Mot de passe",
+ widget=forms.PasswordInput,
+ required=False,
+ )
+ passwd2 = forms.CharField(
+ label="Confirmation de mot de passe",
+ widget=forms.PasswordInput,
+ required=False,
+ )
+
+ def clean_passwd2(self):
+ passwd1 = self.cleaned_data["passwd1"]
+ passwd2 = self.cleaned_data["passwd2"]
+ if passwd1 and passwd2:
+ if passwd1 != passwd2:
+ raise forms.ValidationError("Mots de passes différents")
+ return passwd2
+
+ def save(self, commit=True, *args, **kwargs):
+ user = super().save(commit, *args, **kwargs)
+ if self.cleaned_data["passwd2"]:
+ user.set_password(self.cleaned_data["passwd2"])
+ if commit:
+ user.save()
+ return user
+
+ class Meta:
+ model = User
+ fields = ["username", "first_name", "last_name", "email"]
+
+
+class ProfileRegistrationForm(forms.ModelForm):
+ class Meta:
+ model = Profile
+ fields = [
+ "login_clipper", "phone", "occupation", "departement", "comments"
+ ]
diff --git a/gestion/shared.py b/gestion/shared.py
index 39bc5da7..51ba39c1 100644
--- a/gestion/shared.py
+++ b/gestion/shared.py
@@ -3,6 +3,21 @@ Locking/unlocking tools to prevent tables to be corrupted
"""
from django.db import connection
+from django.contrib.auth.models import User
+from django.conf import settings
+
+
+def get_or_create_clipper(clipper, fullname=None):
+ user, created = User.objects.get_or_create(username=clipper)
+ if created:
+ user.email = settings.CAS_EMAIL_FORMAT % (clipper, )
+ if fullname:
+ bits = fullname.split(" ")
+ user.first_name = bits[0]
+ if len(bits) > 1:
+ user.last_name = " ".join(bits[1:])
+ user.save()
+ return (user, created)
def lock_table(*models):
diff --git a/cof/templates/registration.html b/gestion/templates/gestion/registration.html
similarity index 88%
rename from cof/templates/registration.html
rename to gestion/templates/gestion/registration.html
index e81d7b2b..17b60d3a 100644
--- a/cof/templates/registration.html
+++ b/gestion/templates/gestion/registration.html
@@ -4,14 +4,18 @@
{% block page_size %}col-sm-8{% endblock %}
{% block extra_head %}
-
+
{% endblock %}
{% block realcontent %}
Inscription d'un nouveau membre
+
-
+
+ {% if user %}{% include "gestion/registration_form.html" %}{% endif %}
+