models.user package

Submodules

models.user.decorators module

This module contains decorator functions used as middleware in the Flask application.

models.user.decorators.requires_admin(f: Callable) → Union[Callable, werkzeug.wrappers.response.Response][source]

Returns the passed function only if the Admin is the logged in user.

Parameters

f (Callable) – The function to be returned.

Returns

The function returned.

Return type

Union[Callable, Response]

models.user.decorators.requires_login(f: Callable) → Union[Callable, werkzeug.wrappers.response.Response][source]

Returns the passed function only if login is verified.

Parameters

f (Callable) – The function to be returned.

Returns

The function returned.

Return type

Union[Callable, Response]

models.user.errors module

This module contains User Errors

exception models.user.errors.IncorrectPasswordError(message)[source]

Bases: models.user.errors.UserError

Class raised when an incorrect User password is provided.

exception models.user.errors.InvalidEmailError(message)[source]

Bases: models.user.errors.UserError

Class raised when an email is invalid.

exception models.user.errors.UserAlreadyRegisteredError(message)[source]

Bases: models.user.errors.UserError

Class raised when a User is already registered.

exception models.user.errors.UserError(message)[source]

Bases: Exception

Class that represents a generic User Error.

exception models.user.errors.UserNotFoundError(message)[source]

Bases: models.user.errors.UserError

Class raised when a User is not found.

models.user.user module

This module contains the User Model class.

models.user.user.logger

The logger used to log information of module.

Type

logging.Logger

class models.user.user.User(email: str, password: str, _id: InitVar[Union[str, ObjectId]] = None)[source]

Bases: models.model.Model

Class that models a User.

collection

The database collection name for the class.

Type

str

email

The user email.

Type

str

password

The user email.

Type

str

_id

The user id.

Type

InitVar[Union[str, ObjectId]]

collection: str = 'users'
email: str
classmethod find_by_email(email: str)models.user.user.User[source]

Finds a User by email.

Parameters

email (str) – The email to query by.

Returns

The User corresponding to the query.

Return type

User

Raises

UserErrors.UserNotFoundError – If the User was not found.

classmethod is_login_valid(email: str, password: str)bool[source]

Verifies the email and password provided for a User.

Parameters
  • email (str) – The email to be verified.

  • password (str) – The password to be verified.

Returns

True if the email and password is valid, False otherwise.

Return type

bool

Raises

UserErrors.IncorrectPasswordError – If an incorrect password was provided.

json()dict[source]

Returns the json representation of the User.

Returns

The json representation of the User.

Return type

str

password: str
classmethod register_user(email: str, password: str)bool[source]

Registers a User.

Parameters
  • email (str) – The email to register with.

  • password (str) – The password to register with.

Returns

True if User was successfully registered, False otherwise.

Return type

bool

Raises
  • UserErrors.InvalidEmailError – If an invalid email was provided.

  • UserErrors.UserAlreadyRegisteredError – If the User has already been registered.

  • UserErrors.UserNotFoundError – If the User was not found.

Module contents