From 43d002afd379f7bcdb5d32335178531d42166daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tao=20Bojl=C3=A9n?= <66130243+taobojlen@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:08:27 +0000 Subject: [PATCH] feat: add ability to disable signups (#78) --- config/config.exs | 3 ++- config/runtime.exs | 1 + lib/shroud/accounts.ex | 22 ++++++++++--------- .../user_registration_controller.ex | 6 +++++ .../templates/user_registration/new.html.heex | 10 +++++++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/config/config.exs b/config/config.exs index 5ea6ab5..e3a613e 100644 --- a/config/config.exs +++ b/config/config.exs @@ -43,7 +43,8 @@ config :shroud, :mailer, config :shroud, http_client: HTTPoison, - tracker_list_uri: "https://trackers.shroud.email/list.txt" + tracker_list_uri: "https://trackers.shroud.email/list.txt", + disable_signups: false config :shroud, Shroud.Scheduler, jobs: [ diff --git a/config/runtime.exs b/config/runtime.exs index a8aab40..3aac144 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -127,6 +127,7 @@ if config_env() == :prod do email_octopus_list_id: System.get_env("EMAIL_OCTOPUS_LIST_ID"), email_octopus_api_key: System.get_env("EMAIL_OCTOPUS_API_KEY"), admin_user_email: System.get_env("ADMIN_EMAIL"), + disable_signups: System.get_env("DISABLE_SIGNUPS", false) != false, app_domain: app_domain, email_domain: email_domain, env: :prod diff --git a/lib/shroud/accounts.ex b/lib/shroud/accounts.ex index 414f3f9..274b7f6 100644 --- a/lib/shroud/accounts.ex +++ b/lib/shroud/accounts.ex @@ -94,16 +94,18 @@ defmodule Shroud.Accounts do """ def register_user(attrs) do - case %User{} - |> User.registration_changeset(attrs) - |> Repo.insert(returning: true) do - {:ok, user} -> - Notifier.notify_user_started_trial(user.email) - Logger.notice("User #{user.email} started a trial") - {:ok, user} - - other -> - other + if not Application.fetch_env!(:shroud, :disable_signups) do + case %User{} + |> User.registration_changeset(attrs) + |> Repo.insert(returning: true) do + {:ok, user} -> + Notifier.notify_user_started_trial(user.email) + Logger.notice("User #{user.email} started a trial") + {:ok, user} + + other -> + other + end end end diff --git a/lib/shroud_web/controllers/user_registration_controller.ex b/lib/shroud_web/controllers/user_registration_controller.ex index c8a6e9a..cdaff29 100644 --- a/lib/shroud_web/controllers/user_registration_controller.ex +++ b/lib/shroud_web/controllers/user_registration_controller.ex @@ -30,6 +30,12 @@ defmodule ShroudWeb.UserRegistrationController do changeset: changeset, lifetime: user_params["status"] == "lifetime" ) + + nil -> + render(conn, "new.html", + changeset: User.registration_changeset(%User{}, %{}), + lifetime: user_params["status"] == "lifetime" + ) end end end diff --git a/lib/shroud_web/templates/user_registration/new.html.heex b/lib/shroud_web/templates/user_registration/new.html.heex index d6a5b93..9ccfcd6 100644 --- a/lib/shroud_web/templates/user_registration/new.html.heex +++ b/lib/shroud_web/templates/user_registration/new.html.heex @@ -9,6 +9,12 @@

+ <%= if Application.fetch_env!(:shroud, :disable_signups) do %> +
+ Signups are currently disabled. +
+ <% end %> +
<.form :let={f} for={@changeset} action={~p"/users/register"} as={:user}, class="space-y-6"> @@ -19,7 +25,7 @@
<%= label f, :email, class: "block text-sm font-medium text-gray-700" %>
- <%= email_input f, :email, required: true, autocomplete: "email", class: "appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" %> + <%= email_input f, :email, required: true, autocomplete: "email", class: "appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" %> <%= error_tag f, :email %>
@@ -33,7 +39,7 @@
- <%= submit "Sign up", class: "w-full btn btn-primary" %> + <%= submit "Sign up", disabled: Application.fetch_env!(:shroud, :disable_signups), class: "w-full btn btn-primary disabled:cursor-not-allowed disabled:opacity-50" %>

By signing up for Shroud.email, you agree to our terms of use.