Introduce registerPerson mutation
To register a profile from an unactivated user Signed-off-by: Thomas Citharel <tcit@tcit.fr> 👤 Fix Person interface use Signed-off-by: Thomas Citharel <tcit@tcit.fr> Change host function for data property Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -103,6 +103,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||
:user_id
|
||||
])
|
||||
|> build_urls()
|
||||
# Needed because following constraint can't work for domain null values (local)
|
||||
|> unique_username_validator()
|
||||
|> unique_constraint(:preferred_username, name: :actors_preferred_username_domain_type_index)
|
||||
|> unique_constraint(:url, name: :actors_url_index)
|
||||
|> validate_required([:preferred_username, :keys, :suspended, :url, :type])
|
||||
@@ -177,6 +179,16 @@ defmodule Mobilizon.Actors.Actor do
|
||||
|> put_change(:local, true)
|
||||
end
|
||||
|
||||
def unique_username_validator(
|
||||
%Ecto.Changeset{changes: %{preferred_username: username}} = changeset
|
||||
) do
|
||||
if Actors.get_local_actor_by_name(username) do
|
||||
changeset |> add_error(:preferred_username, "Username is already taken")
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end
|
||||
|
||||
@spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
|
||||
defp build_urls(changeset, type \\ :Person)
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ defmodule Mobilizon.Actors.User do
|
||||
|> cast(attrs, [
|
||||
:email,
|
||||
:role,
|
||||
:password,
|
||||
:password_hash,
|
||||
:confirmed_at,
|
||||
:confirmation_sent_at,
|
||||
@@ -38,13 +39,13 @@ defmodule Mobilizon.Actors.User do
|
||||
:reset_password_token
|
||||
])
|
||||
|> validate_required([:email])
|
||||
|> unique_constraint(:email, message: "registration.error.email_already_used")
|
||||
|> validate_format(:email, ~r/@/)
|
||||
|> unique_constraint(:email, message: "This email is already used.")
|
||||
|> validate_email()
|
||||
|> validate_length(
|
||||
:password,
|
||||
min: 6,
|
||||
max: 100,
|
||||
message: "registration.error.password_too_short"
|
||||
message: "The choosen password is too short."
|
||||
)
|
||||
|
||||
if Map.has_key?(attrs, :default_actor) do
|
||||
@@ -57,21 +58,13 @@ defmodule Mobilizon.Actors.User do
|
||||
def registration_changeset(struct, params) do
|
||||
struct
|
||||
|> changeset(params)
|
||||
|> cast(params, ~w(password)a, [])
|
||||
|> cast_assoc(:default_actor)
|
||||
|> validate_required([:email, :password])
|
||||
|> validate_email()
|
||||
|> validate_length(
|
||||
:password,
|
||||
min: 6,
|
||||
max: 100,
|
||||
message: "registration.error.password_too_short"
|
||||
)
|
||||
|> hash_password()
|
||||
|> save_confirmation_token()
|
||||
|> unique_constraint(
|
||||
:confirmation_token,
|
||||
message: "regisration.error.confirmation_token_already_in_use"
|
||||
message: "The registration is already in use, this looks like an issue on our side."
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user