Create convenience methods to allow or deny all
This commit is contained in:
parent
8b527f618a
commit
38ba27cd0e
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user