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.

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

Link to this function

change_user(user, attrs \\ %{})

View Source
@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{}}
Link to this function

create_user(attrs \\ %{})

View Source
@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{}}
Link to this function

get_user(user_id, query_args \\ [])

View Source
@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
Link to this function

get_user!(user_id, query_args \\ [])

View Source

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
Link to this function

list_users(query_args \\ [])

View Source
@spec list_users(list()) :: list()

Returns the list of users.

Examples

iex> list_users()
[%User{}, ...]
Link to this function

update_user(user, attrs)

View Source
@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{}}
Link to this function

verify_user_password(user, plaintext_password)

View Source
@spec verify_user_password(Teiserver.Account.User.t(), String.t()) :: boolean()

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.