Show a page for subscribing to emails.

This commit is contained in:
Eli Ribble 2026-02-02 19:54:32 +00:00
parent 9d7ca81508
commit 4f56915f15
No known key found for this signature in database
6 changed files with 60 additions and 13 deletions

View file

@ -36,17 +36,20 @@ func maybeSendInitialEmail(ctx context.Context, destination string) error {
return sendEmailInitialContact(ctx, destination)
}
func urlEmailInBrowser(public_id string) string {
return config.MakeURLReport("/email/render/%s", public_id)
}
func sendEmailInitialContact(ctx context.Context, destination string) error {
//data := pgtypes.HStore{}
data := make(map[string]string, 0)
source := config.ForwardEmailReportAddress
data["destination"] = destination
data["source"] = source
data["url_logo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png")
data["url_subscribe"] = config.MakeURLReport("/email/subscribe?email=%s", destination)
data["url_unsubscribe"] = config.MakeURLReport("/email/unsubscribe")
public_id := generatePublicId(enums.CommsMessagetypeemailInitialContact, data)
data["url_browser"] = config.MakeURLReport("/email/%s", public_id)
source := config.ForwardEmailReportAddress
data["Destination"] = destination
data["Source"] = source
data["URLBrowser"] = urlEmailInBrowser(public_id)
data["URLLogo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png")
data["URLSubscribe"] = config.MakeURLReport("/email/subscribe?email=%s", destination)
data["URLUnsubscribe"] = config.MakeURLReport("/email/unsubscribe")
text, html, err := renderEmailTemplates(templateInitialID, data)
if err != nil {

View file

@ -55,7 +55,7 @@ func sendEmailReportConfirmation(ctx context.Context, job Job) error {
data["URLLogo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png")
data["URLReportStatus"] = config.MakeURLReport("/foo")
data["URLReportUnsubscribe"] = config.MakeURLReport("/email/unsubscribe")
data["URLViewInBrowser"] = config.MakeURLReport("/email/%s", public_id)
data["URLViewInBrowser"] = urlEmailInBrowser(public_id)
text, html, err := renderEmailTemplates(templateReportNotificationConfirmationID, data)
if err != nil {
return fmt.Errorf("Failed to render email report notification template: %w", err)

View file

@ -64,32 +64,34 @@
</head>
<body>
<div class="container">
{{if .IsBrowser}}
<div class="view-browser">
Email not displaying correctly? <a href="{{.url_browser}}">View it in your browser</a>
</div>
{{end}}
<div class="header">
<!-- Logo Placeholder -->
<img src="{{.url_logo}}" alt="Report Mosquitoes Online Logo" class="logo"></img>
<img src="{{.URLLogo}}" alt="Report Mosquitoes Online Logo" class="logo"></img>
</div>
<div class="content">
<h1>Welcome</h1>
<p>We're sending you this email because it's the first time we've gotten this email address ({{.destination}}).</p>
<p>We're sending you this email because it's the first time we've gotten this email address ({{.Destination}}).</p>
<p>If you'd rather not receive emails from us you can reply with "Unsubscribe" in the subject or body of the email. You can also use the "Unsubscribe" feature of your mail client, if it supports list unsubscribes.</p>
<p>If instead you'd like to confirm that you're willing to receive emails at this address, you can do so by clicking below:</p>
<div style="text-align: center;">
<a href="{{.url_subscribe}}" class="button">I want emails from Report Mosquitoes Online</a>
<a href="{{.URLSubscribe}}" class="button">I want emails from Report Mosquitoes Online</a>
</div>
</div>
<div class="footer">
<p>This email was sent to you because you or someone else gave your email address to Report Mosquitoes Online.</p>
<p>If you no longer wish to receive these updates, <a href="{{.url_unsubscribe}}">click here to unsubscribe</a>.</p>
<p>If you no longer wish to receive these updates, <a href="{{.URLUnsubscribe}}">click here to unsubscribe</a>.</p>
<p>&copy; 2026 Gleipnir LLC. All rights reserved.</p>
</div>
</div>

View file

@ -6,9 +6,18 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/comms/email"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/html"
"github.com/go-chi/chi/v5"
)
type ContentEmailSubscribe struct {
Email string
}
var (
EmailSubscribeT = buildTemplate("email-subscribe", "base")
)
func getEmailByCode(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "code")
//id := r.FormValue("id")
@ -31,3 +40,13 @@ func getEmailByCode(w http.ResponseWriter, r *http.Request) {
}
w.Write(html)
}
func getEmailSubscribe(w http.ResponseWriter, r *http.Request) {
email := r.FormValue("email")
html.RenderOrError(
w,
EmailSubscribeT,
ContentEmailSubscribe{
Email: email,
},
)
}

View file

@ -24,7 +24,8 @@ func Router() chi.Router {
r.Get("/privacy", getPrivacy)
r.Get("/robots.txt", getRobots)
r.Get("/email/{code}", getEmailByCode)
r.Get("/email/render/{code}", getEmailByCode)
r.Get("/email/subscribe", getEmailSubscribe)
r.Get("/image/{uuid}", getImageByUUID)
r.Route("/mock", addMockRoutes)
r.Get("/pool-submit-complete", getPoolSubmitComplete)

View file

@ -0,0 +1,22 @@
{{template "base.html" .}}
{{define "title"}}Main{{end}}
{{define "extraheader"}}
{{end}}
{{define "content"}}
<!-- Main Content -->
<main>
<section class="py-2 bg-primary text-white">
<div class="banner-container d-flex justify-content-center">
<img class="banner" src="/static/img/rmo/banner.jpg"/>
</div>
</section>
<section class="py-3 row text-center">
<div class="container">
<h1>Thanks!</h1>
<p>You've allowed emails from Report Mosquitoes Online to {{.Email}}.</p>
</div>
</section>
</main>
{{end}}