27 lines
736 B
Elixir
27 lines
736 B
Elixir
defmodule Mv.Accounts.User.Validations.RegistrationEnabled do
|
|
@moduledoc """
|
|
Validation that blocks direct registration (register_with_password) when
|
|
registration is disabled in global settings. Used so that even direct API/form
|
|
submissions cannot register when the setting is off.
|
|
"""
|
|
use Ash.Resource.Validation
|
|
|
|
alias Mv.Membership
|
|
|
|
@impl true
|
|
def init(opts), do: {:ok, opts}
|
|
|
|
@impl true
|
|
def validate(_changeset, _opts, _context) do
|
|
case Membership.get_settings() do
|
|
{:ok, %{registration_enabled: true}} ->
|
|
:ok
|
|
|
|
_ ->
|
|
{:error,
|
|
field: :base,
|
|
message:
|
|
"Registration is disabled. Please use the join form or contact an administrator."}
|
|
end
|
|
end
|
|
end
|