mirror of
https://github.com/plausible/analytics.git
synced 2024-12-29 04:22:34 +03:00
439c5014d4
* Implement PoC for email reverification flow on update * Improve user settings form and email change validation * Expose `previous_email` in Kaffy CRM * Improve plugs setup and remove dead action from AuthController * Fix seeds * Extract predicate query functions from AuthController * Add tests * Update CHANGELOG.md * Rename `has_any_sites?` to `Memberships.any?` and `has_any_memberships?` * Improve flash message on cancelling email change * Cover one more test case for email update
35 lines
713 B
Elixir
35 lines
713 B
Elixir
defmodule PlausibleWeb.RequireAccountPlug do
|
|
import Plug.Conn
|
|
|
|
@unverified_email_exceptions [
|
|
["settings", "email", "cancel"],
|
|
["activate"],
|
|
["activate", "request-code"],
|
|
["me"]
|
|
]
|
|
|
|
def init(options) do
|
|
options
|
|
end
|
|
|
|
def call(conn, _opts) do
|
|
user = conn.assigns[:current_user]
|
|
|
|
cond do
|
|
is_nil(user) ->
|
|
Plug.Conn.put_session(conn, :login_dest, conn.request_path)
|
|
|> Phoenix.Controller.redirect(to: "/login")
|
|
|> halt
|
|
|
|
not user.email_verified and
|
|
conn.path_info not in @unverified_email_exceptions ->
|
|
conn
|
|
|> Phoenix.Controller.redirect(to: "/activate")
|
|
|> halt
|
|
|
|
true ->
|
|
conn
|
|
end
|
|
end
|
|
end
|