View Source Teiserver.Account.UserLib (Teiserver v0.0.1)
Library of user related functions.
Summary
Functions
Returns an %Ecto.Changeset{}
for tracking user changes.
Creates a user.
Deletes a user.
Gets a single user.
Gets a single user.
Returns the list of users.
Updates a user.
Takes a user, a plaintext password and returns a boolean if the password is correct for the user. Note it does this via a secure method to prevent timing attacks, never manually verify the password with standard string comparison.
Functions
@spec change_user(Teiserver.Account.User.t(), map()) :: Ecto.Changeset.t()
Returns an %Ecto.Changeset{}
for tracking user changes.
Examples
iex> change_user(user)
%Ecto.Changeset{data: %User{}}
@spec create_user(map()) :: {:ok, Teiserver.Account.User.t()} | {:error, Ecto.Changeset.t()}
Creates a user.
Examples
iex> create_user(%{field: value})
{:ok, %User{}}
iex> create_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec delete_user(Teiserver.Account.User.t()) :: {:ok, Teiserver.Account.User.t()} | {:error, Ecto.Changeset.t()}
Deletes a user.
Examples
iex> delete_user(user)
{:ok, %User{}}
iex> delete_user(user)
{:error, %Ecto.Changeset{}}
@spec get_user(non_neg_integer(), list()) :: Teiserver.Account.User.t() | nil
Gets a single user.
Returns nil if the User does not exist.
Examples
iex> get_user(123)
%User{}
iex> get_user(456)
nil
Gets a single user.
Raises Ecto.NoResultsError
if the User does not exist.
Examples
iex> get_user!(123)
%User{}
iex> get_user!(456)
** (Ecto.NoResultsError)
@spec get_user_by_id(non_neg_integer()) :: Teiserver.Account.User.t() | nil
@spec get_user_by_name(String.t()) :: Teiserver.Account.User.t() | nil
Returns the list of users.
Examples
iex> list_users()
[%User{}, ...]
@spec update_user(Teiserver.Account.User.t(), map()) :: {:ok, Teiserver.Account.User.t()} | {:error, Ecto.Changeset.t()}
Updates a user.
Examples
iex> update_user(user, %{field: new_value})
{:ok, %User{}}
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Takes a user, a plaintext password and returns a boolean if the password is correct for the user. Note it does this via a secure method to prevent timing attacks, never manually verify the password with standard string comparison.