Skip to content

Users Models

Models for managing user authentication, authorization, and roles.

class automation.dbmodels.users.Users(*args, **kwargs)

Database model for Users.

create(user)

Creates a new User record.

Parameters:

  • user (User): An instance of the User class from the users module.

Returns:

  • tuple: (Query object, status message)
login(password, username='', email='')

Authenticates a user and updates their session token.

Parameters:

  • password (str): User password.
  • username (str, optional): Username.
  • email (str, optional): Email.

Returns:

  • tuple: (User record, status message)
logout(token)

Logs out a user by invalidating their token.

Parameters:

  • token (str): Session token.
update_password(username, new_password)

Updates a user's password.

Parameters:

  • username (str): Username of the user whose password will be updated.
  • new_password (str): New plain text password to set.

Returns:

  • tuple: (User record, status message)
read_by_username(username)

Retrieves a user by username.

read_by_name(name)

Retrieves a user by name (first name).

name_exist(name)

Checks if a user name exists.

username_exist(username)

Checks if a username exists.

email_exist(email)

Checks if an email exists.

identifier_exist(identifier)

Checks if an identifier exists.

encode(value)

Hashes a value (e.g., password).

decode_password(self, password)

Verifies a password against the stored hash.

decode_token(self, token)

Verifies a token against the stored hash.

fill_cvt_users()

Loads users from the database into the in-memory User Manager (CVT).

serialize(self)

Serializes the user record.

class automation.dbmodels.users.Roles(*args, **kwargs)

Database model for User Roles.

create(name, level, identifier)

Creates a new Role record.

Parameters:

  • name (str): Role name.
  • level (int): Permission level (0 is highest).
  • identifier (str): Unique ID.

Returns:

  • tuple: (Query object, status message)
read_by_name(name)

Retrieves a role by name.

read_by_identifier(identifier)

Retrieves a role by identifier.

name_exist(name)

Checks if a role name exists.

identifier_exist(identifier)

Checks if a role identifier exists.

read_names()

Returns a list of all role names.

fill_cvt_roles()

Loads roles from the database into the in-memory Role Manager (CVT).

serialize(self)

Serializes the role record.