Added mix commands to manage users and view actors

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-11-21 15:51:13 +01:00
parent 359bbe5449
commit 5e9c91e659
11 changed files with 542 additions and 9 deletions

View File

@@ -137,7 +137,7 @@ defmodule Mobilizon.Users.User do
end
@doc """
Checks whether an user is confirmed.
Checks whether an user is confirmed.
"""
@spec is_confirmed(t) :: boolean
def is_confirmed(%__MODULE__{confirmed_at: nil}), do: false
@@ -154,20 +154,22 @@ defmodule Mobilizon.Users.User do
end
@spec save_confirmation_token(Ecto.Changeset.t()) :: Ecto.Changeset.t()
defp save_confirmation_token(%Ecto.Changeset{} = changeset) do
case changeset do
%Ecto.Changeset{valid?: true, changes: %{email: _email}} ->
now = DateTime.utc_now()
defp save_confirmation_token(
%Ecto.Changeset{valid?: true, changes: %{email: _email}} = changeset
) do
case fetch_change(changeset, :confirmed_at) do
:error ->
changeset
|> put_change(:confirmation_token, Crypto.random_string(@confirmation_token_length))
|> put_change(:confirmation_sent_at, DateTime.truncate(now, :second))
|> put_change(:confirmation_sent_at, DateTime.utc_now() |> DateTime.truncate(:second))
_ ->
changeset
end
end
defp save_confirmation_token(%Ecto.Changeset{} = changeset), do: changeset
@spec validate_email(Ecto.Changeset.t()) :: Ecto.Changeset.t()
defp validate_email(%Ecto.Changeset{} = changeset) do
changeset = validate_length(changeset, :email, min: 3, max: 250)