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
Authenticates an Admin
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
activate_user(POABackend.Auth.Models.User.t()) :: {:ok, POABackend.Auth.Models.User.t()} | {:error, Ecto.Changeset.t()}
This function Activates a user, storing active: true
in the database for the given user
Authenticates an Admin
authenticate_user(String.t(), String.t()) :: {:ok, POABackend.Auth.Models.User.t()} | {:error, :notvalid}
This function authenticates a user/password pair
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.
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.
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.
deactivate_user(POABackend.Auth.Models.User.t()) :: {:ok, POABackend.Auth.Models.User.t()} | {:error, Ecto.Changeset.t()}
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_user(String.t()) :: POABackend.Auth.Models.User.t() | nil
Get a user from the database based in the user name
This function deletes the banned tokens which already expired
remove_user(POABackend.Auth.Models.User.t()) :: :ok
Deletes a user from the database based in the given user
Checks if a token is banned or not
user_active?(POABackend.Auth.Models.User.t()) :: Boolean.t()
Checks if a user is active
valid_token?(String.t()) :: Boolean.t() | {:error, :token_expired}
Validates if a JWT token is valid.
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