diff --git a/rmo/email.go b/rmo/email.go index df3db1cd..0a9422f2 100644 --- a/rmo/email.go +++ b/rmo/email.go @@ -7,6 +7,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/html" + "github.com/aarondl/opt/omit" "github.com/go-chi/chi/v5" ) @@ -42,6 +43,19 @@ func getEmailByCode(w http.ResponseWriter, r *http.Request) { } func getEmailSubscribe(w http.ResponseWriter, r *http.Request) { email := r.FormValue("email") + if email == "" { + respondError(w, "Not sure what to do with an empty email", nil, http.StatusBadRequest) + return + } + ctx := r.Context() + email_contact, err := models.FindCommsEmailContact(ctx, db.PGInstance.BobDB, email) + if err != nil { + respondError(w, "Email not in the database", err, http.StatusNotFound) + return + } + err = email_contact.Update(ctx, db.PGInstance.BobDB, &models.CommsEmailContactSetter{ + Confirmed: omit.From(true), + }) html.RenderOrError( w, EmailSubscribeT, diff --git a/rmo/template/email-subscribe.html b/rmo/template/email-subscribe.html index fa7469a7..d88a5b08 100644 --- a/rmo/template/email-subscribe.html +++ b/rmo/template/email-subscribe.html @@ -15,6 +15,8 @@
You've allowed emails from Report Mosquitoes Online to {{.Email}}.
+Go ahead and close this page/tab/window whenever you're ready...
+...or maybe check out the site