This commit is contained in:
parent
eadf90b5fc
commit
f1d0526209
19 changed files with 547 additions and 15 deletions
33
lib/mv_web/plugs/join_form_enabled.ex
Normal file
33
lib/mv_web/plugs/join_form_enabled.ex
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
defmodule MvWeb.Plugs.JoinFormEnabled do
|
||||
@moduledoc """
|
||||
For GET /join: returns 404 when the join form is disabled in settings.
|
||||
No-op for other paths.
|
||||
"""
|
||||
import Plug.Conn
|
||||
|
||||
alias Mv.Membership
|
||||
|
||||
def init(opts), do: opts
|
||||
|
||||
def call(conn, _opts) do
|
||||
if join_path?(conn), do: maybe_404(conn), else: conn
|
||||
end
|
||||
|
||||
defp join_path?(conn) do
|
||||
conn.request_path == "/join" and conn.method == "GET"
|
||||
end
|
||||
|
||||
defp maybe_404(conn) do
|
||||
case Membership.get_settings() do
|
||||
{:ok, %{join_form_enabled: true}} -> conn
|
||||
_ -> send_404(conn)
|
||||
end
|
||||
end
|
||||
|
||||
defp send_404(conn) do
|
||||
conn
|
||||
|> put_resp_content_type("text/html")
|
||||
|> send_resp(404, "Not Found")
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue