From c97043e191a07dcc28e06baf62c91f366d4f3628 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 1 Apr 2021 10:43:32 +0300 Subject: [PATCH] Add ability to delete account and start over in activate flow Fixes #581 --- lib/plausible_web/controllers/auth_controller.ex | 6 ++++-- lib/plausible_web/plugs/require_account.ex | 2 +- lib/plausible_web/router.ex | 2 +- lib/plausible_web/templates/auth/activate.html.eex | 10 +++++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 5db18df23..ab8d85bdc 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -377,11 +377,13 @@ defmodule PlausibleWeb.AuthController do logout(conn, params) end - def logout(conn, _params) do + def logout(conn, params) do + redirect_to = Map.get(params, "redirect", "/") + conn |> configure_session(drop: true) |> delete_resp_cookie("logged_in") - |> redirect(to: "/") + |> redirect(to: redirect_to) end def google_auth_callback(conn, %{"code" => code, "state" => site_id}) do diff --git a/lib/plausible_web/plugs/require_account.ex b/lib/plausible_web/plugs/require_account.ex index ee0c6ebdb..4295a4801 100644 --- a/lib/plausible_web/plugs/require_account.ex +++ b/lib/plausible_web/plugs/require_account.ex @@ -14,7 +14,7 @@ defmodule PlausibleWeb.RequireAccountPlug do |> Phoenix.Controller.redirect(to: "/login") |> halt - not user.email_verified and conn.path_info != ["activate"] -> + not user.email_verified and conn.path_info not in [["activate"], ["me"]] -> conn |> Phoenix.Controller.redirect(to: "/activate") |> halt diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index 78cb52664..8dc0d8232 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -95,7 +95,7 @@ defmodule PlausibleWeb.Router do end scope "/", PlausibleWeb do - pipe_through :browser + pipe_through [:browser, :csrf] get "/register", AuthController, :register_form post "/register", AuthController, :register diff --git a/lib/plausible_web/templates/auth/activate.html.eex b/lib/plausible_web/templates/auth/activate.html.eex index 806ab6f91..3f84ced06 100644 --- a/lib/plausible_web/templates/auth/activate.html.eex +++ b/lib/plausible_web/templates/auth/activate.html.eex @@ -18,11 +18,19 @@
Didn't receive an email?
-
    +
    1. Check your spam folder
    2. <%= link("Send a new code", class: "underline text-indigo-600", to: "/activate/request-code", method: :post) %> to <%= @conn.assigns[:current_user].email %>
    3. Contact support@plausible.io if the problem persists
    +
    + Entered the wrong email address? +
    + <% end %> <% else %>