basic_signup_allowlist/lib/basic_signup_whitelist.ex
Willem van den Ende ca4eaf6f54 Add workaround for failing doctest
on_exit in test does not work properly as teardown - the variable is
unset, but doctest apparently runs after tests and it is not cleaned up
2025-09-14 20:19:18 +01:00

31 lines
889 B
Elixir

defmodule BasicSignupWhitelist do
import FunCore.BasicSignupWhitelist
@moduledoc """
Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
"""
@doc """
Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
Rules:
- Returns true if ALLOWED_EMAILS == "*" (all emails allowed)
- Returns true if email matches any entry in the comma-separated list
- Returns false if:
* Environment variable doesn't exist
* Environment variable is empty string
* Email not found in whitelist
## Examples
iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
false
"""
def mail_whitelisted(email) do
env_value = System.get_env("SIGNUP_ALLOWED_EMAILS")
mail_whitelisted_fun(env_value, email)
end
end