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

Make AdherentCreationForm code clearer

This commit is contained in:
Jean-Romain Garnier 2020-04-17 20:41:02 +02:00 committed by Gabriel Detraz
parent 9fe4313540
commit 8b75900103
2 changed files with 4 additions and 5 deletions

View file

@ -502,11 +502,11 @@ class AdherentCreationForm(AdherentForm):
user = super(AdherentForm, self).save(commit=False) user = super(AdherentForm, self).save(commit=False)
is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation") 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") set_passwd = is_set_password_allowed and not self.cleaned_data.get("init_password_by_mail")
if not send_email: if set_passwd:
user.set_password(self.cleaned_data["password1"]) user.set_password(self.cleaned_data["password1"])
user.should_send_password_reset_email = send_email user.did_set_initial_passwd = set_passwd
user.save() user.save()
return user return user

View file

@ -124,8 +124,7 @@ def new_user(request):
is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation") is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation")
if user.is_valid(): if user.is_valid():
# Use "is False" so that if None, the email is sent if user.did_set_initial_passwd:
if is_set_password_allowed and user.should_send_password_reset_email:
user.send_confirm_email_if_necessary(request) user.send_confirm_email_if_necessary(request)
messages.success( messages.success(
request, request,