Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to disable signups #78

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
1 change: 1 addition & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions lib/shroud/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions lib/shroud_web/controllers/user_registration_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions lib/shroud_web/templates/user_registration/new.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
</p>
</div>

<%= if Application.fetch_env!(:shroud, :disable_signups) do %>
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md alert alert alert-warning">
Signups are currently disabled.
</div>
<% end %>

<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
<.form :let={f} for={@changeset} action={~p"/users/register"} as={:user}, class="space-y-6">
Expand All @@ -19,7 +25,7 @@
<div>
<%= label f, :email, class: "block text-sm font-medium text-gray-700" %>
<div class="mt-1">
<%= 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 %>
</div>
</div>
Expand All @@ -33,7 +39,7 @@
</div>

<div>
<%= 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" %>
<p class="text-sm mt-3 text-center">
By signing up for Shroud.email, you agree to our <a href="https://shroud.email/terms/" target="_blank" class="underline">terms of use</a>.
</p>
Expand Down
Loading