Add endpoint for unsubscribing email addresses
This commit is contained in:
parent
b2737b4968
commit
3bed78f742
4 changed files with 67 additions and 13 deletions
|
|
@ -39,8 +39,8 @@ func maybeSendInitialEmail(ctx context.Context, destination string) error {
|
|||
func urlEmailInBrowser(public_id string) string {
|
||||
return config.MakeURLReport("/email/render/%s", public_id)
|
||||
}
|
||||
func urlUnsubscribe(address string) string {
|
||||
return config.MakeURLReport("/email/unsubscribe?email=%s")
|
||||
func urlUnsubscribe(email string) string {
|
||||
return config.MakeURLReport("/email/unsubscribe?email=%s", email)
|
||||
}
|
||||
func sendEmailInitialContact(ctx context.Context, destination string) error {
|
||||
//data := pgtypes.HStore{}
|
||||
|
|
|
|||
24
rmo/email.go
24
rmo/email.go
|
|
@ -16,9 +16,10 @@ type ContentEmail struct {
|
|||
}
|
||||
|
||||
var (
|
||||
EmailConfirmT = buildTemplate("email-confirm", "base")
|
||||
EmailConfirmCompleteT = buildTemplate("email-confirm-complete", "base")
|
||||
EmailUnsubscribeT = buildTemplate("email-unsubscribe", "base")
|
||||
EmailConfirmT = buildTemplate("email-confirm", "base")
|
||||
EmailConfirmCompleteT = buildTemplate("email-confirm-complete", "base")
|
||||
EmailUnsubscribeT = buildTemplate("email-unsubscribe", "base")
|
||||
EmailUnsubscribeCompleteT = buildTemplate("email-unsubscribe-complete", "base")
|
||||
)
|
||||
|
||||
func getEmailByCode(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -85,6 +86,13 @@ func getEmailUnsubscribe(w http.ResponseWriter, r *http.Request) {
|
|||
},
|
||||
)
|
||||
}
|
||||
func getEmailUnsubscribeComplete(w http.ResponseWriter, r *http.Request) {
|
||||
html.RenderOrError(
|
||||
w,
|
||||
EmailUnsubscribeCompleteT,
|
||||
map[string]string{},
|
||||
)
|
||||
}
|
||||
func postEmailConfirm(w http.ResponseWriter, r *http.Request) {
|
||||
email := r.PostFormValue("email")
|
||||
if email == "" {
|
||||
|
|
@ -115,13 +123,7 @@ func postEmailUnsubscribe(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
err = email_contact.Update(ctx, db.PGInstance.BobDB, &models.CommsEmailContactSetter{
|
||||
Confirmed: omit.From(true),
|
||||
IsSubscribed: omit.From(false),
|
||||
})
|
||||
html.RenderOrError(
|
||||
w,
|
||||
EmailConfirmCompleteT,
|
||||
ContentEmail{
|
||||
Email: email,
|
||||
},
|
||||
)
|
||||
http.Redirect(w, r, "/email/unsubscribe/complete", http.StatusFound)
|
||||
}
|
||||
|
|
|
|||
23
rmo/template/email-unsubscribe-complete.html
Normal file
23
rmo/template/email-unsubscribe-complete.html
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{{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>Unsubscribed!</h1>
|
||||
<p>You will not receive any further emails from Report Mosquitoes Online.</p>
|
||||
<p>If this was an accident, or you changed your mind, you can <a href="/email/confirm">re-subscribe</a></p>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
{{end}}
|
||||
29
rmo/template/email-unsubscribe.html
Normal file
29
rmo/template/email-unsubscribe.html
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{{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">
|
||||
<form action="/email/unsubscribe" method="POST">
|
||||
<div class="form-section">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" name="email" placeholder="you@domain.com" value="{{.Email}}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-warning btn-lg">
|
||||
Unsubscribe from all communications
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
{{end}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue