MCPcopy
hub / github.com/knadh/listmonk / SubscriptionPage

Method SubscriptionPage

cmd/public.go:197–248  ·  view source on GitHub ↗

SubscriptionPage renders the subscription management page and handles unsubscriptions. This is the view that {{ UnsubscribeURL }} in campaigns link to.

(c echo.Context)

Source from the content-addressed store, hash-verified

195// SubscriptionPage renders the subscription management page and handles unsubscriptions.
196// This is the view that {{ UnsubscribeURL }} in campaigns link to.
197func (a *App) SubscriptionPage(c echo.Context) error {
198 var (
199 subUUID = c.Param("subUUID")
200 showManage, _ = strconv.ParseBool(c.FormValue("manage"))
201 )
202
203 // Get the subscriber from the DB.
204 s, err := a.core.GetSubscriber(0, subUUID, "")
205 if err != nil {
206 return c.Render(http.StatusInternalServerError, tplMessage,
207 makeMsgTpl(a.i18n.T("public.errorTitle"), "", a.i18n.Ts("public.errorProcessingRequest")))
208 }
209
210 // Prepare the public template.
211 out := unsubTpl{
212 Subscriber: s,
213 SubUUID: subUUID,
214 publicTpl: publicTpl{Title: a.i18n.T("public.unsubscribeTitle")},
215 AllowBlocklist: a.cfg.Privacy.AllowBlocklist,
216 AllowExport: a.cfg.Privacy.AllowExport,
217 AllowWipe: a.cfg.Privacy.AllowWipe,
218 AllowPreferences: a.cfg.Privacy.AllowPreferences,
219 }
220
221 // If the subscriber is blocklisted, throw an error.
222 if s.Status == models.SubscriberStatusBlockListed {
223 return c.Render(http.StatusOK, tplMessage, makeMsgTpl(a.i18n.T("public.noSubTitle"), "", a.i18n.Ts("public.blocklisted")))
224 }
225
226 // Only show preference management if it's enabled in settings.
227 if a.cfg.Privacy.AllowPreferences {
228 out.ShowManage = showManage
229
230 // Get the subscriber's lists from the DB to render in the template.
231 subs, err := a.core.GetSubscriptions(0, subUUID, false)
232 if err != nil {
233 return echo.NewHTTPError(http.StatusBadRequest, a.i18n.T("public.errorFetchingLists"))
234 }
235
236 out.Subscriptions = make([]models.Subscription, 0, len(subs))
237 for _, s := range subs {
238 // Private lists shouldn't be rendered in the template.
239 if s.Type == models.ListTypePrivate {
240 continue
241 }
242
243 out.Subscriptions = append(out.Subscriptions, s)
244 }
245 }
246
247 return c.Render(http.StatusOK, "subscription", out)
248}
249
250// SubscriptionPrefs renders the subscription management page and
251// s unsubscriptions. This is the view that {{ UnsubscribeURL }} in

Callers

nothing calls this directly

Calls 6

makeMsgTplFunction · 0.85
TMethod · 0.80
TsMethod · 0.80
GetSubscriptionsMethod · 0.80
GetSubscriberMethod · 0.45
RenderMethod · 0.45

Tested by

no test coverage detected