diff --git a/CHANGELOG.md b/CHANGELOG.md index c3cdc5b42..357b1a2ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file. - Move `entry_page` and `exit_page` to be part of the `Page` filter group - Paginate /api/sites results and add a `View all` link to the site-switcher dropdown in the dashboard. - Remove the `+ Add Site` link to the site-switcher dropdown in the dashboard. +- `DISABLE_REGISTRATIONS` configuration parameter can now accept `invite_only` to allow invited users to register an account while keeping regular registrations disabled plausible/analytics#1841 ## v1.4.1 diff --git a/config/runtime.exs b/config/runtime.exs index dc859b364..88e7239f5 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -136,6 +136,10 @@ disable_registration = |> get_var_from_path_or_env("DISABLE_REGISTRATION", "false") |> String.to_existing_atom() +if disable_registration not in [true, false, :invite_only] do + raise "DISABLE_REGISTRATION must be one of `true`, `false`, or `invite_only`. See https://plausible.io/docs/self-hosting-configuration#server" +end + hcaptcha_sitekey = get_var_from_path_or_env(config_dir, "HCAPTCHA_SITEKEY") hcaptcha_secret = get_var_from_path_or_env(config_dir, "HCAPTCHA_SECRET") diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 6a2393994..6cde37737 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -25,7 +25,7 @@ defmodule PlausibleWeb.AuthController do ] def register_form(conn, _params) do - if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) do + if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) != false do redirect(conn, to: Routes.auth_path(conn, :login_form)) else changeset = Plausible.Auth.User.changeset(%Plausible.Auth.User{}) @@ -38,7 +38,7 @@ defmodule PlausibleWeb.AuthController do end def register(conn, params) do - if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) do + if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) != false do redirect(conn, to: Routes.auth_path(conn, :login_form)) else user = Plausible.Auth.User.new(params["user"]) @@ -74,7 +74,7 @@ defmodule PlausibleWeb.AuthController do end def register_from_invitation_form(conn, %{"invitation_id" => invitation_id}) do - if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) do + if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) == true do redirect(conn, to: Routes.auth_path(conn, :login_form)) else invitation = Repo.get_by(Plausible.Auth.Invitation, invitation_id: invitation_id) @@ -97,7 +97,7 @@ defmodule PlausibleWeb.AuthController do end def register_from_invitation(conn, %{"invitation_id" => invitation_id} = params) do - if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) do + if Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) == true do redirect(conn, to: Routes.auth_path(conn, :login_form)) else invitation = Repo.get_by(Plausible.Auth.Invitation, invitation_id: invitation_id) diff --git a/lib/plausible_web/templates/auth/login_form.html.eex b/lib/plausible_web/templates/auth/login_form.html.eex index fbb9eb9fc..f66fe7b54 100644 --- a/lib/plausible_web/templates/auth/login_form.html.eex +++ b/lib/plausible_web/templates/auth/login_form.html.eex @@ -16,7 +16,7 @@
Forgot password? Click here to reset it.
<%= submit "Login →", class: "button mt-4 w-full" %> - <%= if !Keyword.fetch!(Application.get_env(:plausible, :selfhost),:disable_registration) do %> + <%= if Keyword.fetch!(Application.get_env(:plausible, :selfhost),:disable_registration) == false do %>Don't have an account? <%= link("Register", to: "/register", class: "text-gray-800 dark:text-gray-50 underline") %> instead.
diff --git a/lib/plausible_web/templates/layout/_header.html.eex b/lib/plausible_web/templates/layout/_header.html.eex index 5d136da91..f6adc3bb2 100644 --- a/lib/plausible_web/templates/layout/_header.html.eex +++ b/lib/plausible_web/templates/layout/_header.html.eex @@ -54,7 +54,7 @@ - <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) -> %> + <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) != false -> %>