| | |
- builtins.object
-
- Authorization
- User
- UserManager
class Authorization(builtins.object) |
| |
Authorization(db)
|
| |
Methods defined here:
- __init__(self, db)
- Initializes a new instance of the class.
Attributes:
permissions (dict): A dictionary to store user permissions.
- add_permission(self, username, role)
- Adds a permission to a specified role.
Args:
role (str): The role to which the permission will be added.
permission (str): The permission to be added to the role.
- check_permission(self, username, permission)
- Check if a user has a specific permission.
Args:
username (str): The username of the user.
role (str): The role to check for.
Returns:
bool: True if the user has the permission, False otherwise.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
|
class User(builtins.object) |
| |
User(username, password, roles=None)
|
| |
Methods defined here:
- __init__(self, username, password, roles=None)
- Initialize a new User instance.
Args:
username (str): The username of the user.
password (str): The password of the user.
roles (list, optional): A list of roles assigned to the user. Defaults to an empty list.
Attributes:
username (str): The username of the user.
password_hash (str): The hashed password of the user.
roles (list): A list of roles assigned to the user.
- check_password(self, password)
- Check if the provided password matches the stored password hash.
Args:
password (str): The plaintext password to check.
Returns:
bool: True if the password matches the stored hash, False otherwise.
Static methods defined here:
- hash_password(password)
- Hashes a password using bcrypt.
Args:
password (str): The password to be hashed.
Returns:
bytes: The hashed password.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
|
class UserManager(builtins.object) |
| |
UserManager(db)
|
| |
Methods defined here:
- __init__(self, db)
- Initializes the Users class.
Args:
db (Database): The database object to use for user management.
- authenticate_user(self, username, password)
- Authenticate a user by their username and password.
Args:
username (str): The username of the user.
password (str): The password of the user.
Returns:
User: The authenticated user object if the username and password are correct.
None: If the authentication fails.
- get_user_permissions(self, username)
- Get the permissions associated with a user.
Args:
username (str): The username of the user.
Returns:
list: A list of permissions associated with the user.
- login_user(self, username, password)
- Logs in a user by their username and password.
Args:
username (str): The username of the user.
password (str): The password of the user.
Returns:
str: A session token if login is successful.
None: If the login fails.
- logout_user(self, session_token)
- Logs out a user by their session token.
Args:
session_token (str): The session token of the user.
- register_user(self, username, password, roles=None)
- Registers a new user with the given username, password, and optional roles.
Args:
username (str): The username for the new user.
password (str): The password for the new user.
roles (list, optional): A list of roles assigned to the new user. Defaults to None.
Raises:
ValueError: If the username already exists in the users dictionary.
- remove_user(self, username)
- Removes a user from the database.
Args:
username (str): The username of the user to be removed.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |