AuthShield v0.0.1 AuthShield.Resources.Users View Source

Users are the base identity in our architecture. It is used to authenticate an profile or to authorize an action given its set of roles.

We use an Role-based access control architecture as an approach to restricting system access to authorized users, so our resources contains users, roles and permissions.

This module implements an interface to deal with database transactions as inserts, updates, deletes, etc.

Link to this section Summary

Types

Transactional responses of failed

Transactional responses of success

Link to this section Types

Link to this type

failed_response()

View Source
failed_response() :: {:error, Ecto.Changeset.t()}

Transactional responses of failed

Link to this type

success_response()

View Source
success_response() :: {:ok, AuthShield.Resources.Schemas.User.t()}

Transactional responses of success

Link to this section Functions

Changes an set of AuthShield.Resources.Schemas.Role of the AuthShield.Resources.Schemas.User.

It will add or remove roles from the list, so you should pass the complete list every time you use this function.

Roles are used in AuthShield.Authorization requests.

Exemples:

  AuthShield.Resources.Users.change_roles(user, roles)

Changes an set of AuthShield.Resources.Schemas.Role of the AuthShield.Resources.Schemas.User.

Similar to append_role/2 but returns the struct or raises if the changeset is invalid.

Deletes a User register.

Exemples:

  AuthShield.Resources.Users.delete(user)

Deletes a AuthShield.Resources.Schemas.User register.

Similar to delete/1 but returns the struct or raises if the changeset is invalid.

Gets a AuthShield.Resources.Schemas.User register by its filters.

Exemples:

  AuthShield.Resources.Users.get_by(email: "lucas@gmail.com")

Gets a AuthShield.Resources.Schemas.User register by its filters.

Similar to get_by/1 but returns the struct or raises if the changeset is invalid.

Creates a new AuthShield.Resources.Schemas.User register.

For an user to be authenticate in the system it will need an credential, so when we create an user we also creates a AuthShield.Credentials.Schemas.Password that can be used to perform actions in AuthShield.Authentication.

Exemples:

  AuthShield.Resources.Users.insert(%{
    first_name: "Lucas",
    last_name: "Mesquita",
    email: "lucas@gmail.com",
    password_credential: %{password: "My_passw@rd2"}
  })

Creates a new AuthShield.Resources.Schemas.User register.

Similar to insert/1 but returns the struct or raises if the changeset is invalid.

Returns a list of AuthShield.Resources.Schemas.User by its filters

Exemples:

  # Getting the all list
  AuthShield.Resources.Users.list()

  # Filtering the list by field
  AuthShield.Resources.Users.list(name: "Lucas")

Preloads the user data by the given fields.

Exemples:

  AuthShield.Resources.Users.preload(user, [:roles])

Changes a User status.

Exemples:

  AuthShield.Resources.Users.status(user, true)

Changes a AuthShield.Resources.Schemas.User status.

Similar to status/1 but returns the struct or raises if the changeset is invalid.

Updates a AuthShield.Resources.Schemas.User register.

Exemples:

  AuthShield.Resources.Users.update(user, %{
    first_name: "Marcos",
    last_name: "Farias",
    email: "marcos@gmail.com"
  })

Updates a AuthShield.Resources.Schemas.User register.

Similar to update/2 but returns the struct or raises if the changeset is invalid.