Allow disabling registration

This commit is contained in:
Shadowfacts 2020-08-02 18:35:14 -04:00
parent dfdde04fc2
commit 35f71aa09f
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
7 changed files with 31 additions and 2 deletions

View File

@ -53,6 +53,10 @@ form {
border-radius: 5px;
}
input[type=radio], input[type=checkbox] {
width: auto;
}
textarea {
min-height: 200px;
max-width: 100%;

View File

@ -75,4 +75,5 @@ config :phoenix, :stacktrace_depth, 20
# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime
config :wiki, :registration_enabled, false
config :wiki, :upload_dir, "uploads"

View File

@ -5,6 +5,18 @@ defmodule WikiWeb.UserRegistrationController do
alias Wiki.Accounts.User
alias WikiWeb.UserAuth
plug :check_registration_enabled
def check_registration_enabled(conn, _opts) do
if Application.get_env(:wiki, :registration_enabled, true) do
conn
else
conn
|> send_resp(403, "Forbidden")
|> halt()
end
end
def new(conn, _params) do
changeset = Accounts.change_user_registration(%User{})
render(conn, "new.html", changeset: changeset)

View File

@ -4,7 +4,9 @@
<li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li>
<li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
<% else %>
<li><%= link "Register", to: Routes.user_registration_path(@conn, :new) %></li>
<%= if registration_enabled() do %>
<li><%= link "Register", to: Routes.user_registration_path(@conn, :new) %></li>
<% end %>
<li><%= link "Log in", to: Routes.user_session_path(@conn, :new) %></li>
<% end %>
</ul>

View File

@ -22,6 +22,8 @@
<% end %>
<p>
<%= link "Register", to: Routes.user_registration_path(@conn, :new) %> |
<%= if registration_enabled() do %>
<%= link "Register", to: Routes.user_registration_path(@conn, :new) %> |
<% end %>
<%= link "Forgot your password?", to: Routes.user_reset_password_path(@conn, :new) %>
</p>

View File

@ -1,3 +1,7 @@
defmodule WikiWeb.LayoutView do
use WikiWeb, :view
def registration_enabled() do
Application.get_env(:wiki, :registration_enabled, true)
end
end

View File

@ -1,3 +1,7 @@
defmodule WikiWeb.UserSessionView do
use WikiWeb, :view
def registration_enabled() do
Application.get_env(:wiki, :registration_enabled, true)
end
end