From 615cd7870da63d68f1f170058f55c8d30cf3526b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 15 May 2020 14:50:23 +0200 Subject: [PATCH] stages/email: add field to select E-Mail and subject --- .github/FUNDING.yml | 1 + passbook/stages/email/api.py | 3 + passbook/stages/email/forms.py | 3 + .../migrations/0003_auto_20200515_1242.py | 32 ++++++ passbook/stages/email/models.py | 20 +++- passbook/stages/email/stage.py | 2 +- .../email/for_email/account_confirm.html | 108 +++++------------- .../email/for_email/password_reset.html | 1 - swagger.yaml | 16 +++ 9 files changed, 105 insertions(+), 81 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 passbook/stages/email/migrations/0003_auto_20200515_1242.py diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..178ae1513 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [BeryJu] diff --git a/passbook/stages/email/api.py b/passbook/stages/email/api.py index 063a1020e..22dc15ca9 100644 --- a/passbook/stages/email/api.py +++ b/passbook/stages/email/api.py @@ -22,6 +22,9 @@ class EmailStageSerializer(ModelSerializer): "use_ssl", "timeout", "from_address", + "token_expiry", + "subject", + "template", ] extra_kwargs = {"password": {"write_only": True}} diff --git a/passbook/stages/email/forms.py b/passbook/stages/email/forms.py index bdd865fb1..e158743e1 100644 --- a/passbook/stages/email/forms.py +++ b/passbook/stages/email/forms.py @@ -27,6 +27,9 @@ class EmailStageForm(forms.ModelForm): "use_ssl", "timeout", "from_address", + "token_expiry", + "subject", + "template", ] widgets = { "name": forms.TextInput(), diff --git a/passbook/stages/email/migrations/0003_auto_20200515_1242.py b/passbook/stages/email/migrations/0003_auto_20200515_1242.py new file mode 100644 index 000000000..aef2c65d9 --- /dev/null +++ b/passbook/stages/email/migrations/0003_auto_20200515_1242.py @@ -0,0 +1,32 @@ +# Generated by Django 3.0.5 on 2020-05-15 12:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_stages_email", "0002_auto_20200510_1844"), + ] + + operations = [ + migrations.AddField( + model_name="emailstage", + name="subject", + field=models.TextField(default="passbook"), + ), + migrations.AddField( + model_name="emailstage", + name="template", + field=models.TextField( + choices=[ + ("stages/email/for_email/password_reset.html", "Password Reset"), + ( + "stages/email/for_email/account_confirmation.html", + "Account Confirmation", + ), + ], + default="stages/email/for_email/password_reset.html", + ), + ), + ] diff --git a/passbook/stages/email/models.py b/passbook/stages/email/models.py index c5ec2e9e5..4eef283df 100644 --- a/passbook/stages/email/models.py +++ b/passbook/stages/email/models.py @@ -7,6 +7,19 @@ from django.utils.translation import gettext as _ from passbook.flows.models import Stage +class EmailTemplates(models.TextChoices): + """Templates used for rendering the E-Mail""" + + PASSWORD_RESET = ( + "stages/email/for_email/password_reset.html", + _("Password Reset"), + ) # nosec + ACCOUNT_CONFIRM = ( + "stages/email/for_email/account_confirmation.html", + _("Account Confirmation"), + ) + + class EmailStage(Stage): """email stage""" @@ -17,12 +30,15 @@ class EmailStage(Stage): use_tls = models.BooleanField(default=False) use_ssl = models.BooleanField(default=False) timeout = models.IntegerField(default=10) + from_address = models.EmailField(default="system@passbook.local") token_expiry = models.IntegerField( default=30, help_text=_("Time in minutes the token sent is valid.") ) - - from_address = models.EmailField(default="system@passbook.local") + subject = models.TextField(default="passbook") + template = models.TextField( + choices=EmailTemplates.choices, default=EmailTemplates.PASSWORD_RESET + ) type = "passbook.stages.email.stage.EmailStageView" form = "passbook.stages.email.forms.EmailStageForm" diff --git a/passbook/stages/email/stage.py b/passbook/stages/email/stage.py index 0bb49e5b3..a1271ab18 100644 --- a/passbook/stages/email/stage.py +++ b/passbook/stages/email/stage.py @@ -54,7 +54,7 @@ class EmailStageView(FormView, AuthenticationStage): # Send mail to user message = TemplateEmailMessage( subject=_("passbook - Password Recovery"), - template_name="stages/email/for_email/password_reset.html", + template_name=self.executor.current_stage.template, to=[pending_user.email], template_context={ "url": self.get_full_url(**{QS_KEY_TOKEN: nonce.pk.hex}), diff --git a/passbook/stages/email/templates/stages/email/for_email/account_confirm.html b/passbook/stages/email/templates/stages/email/for_email/account_confirm.html index 5a4488162..f300b6585 100644 --- a/passbook/stages/email/templates/stages/email/for_email/account_confirm.html +++ b/passbook/stages/email/templates/stages/email/for_email/account_confirm.html @@ -3,82 +3,36 @@ {% load inline %} {% load i18n %} -{% block pre_header %} -{% trans "We're thrilled to have you here! Get ready to dive into your new account." %} -{% endblock %} - {% block content %} - - - - - - - -
-

{% trans 'Welcome!' %} -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
-

- {% trans "We're excited to have you get started. First, you need to confirm your account. Just press the button below."%} -

-
- - - - -
- - - - -
{% trans 'Confirm Account' %} -
-
-
-

- {% trans "If that doesn't work, copy and paste the following link in your browser:" %}

-
-

{{ url }}

-
-

- {% trans "If you have any questions, just reply to this email—we're always happy to help out." %} -

-
- - + +

+ {% trans 'Welcome!' %} +

+

+ {% trans "We're excited to have you get started. First, you need to confirm your account. Just press the button below."%} +

+ + + + + + + +

+ {% blocktrans with url=url %} + If that doesn't work, copy and paste the following link in your browser: {{ url }} + {% endblocktrans %} +

+

+ {% trans "If you have any questions, just reply to this email—we're always happy to help out." %} +

+ {% endblock %} diff --git a/passbook/stages/email/templates/stages/email/for_email/password_reset.html b/passbook/stages/email/templates/stages/email/for_email/password_reset.html index 6632a36fd..d43467958 100644 --- a/passbook/stages/email/templates/stages/email/for_email/password_reset.html +++ b/passbook/stages/email/templates/stages/email/for_email/password_reset.html @@ -37,5 +37,4 @@ {% endblocktrans %}

- {% endblock %} diff --git a/swagger.yaml b/swagger.yaml index df6c6f150..4a9b3057e 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -5903,6 +5903,22 @@ definitions: format: email maxLength: 254 minLength: 1 + token_expiry: + title: Token expiry + description: Time in minutes the token sent is valid. + type: integer + maximum: 2147483647 + minimum: -2147483648 + subject: + title: Subject + type: string + minLength: 1 + template: + title: Template + type: string + enum: + - stages/email/for_email/password_reset.html + - stages/email/for_email/account_confirmation.html IdentificationStage: required: - name