Add configurable prevention of user registration
Should be done appropriately soon.
This commit is contained in:
20
lib/outlook_web/prevent_registration.ex
Normal file
20
lib/outlook_web/prevent_registration.ex
Normal file
@ -0,0 +1,20 @@
|
||||
defmodule Outlook.PreventRegistration do
|
||||
|
||||
import Plug.Conn
|
||||
import Phoenix.Controller
|
||||
|
||||
def prevent_registration(conn, _) do
|
||||
if System.get_env("DISABLE_REGISTRATION") && is_registration_path(conn) do
|
||||
conn
|
||||
|> put_flash(:error, "User Registration is disabled.")
|
||||
|> redirect(to: "/users/log_in")
|
||||
|> halt()
|
||||
else
|
||||
conn
|
||||
end
|
||||
end
|
||||
|
||||
defp is_registration_path(conn) do
|
||||
"/users/register" == current_path(conn, %{})
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user