8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Add option to enable the password field during account creation

This commit is contained in:
Jean-Romain Garnier 2020-04-16 17:16:33 +00:00 committed by Supelec Rezo Rennes
parent 653a059725
commit 8c827cc845
5 changed files with 64 additions and 41 deletions

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.28 on 2020-04-16 17:06
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0067_auto_20191120_0159'),
]
operations = [
migrations.AddField(
model_name='optionaluser',
name='allow_set_password_during_user_creation',
field=models.BooleanField(default=False, help_text='If True, users have the choice to receive an email containing a link to reset their password during creation, or to directly set their password in the page. If False, an email is always sent.'),
),
]

View file

@ -117,6 +117,15 @@ class OptionalUser(AclMixin, PreferencesModel):
" If False, only when a valid registration has been paid." " If False, only when a valid registration has been paid."
), ),
) )
allow_set_password_during_user_creation = models.BooleanField(
default=False,
help_text=_(
"If True, users have the choice to receive an email containing"
" a link to reset their password during creation, or to directly"
" set their password in the page."
" If False, an email is always sent."
),
)
allow_archived_connexion = models.BooleanField( allow_archived_connexion = models.BooleanField(
default=False, help_text=_("If True, archived users are allowed to connect.") default=False, help_text=_("If True, archived users are allowed to connect.")
) )

View file

@ -125,6 +125,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr> <tr>
<th>{% trans "All users are active by default" %}</th> <th>{% trans "All users are active by default" %}</th>
<td>{{ useroptions.all_users_active|tick }}</td> <td>{{ useroptions.all_users_active|tick }}</td>
<th>{% trans "Allow directly entering a password during account creation" %}</th>
<td>{{ useroptions.allow_set_password_during_user_creation|tick }}</td>
</tr>
<tr>
<th>{% trans "Allow archived users to log in" %}</th> <th>{% trans "Allow archived users to log in" %}</th>
<td>{{ useroptions.allow_archived_connexion|tick }}</td> <td>{{ useroptions.allow_archived_connexion|tick }}</td>
</tr> </tr>

View file

@ -382,6 +382,7 @@ class AdherentCreationForm(AdherentForm):
AdherentForm auquel on ajoute une checkbox afin d'éviter les AdherentForm auquel on ajoute une checkbox afin d'éviter les
doublons d'utilisateurs et, optionnellement, doublons d'utilisateurs et, optionnellement,
un champ mot de passe""" un champ mot de passe"""
if OptionalUser.get_cached_value("allow_set_password_during_user_creation"):
# Champ pour choisir si un lien est envoyé par mail pour le mot de passe # Champ pour choisir si un lien est envoyé par mail pour le mot de passe
init_password_by_mail = forms.BooleanField(required=False, initial=True) init_password_by_mail = forms.BooleanField(required=False, initial=True)
init_password_by_mail.label = _("Send password reset link by email.") init_password_by_mail.label = _("Send password reset link by email.")
@ -392,14 +393,14 @@ class AdherentCreationForm(AdherentForm):
required=False, required=False,
label=_("Password"), label=_("Password"),
widget=forms.PasswordInput, widget=forms.PasswordInput,
# validators=[MinLengthValidator(8)], #validators=[MinLengthValidator(8)],
max_length=255, max_length=255,
) )
password2 = forms.CharField( password2 = forms.CharField(
required=False, required=False,
label=_("Password confirmation"), label=_("Password confirmation"),
widget=forms.PasswordInput, widget=forms.PasswordInput,
# validators=[MinLengthValidator(8)], #validators=[MinLengthValidator(8)],
max_length=255, max_length=255,
) )
@ -476,7 +477,8 @@ class AdherentCreationForm(AdherentForm):
# Save the provided password in hashed format # Save the provided password in hashed format
user = super(AdherentForm, self).save(commit=False) user = super(AdherentForm, self).save(commit=False)
send_email = self.cleaned_data.get("init_password_by_mail") is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation")
send_email = not is_set_password_allowed or self.cleaned_data.get("init_password_by_mail")
if not send_email: if not send_email:
user.set_password(self.cleaned_data["password1"]) user.set_password(self.cleaned_data["password1"])

View file

@ -119,12 +119,13 @@ def new_user(request):
user = AdherentCreationForm(request.POST or None, user=request.user) user = AdherentCreationForm(request.POST or None, user=request.user)
GTU_sum_up = GeneralOption.get_cached_value("GTU_sum_up") GTU_sum_up = GeneralOption.get_cached_value("GTU_sum_up")
GTU = GeneralOption.get_cached_value("GTU") GTU = GeneralOption.get_cached_value("GTU")
is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation")
if user.is_valid(): if user.is_valid():
user = user.save() user = user.save()
# Use "is False" so that if None, the email is sent # Use "is False" so that if None, the email is sent
if user.should_send_password_reset_email is False: if is_set_password_allowed and user.should_send_password_reset_email is False:
messages.success( messages.success(
request, request,
_("The user %s was created.") _("The user %s was created.")
@ -150,23 +151,10 @@ def new_user(request):
"action_name": _("Commit"), "action_name": _("Commit"),
} }
if request.user.is_anonymous: if is_set_password_allowed:
params["load_js_file"] = "/static/js/toggle_password_fields.js" params["load_js_file"] = "/static/js/toggle_password_fields.js"
return form(params, "users/user.html", request) return form(params, "users/user.html", request)
"""
return form(
{
"userform": user,
"GTU_sum_up": GTU_sum_up,
"GTU": GTU,
"showCGU": True,
"action_name": _("Commit"),
},
"users/user.html",
request,
)
"""
@login_required @login_required