Allow disabling registration
This commit is contained in:
parent
dfdde04fc2
commit
35f71aa09f
|
@ -53,6 +53,10 @@ form {
|
|||
border-radius: 5px;
|
||||
}
|
||||
|
||||
input[type=radio], input[type=checkbox] {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
textarea {
|
||||
min-height: 200px;
|
||||
max-width: 100%;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 %>
|
||||
<%= 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>
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= 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>
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
defmodule WikiWeb.LayoutView do
|
||||
use WikiWeb, :view
|
||||
|
||||
def registration_enabled() do
|
||||
Application.get_env(:wiki, :registration_enabled, true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
defmodule WikiWeb.UserSessionView do
|
||||
use WikiWeb, :view
|
||||
|
||||
def registration_enabled() do
|
||||
Application.get_env(:wiki, :registration_enabled, true)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue