Files
sukaato-site/lib/sukaato/custom_validators.ex
2025-09-02 20:23:53 -04:00

37 lines
956 B
Elixir

defmodule Sukaato.CustomValidators do
import Ecto.Changeset
import Validate
import Argon2
@moduledoc """
Provide a collecton of custom validation functions for Ecto database
database table update validation.
"""
@doc """
Validate a map , array, or list column for an Ecto database table update.
Arity: 3
Return Value: changeset || add_err/3
"""
def validate_map_format(changeset, field, conventional_mapping) when is_atom(field) do
field_value = get_field(changeset, field)
validation_result = validate(field_value, conventional_mapping)
if elem(validation_result, 0) == :ok do
changeset
else
add_error(changeset, field, "is not a valid map")
end
end
def encrypt_password(changeset, field \\ :password) when is_atom(field) do
field_value = get_field(changeset, field)
field_value = hash_pwd_salt(field_value)
put_change(changeset, field, field_value)
changeset
end
end