poa_backend v0.1.0 POABackend.Auth View Source

This module defines the API for the Authorisation

Link to this section Summary

Functions

This function Activates a user, storing active: true in the database for the given user

This function authenticates a user/password pair

Creates a token entry in the banned tokens table. It receives a jwt token in String format. This function will extract the expiration time from the claims and store them in the Database

Creates a token entry in the banned tokens table. It receives the token in String format and the expiration time as Integer

Registers a user in the system

This function Deactivates a user, storing active: false in the database for the given user

Generates a password randomply

Generates a valid user name randomply

This function is exported for testing purposes

Get a user from the database based in the user name

This function deletes the banned tokens which already expired

Deletes a user from the database based in the given user

Checks if a token is banned or not

Checks if a user is active

Validates if a JWT token is valid

Validates if a given user name is valid or not. It is valid if doesn’t exist a user with that name in the database already

Link to this section Functions

This function Activates a user, storing active: true in the database for the given user

Link to this function authenticate_admin(admin_name, password) View Source
authenticate_admin(String.t(), String.t()) ::
  {:ok, :valid} | {:error, :notvalid}

Authenticates an Admin

Link to this function authenticate_user(user_name, password) View Source
authenticate_user(String.t(), String.t()) ::
  {:ok, POABackend.Auth.Models.User.t()} | {:error, :notvalid}

This function authenticates a user/password pair

Link to this function create_banned_token(jwt_token) View Source
create_banned_token(String.t()) ::
  {:ok, POABackend.Auth.Models.Token.t()} | {:error, any()}

Creates a token entry in the banned tokens table. It receives a jwt token in String format. This function will extract the expiration time from the claims and store them in the Database.

Link to this function create_banned_token(token, expires) View Source
create_banned_token(String.t(), integer()) ::
  {:ok, POABackend.Auth.Models.Token.t()} | {:error, :already_exists}

Creates a token entry in the banned tokens table. It receives the token in String format and the expiration time as Integer.

Link to this function create_user(user_name, password, active \\ true) View Source
create_user(String.t(), String.t(), Boolean.t()) ::
  {:ok, POABackend.Auth.Models.User.t()}
  | {:error, :already_exists}
  | {:error, Ecto.Changeset.t()}

Registers a user in the system.

This function Deactivates a user, storing active: false in the database for the given user

Link to this function generate_password() View Source
generate_password() :: String.t()

Generates a password randomply

Link to this function generate_user_name() View Source
generate_user_name() :: String.t()

Generates a valid user name randomply

Link to this function generate_user_name(user_name) View Source
generate_user_name(String.t()) :: String.t()

This function is exported for testing purposes

Get a user from the database based in the user name

Link to this function purge_banned_tokens() View Source
purge_banned_tokens() :: :ok

This function deletes the banned tokens which already expired

Deletes a user from the database based in the given user

Link to this function token_banned?(token) View Source
token_banned?(String.t()) :: Boolean.t()

Checks if a token is banned or not

Link to this function user_active?(user) View Source
user_active?(POABackend.Auth.Models.User.t()) :: Boolean.t()

Checks if a user is active

Link to this function valid_token?(jwt_token) View Source
valid_token?(String.t()) :: Boolean.t() | {:error, :token_expired}

Validates if a JWT token is valid.

Link to this function valid_user_name?(user_name) View Source
valid_user_name?(String.t()) :: Boolean.t()

Validates if a given user name is valid or not. It is valid if doesn’t exist a user with that name in the database already