MCPcopy Index your code
hub / github.com/writefreely/writefreely / handleDeleteEmailSubscription

Function handleDeleteEmailSubscription

email.go:218–289  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

216}
217
218func handleDeleteEmailSubscription(app *App, w http.ResponseWriter, r *http.Request) error {
219 alias := collectionAliasFromReq(r)
220
221 vars := mux.Vars(r)
222 subID := vars["subscriber"]
223 email := r.FormValue("email")
224 token := r.FormValue("t")
225 slug := r.FormValue("slug")
226 isWeb := r.Method == "GET"
227
228 // Display collection if this is a collection
229 var c *Collection
230 var err error
231 if app.cfg.App.SingleUser {
232 c, err = app.db.GetCollectionByID(1)
233 } else {
234 c, err = app.db.GetCollection(alias)
235 }
236 if err != nil {
237 log.Error("Get collection: %s", err)
238 return err
239 }
240
241 from := c.CanonicalURL()
242
243 if subID != "" {
244 // User unsubscribing via email, so assume action is taken by either current
245 // user or not current user, and only use the request's information to
246 // satisfy this unsubscribe, i.e. subscriberID and token.
247 err = app.db.DeleteEmailSubscriber(subID, token)
248 } else {
249 // User unsubscribing through the web app, so assume action is taken by
250 // currently-auth'd user.
251 var userID int64
252 u := getUserSession(app, r)
253 if u != nil {
254 // User is logged in
255 userID = u.ID
256 if userID == c.OwnerID {
257 from = "/" + c.Alias + "/"
258 }
259 }
260 if email == "" && userID <= 0 {
261 // Get email address from saved cookie
262 session, err := app.sessionStore.Get(r, userEmailCookieName)
263 if err != nil {
264 log.Error("Unable to get email cookie: %s", err)
265 } else {
266 email = session.Values[userEmailCookieVal].(string)
267 }
268 }
269
270 if email == "" && userID <= 0 {
271 err = fmt.Errorf("No subscriber given.")
272 log.Error("Not deleting subscription: %s", err)
273 return err
274 }
275

Callers

nothing calls this directly

Calls 8

CanonicalURLMethod · 0.95
collectionAliasFromReqFunction · 0.85
getUserSessionFunction · 0.85
addSessionFlashFunction · 0.85
DeleteEmailSubscriberMethod · 0.80
GetCollectionByIDMethod · 0.65
GetCollectionMethod · 0.65

Tested by

no test coverage detected