Adds "invite_only" disable_registration config option (#1841)

* Adds tri-state disable_registration config

* Formatting

* Changes variable back to atom

* Changelog

* Uses atoms correctly :/

* Swaps to a more fitting value

* Formatting
pull/1887/head
Vignesh Joglekar 5 years ago committed by GitHub
parent eeaefc1ad0
commit b7b69c6f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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")

@ -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)

@ -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>

@ -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">

Loading…
Cancel
Save