diff --git a/assets/css/app.scss b/assets/css/app.scss index 50487a4..d7d50c2 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -53,6 +53,10 @@ form { border-radius: 5px; } + input[type=radio], input[type=checkbox] { + width: auto; + } + textarea { min-height: 200px; max-width: 100%; diff --git a/config/dev.exs b/config/dev.exs index a4b6d53..5d936a7 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -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" diff --git a/lib/wiki_web/controllers/user_registration_controller.ex b/lib/wiki_web/controllers/user_registration_controller.ex index a623ad1..deb2885 100644 --- a/lib/wiki_web/controllers/user_registration_controller.ex +++ b/lib/wiki_web/controllers/user_registration_controller.ex @@ -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) diff --git a/lib/wiki_web/templates/layout/_user_menu.html.eex b/lib/wiki_web/templates/layout/_user_menu.html.eex index f281cfc..57cda5a 100644 --- a/lib/wiki_web/templates/layout/_user_menu.html.eex +++ b/lib/wiki_web/templates/layout/_user_menu.html.eex @@ -4,7 +4,9 @@
  • <%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %>
  • <%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %>
  • <% else %> -
  • <%= link "Register", to: Routes.user_registration_path(@conn, :new) %>
  • + <%= if registration_enabled() do %> +
  • <%= link "Register", to: Routes.user_registration_path(@conn, :new) %>
  • + <% end %>
  • <%= link "Log in", to: Routes.user_session_path(@conn, :new) %>
  • <% end %> diff --git a/lib/wiki_web/templates/user_session/new.html.eex b/lib/wiki_web/templates/user_session/new.html.eex index 7be6449..0d85a0a 100644 --- a/lib/wiki_web/templates/user_session/new.html.eex +++ b/lib/wiki_web/templates/user_session/new.html.eex @@ -22,6 +22,8 @@ <% end %>

    - <%= 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) %>

    diff --git a/lib/wiki_web/views/layout_view.ex b/lib/wiki_web/views/layout_view.ex index 003968e..d4fbc4a 100644 --- a/lib/wiki_web/views/layout_view.ex +++ b/lib/wiki_web/views/layout_view.ex @@ -1,3 +1,7 @@ defmodule WikiWeb.LayoutView do use WikiWeb, :view + + def registration_enabled() do + Application.get_env(:wiki, :registration_enabled, true) + end end diff --git a/lib/wiki_web/views/user_session_view.ex b/lib/wiki_web/views/user_session_view.ex index 73fde9b..fd057e4 100644 --- a/lib/wiki_web/views/user_session_view.ex +++ b/lib/wiki_web/views/user_session_view.ex @@ -1,3 +1,7 @@ defmodule WikiWeb.UserSessionView do use WikiWeb, :view + + def registration_enabled() do + Application.get_env(:wiki, :registration_enabled, true) + end end