Create convenience methods to allow or deny all

This commit is contained in:
Your Name 2025-09-16 13:47:22 +00:00
parent 8b527f618a
commit 38ba27cd0e

View File

@ -13,6 +13,7 @@ defmodule BasicSignupAllowlist do
@spec signup_allowlist_emails() :: String.t() @spec signup_allowlist_emails() :: String.t()
def signup_allowlist_emails, do: @signup_allowlist_emails def signup_allowlist_emails, do: @signup_allowlist_emails
@doc """ @doc """
Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable. Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable.
@ -26,10 +27,10 @@ defmodule BasicSignupAllowlist do
## Examples ## Examples
iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS") iex> BasicSignupAllowlist.forbid_signup_with_any_email()
iex> BasicSignupAllowlist.signup_allowed?("joe@example.com") iex> BasicSignupAllowlist.signup_allowed?("joe@example.com")
false false
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS", "*") iex> BasicSignupAllowlist.allow_signup_with_all_emails()
iex> BasicSignupAllowlist.signup_allowed?("joe@example.com") iex> BasicSignupAllowlist.signup_allowed?("joe@example.com")
true true
@ -39,4 +40,12 @@ defmodule BasicSignupAllowlist do
env_value = System.get_env(@signup_allowlist_emails) env_value = System.get_env(@signup_allowlist_emails)
signup_allowed_fun(env_value, email) signup_allowed_fun(env_value, email)
end end
def allow_signup_with_all_emails() do
System.put_env(signup_allowlist_emails(), "*")
end
def forbid_signup_with_any_email() do
System.delete_env(signup_allowlist_emails())
end
end end