2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.PageController do
|
|
|
|
use PlausibleWeb, :controller
|
|
|
|
use Plausible.Repo
|
|
|
|
|
|
|
|
@demo_referrers [
|
2020-02-10 16:17:00 +03:00
|
|
|
{"indiehackers.com", 56},
|
|
|
|
{"Github", 23},
|
2019-09-02 14:29:19 +03:00
|
|
|
{"Twitter", 17},
|
2020-02-10 16:17:00 +03:00
|
|
|
{"Reddit", 8},
|
2019-09-02 14:29:19 +03:00
|
|
|
{"Google", 6},
|
|
|
|
{"DuckDuckGo", 4},
|
2020-06-08 10:35:13 +03:00
|
|
|
{"Bing", 2}
|
2019-09-02 14:29:19 +03:00
|
|
|
]
|
|
|
|
|
2020-06-08 10:35:13 +03:00
|
|
|
@demo_pages [
|
|
|
|
{"/", 140},
|
|
|
|
{"/plausible.io", 63},
|
|
|
|
{"/blog", 41},
|
|
|
|
{"/register", 13},
|
|
|
|
{"/login", 7},
|
|
|
|
{"/blog/google-analytics-and-privacy", 4},
|
|
|
|
{"/blog/launching-plausible", 2}
|
2019-09-02 14:29:19 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
if conn.assigns[:current_user] do
|
|
|
|
user = conn.assigns[:current_user] |> Repo.preload(:sites)
|
|
|
|
render(conn, "sites.html", sites: user.sites)
|
|
|
|
else
|
2020-06-08 10:35:13 +03:00
|
|
|
render(conn, "index.html",
|
|
|
|
demo_referrers: @demo_referrers,
|
|
|
|
demo_pages: @demo_pages,
|
|
|
|
landing_nav: true
|
|
|
|
)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule Token do
|
|
|
|
use Joken.Config
|
|
|
|
end
|
|
|
|
|
|
|
|
defp sign_token!(user) do
|
|
|
|
claims = %{
|
|
|
|
id: user.id,
|
|
|
|
email: user.email,
|
2020-06-08 10:35:13 +03:00
|
|
|
name: user.name
|
2019-09-02 14:29:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
signer = Joken.Signer.create("HS256", "4d1d2ae6-4595-4d0b-b98a-8ca5b1f2095a")
|
|
|
|
{:ok, token, _} = Token.generate_and_sign(claims, signer)
|
|
|
|
token
|
|
|
|
end
|
|
|
|
|
|
|
|
def feedback(conn, _params) do
|
|
|
|
if conn.assigns[:current_user] do
|
|
|
|
token = sign_token!(conn.assigns[:current_user])
|
2020-04-13 17:54:47 +03:00
|
|
|
redirect(conn, external: "https://plausible.nolt.io/sso/#{token}")
|
2019-09-02 14:29:19 +03:00
|
|
|
else
|
2020-04-13 17:54:47 +03:00
|
|
|
redirect(conn, external: "https://plausible.nolt.io")
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def roadmap(conn, _params) do
|
|
|
|
if conn.assigns[:current_user] do
|
|
|
|
token = sign_token!(conn.assigns[:current_user])
|
2020-06-08 10:35:13 +03:00
|
|
|
|
|
|
|
redirect(conn,
|
|
|
|
external:
|
|
|
|
"https://plausible.nolt.io/sso/#{token}?returnUrl=https://plausible.nolt.io/roadmap"
|
|
|
|
)
|
2019-09-02 14:29:19 +03:00
|
|
|
else
|
2020-04-13 17:54:47 +03:00
|
|
|
redirect(conn, external: "https://plausible.nolt.io/roadmap")
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def contact_form(conn, _params) do
|
|
|
|
render(conn, "contact_form.html")
|
|
|
|
end
|
|
|
|
|
|
|
|
def submit_contact_form(conn, %{"text" => text, "email" => email}) do
|
2020-05-26 16:09:34 +03:00
|
|
|
PlausibleWeb.Email.feedback(email, text) |> Plausible.Mailer.send_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
render(conn, "contact_thanks.html")
|
|
|
|
end
|
|
|
|
|
|
|
|
def privacy(conn, _params) do
|
|
|
|
render(conn, "privacy.html")
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_policy(conn, _params) do
|
|
|
|
render(conn, "data_policy.html")
|
|
|
|
end
|
|
|
|
|
|
|
|
def terms(conn, _params) do
|
|
|
|
render(conn, "terms.html")
|
|
|
|
end
|
|
|
|
end
|