Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Fix incorrect form messages on public re-subscription to double opt-in lists. Closes #1638.

Kailash Nadhb2a5e37ccbf3
diff --git a/cmd/public.go b/cmd/public.go
index 019786ad..ff61637a 100644
--- a/cmd/public.go
+++ b/cmd/public.go
@@ -705,11 +705,12 @@ func processSubForm(c echo.Context) (bool, error) {
return false, err
}
- if _, err := app.core.UpdateSubscriberWithLists(sub.ID, sub, nil, listUUIDs, false, false); err != nil {
+ _, hasOptin, err := app.core.UpdateSubscriberWithLists(sub.ID, sub, nil, listUUIDs, false, false)
+ if err != nil {
return false, err
}
- return false, nil
+ return hasOptin, nil
}
return false, echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("%s", err.(*echo.HTTPError).Message))
diff --git a/cmd/subscribers.go b/cmd/subscribers.go
index 3cfd3851..57510aff 100644
--- a/cmd/subscribers.go
+++ b/cmd/subscribers.go
@@ -238,7 +238,7 @@ func handleUpdateSubscriber(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("subscribers.invalidName"))
}
- out, err := app.core.UpdateSubscriberWithLists(id, req.Subscriber, req.Lists, nil, req.PreconfirmSubs, true)
+ out, _, err := app.core.UpdateSubscriberWithLists(id, req.Subscriber, req.Lists, nil, req.PreconfirmSubs, true)
if err != nil {
return err
}
diff --git a/internal/core/subscribers.go b/internal/core/subscribers.go
index 66593545..b0a242ae 100644
--- a/internal/core/subscribers.go
+++ b/internal/core/subscribers.go
@@ -272,14 +272,12 @@ func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs
pq.Array(listUUIDs),
subStatus); err != nil {
if pqErr, ok := err.(*pq.Error); ok && pqErr.Constraint == "subscribers_email_key" {
- return models.Subscriber{}, false, echo.NewHTTPError(http.StatusConflict,
- c.i18n.T("subscribers.emailExists"))
+ return models.Subscriber{}, false, echo.NewHTTPError(http.StatusConflict, c.i18n.T("subscribers.emailExists"))
} else {
// return sub.Subscriber, errSubscriberExists
c.log.Printf("error inserting subscriber: %v", err)
return models.Subscriber{}, false, echo.NewHTTPError(http.StatusInternalServerError,
- c.i18n.Ts("globals.messages.errorCreating",
- "name", "{globals.terms.subscriber}", "error", pqErrMsg(err)))
+ c.i18n.Ts("globals.messages.errorCreating", "name", "{globals.terms.subscriber}", "error", pqErrMsg(err)))
}
}
@@ -337,7 +335,7 @@ func (c *Core) UpdateSubscriber(id int, sub models.Subscriber) (models.Subscribe
// UpdateSubscriberWithLists updates a subscriber's properties.
// If deleteLists is set to true, all existing subscriptions are deleted and only
// the ones provided are added or retained.
-func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, deleteLists bool) (models.Subscriber, error) {
+func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, deleteLists bool) (models.Subscriber, bool, error) {
subStatus := models.SubscriptionStatusUnconfirmed
if preconfirm {
subStatus = models.SubscriptionStatusConfirmed
@@ -347,7 +345,7 @@ func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs
attribs := []byte("{}")
if len(sub.Attribs) > 0 {
if b, err := json.Marshal(sub.Attribs); err != nil {
- return models.Subscriber{}, echo.NewHTTPError(http.StatusInternalServerError,
+ return models.Subscriber{}, false, echo.NewHTTPError(http.StatusInternalServerError,
c.i18n.Ts("globals.messages.errorUpdating",
"name", "{globals.terms.subscriber}", "error", err.Error()))
} else {
@@ -366,21 +364,23 @@ func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs
deleteLists)
if err != nil {
c.log.Printf("error updating subscriber: %v", err)
- return models.Subscriber{}, echo.NewHTTPError(http.StatusInternalServerError,
+ return models.Subscriber{}, false, echo.NewHTTPError(http.StatusInternalServerError,
c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.subscriber}", "error", pqErrMsg(err)))
}
out, err := c.GetSubscriber(sub.ID, "", sub.Email)
if err != nil {
- return models.Subscriber{}, err
+ return models.Subscriber{}, false, err
}
+ hasOptin := false
if !preconfirm && c.constants.SendOptinConfirmation {
// Send a confirmation e-mail (if there are any double opt-in lists).
- c.h.SendOptinConfirmation(out, listIDs)
+ num, _ := c.h.SendOptinConfirmation(out, listIDs)
+ hasOptin = num > 0
}
- return out, nil
+ return out, hasOptin, nil
}
// BlocklistSubscribers blocklists the given list of subscribers.