accounts_accept_terms: Check if imported user wants marketing emails.

This commit is contained in:
Aman Agrawal 2024-09-11 09:00:22 +00:00 committed by Tim Abbott
parent d18959b1b6
commit cbb73bc82f
3 changed files with 23 additions and 0 deletions

View File

@ -59,6 +59,16 @@ the registration flow has its own (nearly identical) copy of the fields below in
{% endfor %}
{% endif %}
</div>
{% if first_time_terms_of_service_message_template %}
<div class="input-group">
<label for="id_enable_marketing_emails_first_login" class="inline-block checkbox marketing_emails_checkbox">
<input id="id_enable_marketing_emails_first_login" type="checkbox" name="enable_marketing_emails"
checked="checked" />
<span class="rendered-checkbox"></span>
{% trans %}Subscribe me to Zulip's low-traffic newsletter (a few emails a year).{% endtrans %}
</label>
</div>
{% endif %}
{% endif %}
<div class="controls">
<button id="accept_tos_button" type="submit">{{ _('Continue') }}</button>

View File

@ -234,6 +234,7 @@ class RegistrationForm(RealmDetailsForm):
class ToSForm(forms.Form):
terms = forms.BooleanField(required=False)
enable_marketing_emails = forms.BooleanField(required=False)
email_address_visibility = forms.TypedChoiceField(
required=False,
coerce=int,

View File

@ -57,6 +57,18 @@ def accounts_accept_terms(request: HttpRequest) -> HttpResponse:
email_address_visibility,
acting_user=request.user,
)
enable_marketing_emails = form.cleaned_data["enable_marketing_emails"]
if (
enable_marketing_emails is not None
and enable_marketing_emails != request.user.enable_marketing_emails
):
do_change_user_setting(
request.user,
"enable_marketing_emails",
enable_marketing_emails,
acting_user=request.user,
)
return redirect(home)
else:
form = ToSForm()