From 8e8d03543945dd8666589de7f3543d158fbb1947 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 20:53:10 +0200 Subject: [PATCH] Save before checking if confirmation email should be sent --- users/views.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/users/views.py b/users/views.py index 06f65dce..4b539b9d 100644 --- a/users/views.py +++ b/users/views.py @@ -124,6 +124,8 @@ def new_user(request): is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation") if user.is_valid(): + user = user.save() + if user.did_set_initial_passwd: user.send_confirm_email_if_necessary(request) messages.success( @@ -139,7 +141,6 @@ def new_user(request): % user.pseudo, ) - user = user.save() return redirect(reverse("users:profil", kwargs={"userid": str(user.id)})) # Anonymous users are allowed to create new accounts @@ -221,12 +222,12 @@ def edit_info(request, user, userid): ) if user_form.is_valid(): if user_form.changed_data: - if user.send_confirm_email_if_necessary(request): - messages.success(request, _("Sent a new confirmation email.")) - user = user_form.save() messages.success(request, _("The user was edited.")) + if user.send_confirm_email_if_necessary(request): + messages.success(request, _("Sent a new confirmation email.")) + return redirect(reverse("users:profil", kwargs={"userid": str(userid)})) return form( {"userform": user_form, "action_name": _("Edit")}, @@ -541,12 +542,12 @@ def edit_email_settings(request, user_instance, **_kwargs): ) if email_settings.is_valid(): if email_settings.changed_data: - if user_instance.send_confirm_email_if_necessary(request): - messages.success(request, _("An email to confirm your address was sent.")) - email_settings.save() messages.success(request, _("The email settings were edited.")) + if user_instance.send_confirm_email_if_necessary(request): + messages.success(request, _("An email to confirm your address was sent.")) + return redirect( reverse("users:profil", kwargs={"userid": str(user_instance.id)}) )