2020-01-22 12:16:53 +03:00
|
|
|
defmodule PlausibleWeb.UnsubscribeController do
|
|
|
|
use PlausibleWeb, :controller
|
|
|
|
use Plausible.Repo
|
|
|
|
alias Plausible.Site.{WeeklyReport, MonthlyReport}
|
|
|
|
|
|
|
|
def weekly_report(conn, %{"website" => website, "email" => email}) do
|
|
|
|
site = Repo.get_by(Plausible.Site, domain: website)
|
2021-05-03 16:56:46 +03:00
|
|
|
weekly_report = site && Repo.get_by(WeeklyReport, site_id: site.id)
|
2020-01-22 12:16:53 +03:00
|
|
|
|
2021-05-03 16:56:46 +03:00
|
|
|
if weekly_report do
|
|
|
|
weekly_report
|
|
|
|
|> WeeklyReport.remove_recipient(email)
|
|
|
|
|> Repo.update!()
|
|
|
|
end
|
2020-01-22 12:16:53 +03:00
|
|
|
|
2020-03-02 12:12:11 +03:00
|
|
|
conn
|
|
|
|
|> assign(:skip_plausible_tracking, true)
|
2020-06-08 10:35:13 +03:00
|
|
|
|> render("success.html",
|
|
|
|
interval: "weekly",
|
|
|
|
site: website,
|
|
|
|
layout: {PlausibleWeb.LayoutView, "focus.html"}
|
|
|
|
)
|
2020-01-22 12:16:53 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def monthly_report(conn, %{"website" => website, "email" => email}) do
|
|
|
|
site = Repo.get_by(Plausible.Site, domain: website)
|
2021-05-03 16:56:46 +03:00
|
|
|
monthly_report = site && Repo.get_by(MonthlyReport, site_id: site.id)
|
2020-01-22 12:16:53 +03:00
|
|
|
|
2021-05-03 16:56:46 +03:00
|
|
|
if monthly_report do
|
|
|
|
monthly_report
|
|
|
|
|> MonthlyReport.remove_recipient(email)
|
|
|
|
|> Repo.update!()
|
|
|
|
end
|
2020-01-22 12:16:53 +03:00
|
|
|
|
2020-03-02 12:12:11 +03:00
|
|
|
conn
|
|
|
|
|> assign(:skip_plausible_tracking, true)
|
2020-06-08 10:35:13 +03:00
|
|
|
|> render("success.html",
|
|
|
|
interval: "monthly",
|
|
|
|
site: website,
|
|
|
|
layout: {PlausibleWeb.LayoutView, "focus.html"}
|
|
|
|
)
|
2020-01-22 12:16:53 +03:00
|
|
|
end
|
|
|
|
end
|