From 25f95ae84e500cc82a9c0a46c9f790e8d6a96881 Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Thu, 1 Jun 2023 19:34:48 +0800 Subject: [PATCH] add landing page (#2989) * add landing page * cont. * add redirect to /sites test * add changelog entry * adapt for mobile --- CHANGELOG.md | 3 +- .../controllers/page_controller.ex | 8 ++--- .../templates/page/index.html.eex | 34 +++++++++++++++++++ lib/plausible_web/views/page_view.ex | 3 ++ .../controllers/page_controller_test.exs | 18 ++++++++++ 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 lib/plausible_web/templates/page/index.html.eex create mode 100644 lib/plausible_web/views/page_view.ex create mode 100644 test/plausible_web/controllers/page_controller_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 20f74be07..f7f4df102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ All notable changes to this project will be documented in this file. - Ability to change domain for existing site (requires numeric IDs data migration, instructions will be provided separately) UI + API (`PUT /api/v1/sites`) - Add `LOG_FAILED_LOGIN_ATTEMPTS` environment variable to enable failed login attempts logs plausible/analytics#2936 - Add `MAILER_NAME` environment variable support plausible/analytics#2937 -- Add `MAILGUN_BASE_URI` support for `Bamboo.MailgunAdapter` plausible/analytics#2935 +- Add `MAILGUN_BASE_URI` support for `Bamboo.MailgunAdapter` plausible/analytics#2935 +- Add a landing page for self-hosters plausible/analytics#2989 ### Fixed - Fix tracker bug - call callback function even when event is ignored diff --git a/lib/plausible_web/controllers/page_controller.ex b/lib/plausible_web/controllers/page_controller.ex index 03ec4f2aa..28dd3b35f 100644 --- a/lib/plausible_web/controllers/page_controller.ex +++ b/lib/plausible_web/controllers/page_controller.ex @@ -2,14 +2,14 @@ defmodule PlausibleWeb.PageController do use PlausibleWeb, :controller use Plausible.Repo + plug PlausibleWeb.RequireLoggedOutPlug + @doc """ The root path is never accessible in Plausible.Cloud because it is handled by the upstream reverse proxy. - This controller action is only ever triggered in self-hosted Plausible. It redirects the user to /login where `PlausibleWeb.RequireLoggedOutPlug` plug kicks in. If they are already logged in, they are redirected to /sites, otherwise they'll see the /login page. + This controller action is only ever triggered in self-hosted Plausible. """ def index(conn, _params) do - conn - |> put_session(:login_dest, conn.request_path) - |> redirect(to: "/login") + render(conn, "index.html", layout: {PlausibleWeb.LayoutView, "focus.html"}) end end diff --git a/lib/plausible_web/templates/page/index.html.eex b/lib/plausible_web/templates/page/index.html.eex new file mode 100644 index 000000000..add67784b --- /dev/null +++ b/lib/plausible_web/templates/page/index.html.eex @@ -0,0 +1,34 @@ +
+

+ Welcome to Plausible Analytics! +

+

+ Plausible Analytics is a simple, open source, lightweight (< 1 KB) and privacy-friendly alternative to Google Analytics. We're completely independent and solely funded by our 10,000+ paying subscribers. Read more about us. +

+ +
diff --git a/lib/plausible_web/views/page_view.ex b/lib/plausible_web/views/page_view.ex new file mode 100644 index 000000000..c4ace790b --- /dev/null +++ b/lib/plausible_web/views/page_view.ex @@ -0,0 +1,3 @@ +defmodule PlausibleWeb.PageView do + use PlausibleWeb, :view +end diff --git a/test/plausible_web/controllers/page_controller_test.exs b/test/plausible_web/controllers/page_controller_test.exs new file mode 100644 index 000000000..f9246391d --- /dev/null +++ b/test/plausible_web/controllers/page_controller_test.exs @@ -0,0 +1,18 @@ +defmodule PlausibleWeb.PageControllerTest do + use PlausibleWeb.ConnCase, async: true + + describe "GET /" do + test "shows landing page when user not authenticated", %{conn: conn} do + assert conn |> get("/") |> html_response(200) =~ "Welcome to Plausible Analytics!" + end + + test "redirects to /sites if user is authenticated", %{conn: conn} do + user = insert(:user) + + assert conn + |> init_test_session(%{current_user_id: user.id}) + |> get("/") + |> redirected_to(302) == "/sites" + end + end +end