basic_signup_allowlist/lib/basic_signup_whitelist.ex
Willem van den Ende c848ca17ad Gave up trying to reset env var - set to "*" after test
And after doctest. it stayed at "*" after the last test anyway, letting
the doctest fail.

doctests are not recommended for side effectful tests anyway https://hexdocs.pm/ex_unit/main/ExUnit.DocTest.html
2025-09-14 21:30:08 +01:00

34 lines
1023 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
iex> System.put_env("SIGNUP_ALLOWED_EMAILS","*")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
true
"""
def mail_whitelisted(email) do
env_value = System.get_env("SIGNUP_ALLOWED_EMAILS")
mail_whitelisted_fun(env_value, email)
end
end