user
delete_user(token, db=Depends(get_db_session))
async
¶
Deletes a user based on the credentials and token provided. The function retrieves the user's data from the database using the information decoded from the token. If the user does not exist, an HTTP exception is raised. If the user exists, the function proceeds to delete the user from the database and commits the transaction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
An access token for the user requesting deletion. |
required |
db
|
Session
|
A SQLAlchemy session dependency for interacting with the database. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
MessageResponse
|
A |
Raises:
Type | Description |
---|---|
HTTPException
|
If the user is not found, with status code 404. |
Source code in backend/app/user/router.py
update_user(token, user, db=Depends(get_db_session))
async
¶
Updates the user information in the database based on the provided token and user data. The token is used to authenticate and retrieve the corresponding user. The user details in the database are updated with the provided data, and the updated information is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
The authentication token identifying the user to be updated. |
required |
user
|
EnUserUpdate
|
The updated details of the user. |
required |
db
|
Session
|
The database session used for executing queries. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
DataResponse
|
Response containing the updated user details in a data response format. |
Source code in backend/app/user/router.py
user_login(username=Form(...), password=Form(...), db=Depends(get_db_session))
async
¶
Authenticates a user and generates an access token upon successful login.
This function allows the user to log into the system by providing the correct credentials. Upon successful authentication, an access token is generated and returned with additional details. If the credentials are invalid or the user does not exist, appropriate exceptions are raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username
|
str
|
The username of the user attempting to log in. |
Form(...)
|
password
|
str
|
The password associated with the username. |
Form(...)
|
db
|
Session
|
The database session dependency that allows for database queries. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
JSONResponse
|
A JSON response containing a success message, an access token, and the token type if authentication is successful. |
Raises:
Type | Description |
---|---|
HTTPException
|
Raised with status code 404 if the user does not exist, or with status code 401 if the password is incorrect. |
Source code in backend/app/user/router.py
user_read(token, db=Depends(get_db_session))
async
¶
Handles a GET API endpoint to read user information from the database.
This function authenticates the request using the provided token and retrieves the corresponding user data from the database. If the token is invalid or the user is not found, appropriate HTTP exceptions are raised. On successful retrieval, it returns the user data wrapped in a response model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
A token string obtained through user authentication. |
required |
db
|
Session
|
The database session used for querying user data. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
DataResponse
|
A DataResponse instance containing user information if authentication and retrieval are successful. |
Source code in backend/app/user/router.py
user_register(user, db=Depends(get_db_session))
async
¶
Registers a new user in the system. The function verifies whether the username and email provided by the user are unique before proceeding with the creation of a new user record. If the username or email is already in use, an exception is raised with the appropriate error details. A successful registration results in the creation of a persisted user entity in the database. Passwords are securely hashed before storage to ensure data protection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
EnUser
|
An instance of EnUser containing the user's registration details, including username, email, and password. Type: EnUser |
required |
db
|
Session
|
Dependency-injected database session to interact with the database. Type: Session |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
MessageResponse
|
A response model indicating the success of the operation. Returns a MessageResponse object on success. |
Raises:
Type | Description |
---|---|
HTTPException
|
|