Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Allow override of invite template #917

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/server/assets/email/_plainheader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ To: {{.ToEmail}}
From: {{.FromEmail}}
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
{{- end -}}
{{end}}
1 change: 0 additions & 1 deletion cmd/server/assets/email/default_email_verify.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- define "email/verifyemail" -}}
{{template "email/plainheader" .}}

Hello,

Click the link below to verify your email address for {{.RealmName}} on the COVID-19 exposure notifications verification server:
Expand Down
1 change: 0 additions & 1 deletion cmd/server/assets/email/default_invite.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- define "email/invite" -}}
{{template "email/plainheader" .}}

Welcome,

You have been invited to join the {{.RealmName}} COVID-19 exposure notifications verification server.
Expand Down
1 change: 0 additions & 1 deletion cmd/server/assets/email/default_reset_password.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- define "email/passwordresetemail" -}}
{{template "email/plainheader" .}}

Hello,

Click the link below to reset your password for the COVID-19 exposure notifications verification server.
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/assets/realmadmin/_form_codes.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
{{end}}
<small class="form-text text-muted">
The SMS message will be constructed based on the template you provide. The overall
length of of the SMS message should not exceede 160 characters, or your message will need to be split
length of of the SMS message should not exceed 160 characters, or your message will need to be split
in transit and may not be joined correctly. There are some special strings that you can use
to substitute items.
{{if $realm.EnableENExpress}}
Expand Down
39 changes: 37 additions & 2 deletions cmd/server/assets/realmadmin/_form_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{$emailConfig := .emailConfig}}

<p class="mb-4">
These are the settings for configuring an SMTP email provider. The verification server
These are the settings for configuring an SMTP email provider and email templates. The verification server
will use this email account to send invitations, password resets, and account-verifications
for the realm.
</p>
Expand Down Expand Up @@ -79,10 +79,45 @@
587 is the default port for SMTP, and legacy port 25 is blocked.
</small>
</div>

<div class="form-label-group">
<textarea name="email_invite_template" id="email-invite-template" class="form-control text-monospace{{if $realm.ErrorsFor "EmailInviteTemplate"}} is-invalid{{end}}"
rows="5" placeholder="Email invite template">{{$realm.EmailInviteTemplate}}</textarea>
<label for="email-invite-template">Email invitation template</label>
{{if $realm.ErrorsFor "EmailInviteTemplate"}}
<div class="invalid-feedback">
{{joinStrings ($realm.ErrorsFor "EmailInviteTemplate") ", "}}
</div>
{{end}}
<small class="form-text text-muted">
<p>
The invitation email message will be constructed based on the template you provide.
This can be helpful for introducing new users to the system or providing additional instructions.
There are some special strings that you can use to substitute items.

Your email invite template <em>MUST</em> contain <code>[invitelink]</code>.
</p>

<ul>
<li><code>[invitelink]</code> The link given to the user to accept the invitation.</li>
<li><code>[realname]</code> The name of the current realm. Currently <em>{{$realm.Name}}</em>.</li>
</ul>

Here is an example invitation template.
<p>
<samp class="text-dark">
Welcome,<br/>
You have been invited to the State of Wonder Dept. of Health COVID-19 exposure notification
server. You may use the following link to set your password and sign-in:<br/>
[invitelink]
</samp>
</p>
</small>
</div>
</div>

<div class="mt-4">
<input type="submit" class="btn btn-primary btn-block" value="Update SMTP settings" />
<input type="submit" class="btn btn-primary btn-block" value="Update email settings" />
</div>
</form>

Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func SendPasswordResetEmailFunc(ctx context.Context, db *database.Database, h *r

return func(ctx context.Context, resetLink string) error {
var message []byte
if realm.EmailInviteTemplate != "" {
if realm.EmailPasswordResetTemplate != "" {
// Render from the realm template with the plain header.
header, err := h.RenderEmail("email/plainheader", map[string]interface{}{
"ToEmail": email,
Expand Down Expand Up @@ -147,7 +147,7 @@ func SendEmailVerificationEmailFunc(ctx context.Context, db *database.Database,

return func(ctx context.Context, verifyLink string) error {
var message []byte
if realm.EmailInviteTemplate != "" {
if realm.EmailVerifyTemplate != "" {
// Render from the realm template with the plain header.
header, err := h.RenderEmail("email/plainheader", map[string]interface{}{
"ToEmail": email,
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/realmadmin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *Controller) HandleSettings() http.Handler {
SMTPPassword string `form:"smtp_password"`
SMTPHost string `form:"smtp_host"`
SMTPPort string `form:"smtp_port"`
EmailInviteTemplate string `form:"email_invite_template"`

Security bool `form:"security"`
MFAMode int16 `form:"mfa_mode"`
Expand Down Expand Up @@ -170,6 +171,7 @@ func (c *Controller) HandleSettings() http.Handler {
// Email
if form.Email {
realm.UseSystemEmailConfig = form.UseSystemEmailConfig
realm.EmailInviteTemplate = form.EmailInviteTemplate
}

// Security
Expand Down