Skip to content

Commit

Permalink
registration: add email notification capability
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpau committed Feb 2, 2022
1 parent 7d5c0a2 commit 04e9f0b
Show file tree
Hide file tree
Showing 18 changed files with 680 additions and 58 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ coverage:

templates:
@./assets/scripts/generate_ui.sh
@./assets/scripts/generate_email_templates.sh

docs:
@mkdir -p .doc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<body>
<p>
Please confirm your registration by clicking this
<a href="{{ .registration_url }}/ack/{{ .registration_id }}">link</a>
and providing the registration code <b><code>{{ .registration_code }}</code></b>
within the next 45 minutes. If you haven't done so, please re-register.
</p>

<p>The registation metadata follows:</p>
<ul style="list-style-type: disc">
<li>Session ID: {{ .session_id }}</li>
<li>Request ID: {{ .request_id }}</li>
<li>Username: <code>{{ .username }}</code></li>
<li>Email: <code>{{ .email }}</code></li>
<li>IP Address: <code>{{ .src_ip }}</code></li>
<li>Timestamp: {{ .timestamp }}</li>
</ul>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Registration Confirmation Required
53 changes: 44 additions & 9 deletions assets/portal/templates/basic/register.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
{{ if eq .Data.view "register" }}
<form action="{{ pathjoin .ActionEndpoint "/register" }}" method="POST">
{{ end }}
{{ if eq .Data.view "ack" }}
<form action="{{ pathjoin .ActionEndpoint "/register/ack" .Data.registration_id }}" method="POST">
{{ end }}
<div class="card card-large app-card">
<div class="card-content">
<span class="card-title center-align">
Expand All @@ -38,41 +41,46 @@
</span>
{{ if eq .Data.view "register" }}
<div class="input-field">
<input id="registrant" name="username" type="text" class="validate"
<input id="registrant" name="registrant" type="text" class="validate"
pattern="{{ .Data.username_validate_pattern }}"
title="{{ .Data.username_validate_title }}"
autocorrect="off" autocapitalize="off" spellcheck="false"
autocomplete="off"
required />
<label for="registrant">Username</label>
</div>
<div class="input-field">
<input id="registrant_email" name="email" type="email" class="validate"
<input id="registrant_email" name="registrant_email" type="email" class="validate"
autocorrect="off" autocapitalize="off" spellcheck="false"
autocomplete="off"
required />
<label for="registrant_email">Email Address</label>
</div>
<div class="input-field">
<input id="password" name="password" type="password" class="validate"
<input id="registrant_password" name="registrant_password" type="password" class="validate"
pattern="{{ .Data.password_validate_pattern }}"
title="{{ .Data.password_validate_title }}"
autocorrect="off" autocapitalize="off" spellcheck="false"
autocomplete="off"
required />
<label for="password">Password</label>
<label for="registrant_password">Password</label>
</div>
<div class="input-field">
<input id="password_confirm" name="password_confirm" type="password" class="validate"
<input id="registrant_password_confirm" name="registrant_password_confirm" type="password" class="validate"
pattern="{{ .Data.password_validate_pattern }}"
title="{{ .Data.password_validate_title }}"
autocorrect="off" autocapitalize="off" spellcheck="false"
autocomplete="off"
required />
<label for="password_confirm">Confirm Password</label>
<label for="registrant_password_confirm">Confirm Password</label>
</div>
{{ if .Data.require_registration_code }}
<div class="input-field">
<input id="code" name="code" type="text" class="validate"
<input id="registrant_code" name="registrant_code" type="text" class="validate"
autocorrect="off" autocapitalize="off" spellcheck="false"
autocomplete="off"
required />
<label for="code">Registration Code</label>
<label for="registrant_code">Registration Code</label>
</div>
{{ end }}
{{ if .Data.require_accept_terms }}
Expand All @@ -98,6 +106,16 @@
{{ end }}

{{ if eq .Data.view "ack" }}
<div class="input-field">
<input id="registration_code" name="registration_code" type="password" class="validate"
autocorrect="off" autocapitalize="off" spellcheck="false"
autocomplete="off"
required />
<label for="registration_code">Registration Code</label>
</div>
{{ end }}

{{ if eq .Data.view "ackfail" }}
<p>Unfortunately, things did not go as expected. {{ .Data.message }}.</p>
{{ end }}

Expand All @@ -111,6 +129,11 @@
</div>
<div class="card-action right-align">
{{ if eq .Data.view "register" }}
<button type="reset" name="reset" class="btn waves-effect waves-light navbtn active navbtn-last red lighten-1 app-btn">
<i class="las la-redo-alt app-btn-icon"></i>
<span class="app-btn-text">Clear</span>
</button>

<a href="{{ .ActionEndpoint }}" class="navbtn-last">
<button type="button" class="waves-effect waves-light btn navbtn active navbtn-last app-btn">
<i class="las la-undo left app-btn-icon"></i>
Expand All @@ -122,6 +145,7 @@
<span class="app-btn-text">Submit</span>
</button>
{{ end }}

{{ if ne .Data.view "register" }}
<a href="{{ .ActionEndpoint }}" class="navbtn-last">
<button type="button" class="waves-effect waves-light btn navbtn active navbtn-last app-btn">
Expand All @@ -130,9 +154,20 @@
</button>
</a>
{{ end }}

{{ if eq .Data.view "ack" }}
<button type="reset" name="reset" class="btn waves-effect waves-light navbtn active navbtn-last red lighten-1 app-btn">
<i class="las la-redo-alt app-btn-icon"></i>
<span class="app-btn-text">Clear</span>
</button>
<button type="submit" name="submit" class="waves-effect waves-light btn navbtn active navbtn-last app-btn">
<i class="las la-chevron-circle-right app-btn-icon"></i>
<span class="app-btn-text">Submit</span>
</button>
{{ end }}
</div>
</div>
{{ if eq .Data.view "register" }}
{{ if or (eq .Data.view "register") (eq .Data.view "ack") }}
</form>
{{ end }}
</div>
Expand Down
51 changes: 51 additions & 0 deletions assets/scripts/generate_email_templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -e

printf "Generating default email messaging templates\n"

TMPL_BODY_FILE=pkg/messaging/email_template_body.go
TMPL_SUBJ_FILE=pkg/messaging/email_template_subject.go

declare -a _LANG
declare -a _TEMPLATES
declare -a _NAMES
_LANG[${#_LANG[@]}]="en"
_TEMPLATES[${#_TEMPLATES[@]}]="registration_confirmation"

printf "package messaging\n\n" > ${TMPL_BODY_FILE}
printf "// EmailTemplateBody stores email body templates.\n" >> ${TMPL_BODY_FILE}
printf "var EmailTemplateBody = map[string]string{\n" >> ${TMPL_BODY_FILE}

printf "package messaging\n\n" > ${TMPL_SUBJ_FILE}
printf "// EmailTemplateSubject stores email subject templates.\n" >> ${TMPL_SUBJ_FILE}
printf "var EmailTemplateSubject = map[string]string{\n" >> ${TMPL_SUBJ_FILE}

for LANG_ID in "${!_LANG[@]}"; do
LANG_NAME=${_LANG[$LANG_ID]};
echo "Generating theme ${LANG_NAME}";
for TMPL_ID in "${!_TEMPLATES[@]}"; do
TMPL_NAME=${_TEMPLATES[$TMPL_ID]};
echo "At template ${TMPL_NAME}";

# Email body
printf "\"${LANG_NAME}/${TMPL_NAME}\": \`" >> ${TMPL_BODY_FILE}
cat assets/portal/messaging/templates/email/${LANG_NAME}/${TMPL_NAME}_body.template >> ${TMPL_BODY_FILE}
truncate -s -1 ${TMPL_BODY_FILE}
printf "\`,\n" >> ${TMPL_BODY_FILE}

# Email subject.
printf "\"${LANG_NAME}/${TMPL_NAME}\": \`" >> ${TMPL_SUBJ_FILE}
cat assets/portal/messaging/templates/email/${LANG_NAME}/${TMPL_NAME}_subject.template >> ${TMPL_SUBJ_FILE}
truncate -s -1 ${TMPL_SUBJ_FILE}
printf "\`,\n" >> ${TMPL_SUBJ_FILE}

done
done

printf "}\n" >> ${TMPL_BODY_FILE}
go fmt ${TMPL_BODY_FILE}
versioned -addlicense -copyright="Paul Greenberg [email protected]" -year=2022 -filepath=${TMPL_BODY_FILE}

printf "}\n" >> ${TMPL_SUBJ_FILE}
go fmt ${TMPL_SUBJ_FILE}
versioned -addlicense -copyright="Paul Greenberg [email protected]" -year=2022 -filepath=${TMPL_SUBJ_FILE}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.16

require (
github.com/crewjam/saml v0.4.6
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac
github.com/emersion/go-smtp v0.15.0
github.com/go-ldap/ldap/v3 v3.4.1
github.com/golang-jwt/jwt/v4 v4.2.0
github.com/google/go-cmp v0.5.7
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac h1:tn/OQ2PmwQ0XFVgAHfjlLyqMewry25Rz7jWnVoh4Ggs=
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-smtp v0.15.0 h1:3+hMGMGrqP/lqd7qoxZc1hTU8LY8gHV9RFGWlqSDmP8=
github.com/emersion/go-smtp v0.15.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
github.com/go-asn1-ber/asn1-ber v1.5.1 h1:pDbRAunXzIUXfx4CB2QJFv5IuPiuoW+sWvr/Us009o8=
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-ldap/ldap/v3 v3.4.1 h1:fU/0xli6HY02ocbMuozHAYsaHLcnkLjvho2r5a34BUU=
Expand Down
Loading

0 comments on commit 04e9f0b

Please sign in to comment.