user
EnUser
¶
Bases: SQLModel
Represents a user entity with various attributes and validation mechanisms for the user-related data fields.
This class is primarily used to model user information and enforce constraints on attributes such as username, password, email, and names. It includes mechanisms to handle secure storage and validation of sensitive data like passwords and email addresses. Additionally, methods are provided for verifying passwords and extracting specific token-relevant user data.
Attributes:
Name | Type | Description |
---|---|---|
username |
str
|
The unique username for the user. |
firstname |
str | None
|
The optional first name of the user. |
lastname |
str | None
|
The optional last name of the user. |
password |
str
|
The hashed password for the user. |
mail |
str
|
The valid email address associated with the user. |
Source code in backend/app/user/model.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
is_good_password(value)
classmethod
¶
Validates the strength of a password after it has been assigned or modified. The method ensures that the password meets specific security requirements, such as minimum and maximum length, uppercase and lowercase characters, numeric characters, and the inclusion of special symbols.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The password string to be validated. |
required |
Returns:
Type | Description |
---|---|
str
|
The original password string if it meets all validation criteria. |
Raises:
Type | Description |
---|---|
HTTPException
|
If the password fails any validation check, such as length, lack of uppercase letters, lowercase letters, digits, or special characters. |
Source code in backend/app/user/model.py
is_mail_address(value)
classmethod
¶
Validates and ensures the provided email address is in a valid format. This function checks whether the given string contains the '@' symbol, indicating it is properly structured as an email address. If the validation fails, an HTTPException is raised with an appropriate status code and detail message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The email address to be validated. |
required |
Returns:
Type | Description |
---|---|
str
|
The validated email address if it is valid. |
Raises:
Type | Description |
---|---|
HTTPException
|
If the email address does not contain the '@' symbol. |
Source code in backend/app/user/model.py
EnUserDB
¶
Bases: EnUser
Represents a database model for storing user information.
This class inherits from EnUser
and serves as a database table
for user-related data. It defines the structure of the users
table, including various user attributes like ID, date of joining,
last login, and flags for active status, superuser, and staff roles.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
The unique identifier for each user. |
date_joined |
datetime | None
|
The datetime when the user registered. Defaults to None. |
last_login |
datetime | None
|
The last login datetime for the user. Defaults to None. |
is_active |
bool
|
Whether the user account is active. Defaults to False. |
is_superuser |
bool
|
Whether the user has superuser privileges. Defaults to False. |
is_staff |
bool
|
Whether the user is part of the staff. Defaults to False. |
Source code in backend/app/user/model.py
EnUserUpdate
¶
Bases: EnUser
Represents an update to an EnUser.
This class serves as a model for updating an existing user's details in the
system. It extends the EnUser
class, inheriting its attributes and adding
optional fields specific to updating a user's information. Each attribute can
be set to None if the corresponding field is not being updated.
Attributes:
Name | Type | Description |
---|---|---|
username |
str | None
|
Optional updated username for the user. |
firstname |
str | None
|
Optional updated first name for the user. |
lastname |
str | None
|
Optional updated last name for the user. |
password |
str | None
|
Optional updated password for the user. |
mail |
str | None
|
Optional updated email address for the user. |