create logical link between users and members closes #164 #172

Merged
moritz merged 14 commits from feature/user-member-relation into main 2025-10-16 16:29:49 +02:00
Showing only changes of commit 3b0c1da1ab - Show all commits

View file

@ -166,6 +166,28 @@ defmodule Mv.Accounts.User do
where: [action_is([:register_with_password, :admin_set_password])],
message: "must have length of at least 8"
# Email validation with EctoCommons.EmailValidator (same as Member)
# This ensures consistency between User and Member email validation
validate fn changeset, _ ->
# Get email from attribute (Ash.CiString) and convert to string
email = Ash.Changeset.get_attribute(changeset, :email)
email_string = if email, do: to_string(email), else: nil
# Only validate if email is present
if email_string do
changeset2 =
{%{}, %{email: :string}}
|> Ecto.Changeset.cast(%{email: email_string}, [:email])
|> EctoCommons.EmailValidator.validate_email(:email, checks: [:html_input, :pow])
if changeset2.valid? do
:ok
else
moritz marked this conversation as resolved Outdated

For translation reasons, gettext should be used for all those error messages

For translation reasons, gettext should be used for all those error messages

These messages are translated by ash. Only the translation text was missing.

These messages are translated by ash. Only the translation text was missing.
{:error, field: :email, message: "is not a valid email"}
end
else
:ok
end
end
# Prevent overwriting existing member relationship
@ -204,7 +226,13 @@ defmodule Mv.Accounts.User do
attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false, public?: true
attribute :email, :ci_string do
allow_nil? false
public? true
# Same constraints as Member email for consistency
constraints min_length: 5, max_length: 254
end
attribute :hashed_password, :string, sensitive?: true, allow_nil?: true
attribute :oidc_id, :string, allow_nil?: true
end