Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Adds "invite_only" disable_registration config option (#1841)

Vignesh Joglekarb7b69c6f6268
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c3cdc5b421..357b1a2ee4 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 dc859b3642..88e7239f5f 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 6a23939941..6cde37737c 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 fbb9eb9fcd..f66fe7b542 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 @@
<p class="text-gray-500 text-xs my-2">Forgot password? <a href="/password/request-reset" class="underline text-gray-800 dark:text-gray-50">Click here</a> to reset it.</p>
</div>
<%= 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 %>
<p class="text-center text-gray-500 text-xs mt-4">
Don't have an account? <%= link("Register", to: "/register", class: "text-gray-800 dark:text-gray-50 underline") %> instead.
</p>
diff --git a/lib/plausible_web/templates/layout/_header.html.eex b/lib/plausible_web/templates/layout/_header.html.eex
index 5d136da918..f6adc3bb2b 100644
--- a/lib/plausible_web/templates/layout/_header.html.eex
+++ b/lib/plausible_web/templates/layout/_header.html.eex
@@ -54,7 +54,7 @@
</div>
</li>
</ul>
- <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) -> %>
+ <% Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_registration) != false -> %>
<ul class="flex" x-show="!document.cookie.includes('logged_in=true')">
<li>
<div class="inline-flex">