stages/email: add field to select E-Mail and subject

This commit is contained in:
Jens Langhammer 2020-05-15 14:50:23 +02:00
parent b907105f4a
commit 615cd7870d
9 changed files with 105 additions and 81 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: [BeryJu]

View File

@ -22,6 +22,9 @@ class EmailStageSerializer(ModelSerializer):
"use_ssl",
"timeout",
"from_address",
"token_expiry",
"subject",
"template",
]
extra_kwargs = {"password": {"write_only": True}}

View File

@ -27,6 +27,9 @@ class EmailStageForm(forms.ModelForm):
"use_ssl",
"timeout",
"from_address",
"token_expiry",
"subject",
"template",
]
widgets = {
"name": forms.TextInput(),

View File

@ -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",
),
),
]

View File

@ -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"

View File

@ -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}),

View File

@ -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 %}
<!-- HERO -->
<tr>
<td bgcolor="#3625b7" align="center" style="padding: 0px 10px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="480">
<tr>
<td bgcolor="#566572" align="center" valign="top"
style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #8F9BA3; font-family: 'Metropolis', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; letter-spacing: 4px; line-height: 48px;">
<h1 style="font-size: 32px; font-weight: 400; margin: 0; color: #E9ECEF;">{% trans 'Welcome!' %}
</h1>
</td>
</tr>
</table>
</td>
</tr>
<!-- COPY BLOCK -->
<tr>
<td bgcolor="#1b2a32" align="center" style="padding: 0px 10px 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="480">
<!-- COPY -->
<tr>
<td bgcolor="#566572" align="left"
style="padding: 20px 30px 40px 30px; color: #E9ECEF; font-family: 'Metropolis', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<p style="margin: 0;">
{% trans "We're excited to have you get started. First, you need to confirm your account. Just press the button below."%}
</p>
</td>
</tr>
<!-- BULLETPROOF BUTTON -->
<tr>
<td bgcolor="#566572" align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#566572" align="center" style="padding: 20px 30px 60px 30px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" style="border-radius: 3px;" bgcolor="#3625b7"><a
href="{{ url }}" target="_blank"
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3625b7; display: inline-block;">{% trans 'Confirm Account' %}</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- COPY -->
<tr>
<td bgcolor="#566572" align="left"
style="padding: 0px 30px 0px 30px; color: #E9ECEF; font-family: 'Metropolis', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<p style="margin: 0;">
{% trans "If that doesn't work, copy and paste the following link in your browser:" %}</p>
</td>
</tr>
<!-- COPY -->
<tr>
<td bgcolor="#566572" align="left"
style="padding: 20px 30px 20px 30px; color: #E9ECEF; font-family: 'Metropolis', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<p style="margin: 0;"><a href="{{ url }}" target="_blank" style="color: #3625b7;">{{ url }}</a></p>
</td>
</tr>
<!-- COPY -->
<tr>
<td bgcolor="#566572" align="left"
style="padding: 0px 30px 20px 30px; color: #E9ECEF; font-family: 'Metropolis', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;">
<p style="margin: 0;">
{% trans "If you have any questions, just reply to this email—we're always happy to help out." %}
</p>
</td>
</tr>
</table>
</td>
</tr>
<td>
<h2>
{% trans 'Welcome!' %}
</h2>
<p>
{% trans "We're excited to have you get started. First, you need to confirm your account. Just press the button below."%}
</p>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="btn btn-primary">
<tbody>
<tr>
<td align="center">
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td> <a href="{{ url }}" target="_blank">{% trans 'Confirm Account' %}</a> </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>
{% blocktrans with url=url %}
If that doesn't work, copy and paste the following link in your browser: {{ url }}
{% endblocktrans %}
</p>
<p>
{% trans "If you have any questions, just reply to this email—we're always happy to help out." %}
</p>
</td>
{% endblock %}

View File

@ -37,5 +37,4 @@
{% endblocktrans %}
</p>
</td>
{% endblock %}

View File

@ -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