mirror of
https://github.com/plausible/analytics.git
synced 2024-12-18 14:51:57 +03:00
44 lines
1.2 KiB
Elixir
44 lines
1.2 KiB
Elixir
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)
|
|
weekly_report = site && Repo.get_by(WeeklyReport, site_id: site.id)
|
|
|
|
if weekly_report do
|
|
weekly_report
|
|
|> WeeklyReport.remove_recipient(email)
|
|
|> Repo.update!()
|
|
end
|
|
|
|
conn
|
|
|> assign(:skip_plausible_tracking, true)
|
|
|> render("success.html",
|
|
interval: "weekly",
|
|
site: website,
|
|
layout: {PlausibleWeb.LayoutView, "focus.html"}
|
|
)
|
|
end
|
|
|
|
def monthly_report(conn, %{"website" => website, "email" => email}) do
|
|
site = Repo.get_by(Plausible.Site, domain: website)
|
|
monthly_report = site && Repo.get_by(MonthlyReport, site_id: site.id)
|
|
|
|
if monthly_report do
|
|
monthly_report
|
|
|> MonthlyReport.remove_recipient(email)
|
|
|> Repo.update!()
|
|
end
|
|
|
|
conn
|
|
|> assign(:skip_plausible_tracking, true)
|
|
|> render("success.html",
|
|
interval: "monthly",
|
|
site: website,
|
|
layout: {PlausibleWeb.LayoutView, "focus.html"}
|
|
)
|
|
end
|
|
end
|