diff --git a/config/config.exs b/config/config.exs index f1e323c..24bc9e1 100644 --- a/config/config.exs +++ b/config/config.exs @@ -11,9 +11,13 @@ config :exmr, ecto_repos: [Exmr.Repo], generators: [timestamp_type: :utc_datetime] +config :exmr, + registration_enabled: "true" + # Configures the endpoint config :exmr, ExmrWeb.Endpoint, url: [host: "localhost"], + registration_enabled: "true", adapter: Bandit.PhoenixAdapter, render_errors: [ formats: [html: ExmrWeb.ErrorHTML, json: ExmrWeb.ErrorJSON], diff --git a/lib/exmr.ex b/lib/exmr.ex index b3f2fe5..8af05bc 100644 --- a/lib/exmr.ex +++ b/lib/exmr.ex @@ -6,4 +6,8 @@ defmodule Exmr do Contexts are also responsible for managing your data, regardless if it comes from the database, an external API or others. """ + + def enable_registration do + Application.fetch_env!(:exmr, :registration_enabled) + end end diff --git a/lib/exmr_web/router.ex b/lib/exmr_web/router.ex index 248fbdc..460690a 100644 --- a/lib/exmr_web/router.ex +++ b/lib/exmr_web/router.ex @@ -3,6 +3,8 @@ defmodule ExmrWeb.Router do import ExmrWeb.UserAuth + # enable_registration = Application.fetch_env!(:exmr, :registration_enabled) + pipeline :browser do plug :accepts, ["html"] plug :fetch_session @@ -52,7 +54,7 @@ defmodule ExmrWeb.Router do live_session :redirect_if_user_is_authenticated, on_mount: [{ExmrWeb.UserAuth, :redirect_if_user_is_authenticated}] do - if Application.get_env(:exmr, :registration_enabled) != "false" do + if Exmr.enable_registration() != "false" do live "/users/register", UserRegistrationLive, :new end @@ -69,7 +71,7 @@ defmodule ExmrWeb.Router do live_session :require_authenticated_user, on_mount: [{ExmrWeb.UserAuth, :ensure_authenticated}] do - if Application.get_env(:exmr, :registration_enabled) == "false" do + if Exmr.enable_registration() == "false" do live "/users/register", UserRegistrationLive, :new end