feat(gestionCOF/registration): self registration can create accounts
This commit is contained in:
parent
5bc57493f7
commit
ce9f8f8ac7
3 changed files with 56 additions and 3 deletions
|
@ -307,6 +307,20 @@ class RegistrationKFProfileForm(forms.ModelForm):
|
|||
]
|
||||
|
||||
|
||||
class SelfRegistrationProfileForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kw):
|
||||
super().__init__(*args, **kw)
|
||||
self.fields["occupation"].initial = "Extérieur"
|
||||
|
||||
class Meta:
|
||||
model = CofProfile
|
||||
fields = [
|
||||
"phone",
|
||||
"occupation",
|
||||
"departement",
|
||||
]
|
||||
|
||||
|
||||
STATUS_CHOICES = (
|
||||
("no", "Non"),
|
||||
("wait", "Oui mais attente paiement"),
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% if member %}
|
||||
<h3>Inscription K-Fêt du compte GestioCOF existant <tt>{{ member.username }}</tt></h3>
|
||||
{% else %}
|
||||
<h3>Inscription K-Fêt d'un nouveau compte (extérieur ?)</h3>
|
||||
<h3>Inscription K-Fêt d'un nouveau compte extérieur</h3>
|
||||
{% endif %}
|
||||
<form role="form" id="profile" method="post" action="{% url 'self.kf_registration' %}">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -4,6 +4,7 @@ from datetime import timedelta
|
|||
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import login as django_login
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
|
@ -47,6 +48,7 @@ from gestioncof.forms import (
|
|||
RegistrationPassUserForm,
|
||||
RegistrationProfileForm,
|
||||
RegistrationUserForm,
|
||||
SelfRegistrationProfileForm,
|
||||
SubscribForm,
|
||||
SurveyForm,
|
||||
SurveyStatusFilterForm,
|
||||
|
@ -695,9 +697,46 @@ def registration(request):
|
|||
return render(request, "registration.html")
|
||||
|
||||
|
||||
# TODO: without login
|
||||
@login_required
|
||||
def self_kf_registration(request):
|
||||
# we manage prefilling for authenticated user separatly
|
||||
if request.user.is_authenticated:
|
||||
return self_kf_registration_logged(request)
|
||||
|
||||
member = None
|
||||
|
||||
if request.POST:
|
||||
user_form = RegistrationPassUserForm(request.POST)
|
||||
profile_form = SelfRegistrationProfileForm(request.POST)
|
||||
agreement_form = SubscribForm(request.POST)
|
||||
if user_form.is_valid() and profile_form.is_valid():
|
||||
member = user_form.save()
|
||||
msg = "Création du compte GestioCOF {:s} réussie.".format(member.username)
|
||||
messages.success(request, msg)
|
||||
member.backend = "django.contrib.auth.backends.ModelBackend"
|
||||
django_login(request, member)
|
||||
|
||||
profile, _ = CofProfile.objects.get_or_create(user=member)
|
||||
profile_form = SelfRegistrationProfileForm(request.POST, instance=profile)
|
||||
profile_form.save()
|
||||
return self_kf_registration_logged(request)
|
||||
else:
|
||||
user_form = RegistrationPassUserForm()
|
||||
profile_form = SelfRegistrationProfileForm()
|
||||
agreement_form = SubscribForm()
|
||||
|
||||
return render(
|
||||
request,
|
||||
"gestioncof/self_registration.html",
|
||||
{
|
||||
"user_form": user_form,
|
||||
"profile_form": profile_form,
|
||||
"agreement_form": agreement_form,
|
||||
"member": member,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def self_kf_registration_logged(request):
|
||||
member = request.user
|
||||
(profile, _) = CofProfile.objects.get_or_create(user=member)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue