Web package

Module Contents

This section contains detailed documentation of the web package, this package contains the flask app which is the central hub for connecting the back end to the front end of the prototype.

web.app module

web.app.api_check_recommendation()

API endpoint to handle recommendation check requests for a user to avoid calculating recommendations again.

  • Checks if the user is authenticated (user_id in session).

  • If not authenticated, returns a 401 Unauthorized error.

  • Parses request data (JSON) which contains user interactions.

  • Calls api_check_recommendations to fetch recommendations.

Returns:

  • JSON: Response containing a list of recommendations containg dicts or an error message.

web.app.api_matches()

API endpoint to fetch match recommendations for the authenticated user.

Returns:

  • JSON: Response containing a list of matches for the authenticated user.

  • Redirects to the login page if the user is not authenticated.

Verifies if the user is authenticated. Calls get_matches to retrieve the user’s match recommendations from the database. Returns a JSON response containing the user’s match recommendations.

web.app.api_recommendation()

API endpoint to handle recommendation requests for a user.

  • Checks if the user is authenticated (user_id in session).

  • If not authenticated, returns a 401 Unauthorized error.

  • Parses request data (JSON) which contains user interactions.

  • Calls api_recommendations to process the data and fetch recommendations.

Returns:

  • JSON: Response containing a list of recommendations containg dicts or an error message.

web.app.create_account()

Route to render the account creation page.

Returns:

  • Rendered HTML: The signup page for new users.

Checks if the user’s Firebase UID is in the session and redirects to the login page if not. Redirects to recommendations if the user has already signed up. Renders the account creation page if the user has not signed up.

web.app.delete_account()

Endpoint for deleting the authenticated user’s account.

Returns:

  • Redirect: To the account creation page after account deletion.

  • If not authenticated, redirects to the login page.

Verifies if the user is authenticated. Calls account_deletion to remove the user’s data from the database. Clears the session and redirects to the account creation page upon successful deletion.

web.app.edit_profile()

Route to render the profile editing page for the authenticated user.

Returns:

  • Rendered HTML: The profile editing page populated with the current user’s data.

Checks if the user is authenticated and redirects to the login page if not. Retrieves the current user’s data from the database (using “get_user_data”). Renders the profile editing template with the retrieved user data.

web.app.handle_add_user()

Flask route handler to add a new user to the system.

This route handler extracts the Firebase UID from the session, adds new user data to the database, and redirects to the recommendations page with the new user’s ID on successful addition. It returns an error message with HTTP status 500 upon failure.

  • Extracts Firebase UID from session.

  • If UID is not found, redirects to the login page.

  • Calls add_user to insert new user data into the database.

  • Redirects to recommendations page with the new user’s ID on successful addition.

  • On exception, returns an error message with HTTP status 500.

Returns:

  • On success: Redirect to the recommendations page for the new user.

  • On failure: Error message with status code 500.

web.app.image(requested_id)

Serves a pre-signed URL for an image stored in S3, allowing for secure, temporary access to the image.

This endpoint checks if the user requesting the image is authenticated by verifying the presence of ‘user_id’ in the session. If the user is authenticated, it generates a pre-signed URL for the requested image from an S3 bucket, which is valid for a limited time. The client is then redirected to this pre-signed URL to directly access the image.

Args:

  • requested_id (str): The ID of the user who’s profile picture has been requested for viewing, used to construct the object name in the S3 bucket.

Returns:

  • A redirect to the pre-signed URL of the image if the user is authenticated and authorized.

  • A JSON response with an ‘Unauthorized’ error message and a 401 status code if the user is not authenticated.

web.app.index()

Flask route to render the login page.

Returns:

  • Rendered HTML: The ‘login.html’ template, serving as the application’s login page.

This is the default route for the web application, which renders the login page. It acts as the entry point for users accessing the site.

web.app.login()

Route to render the login page.

Renders and returns the login template.

Returns:

  • Rendered HTML: The login page of the application.

web.app.logout()

Route to handle user logout.

Returns:

  • Redirect: To the login page.

Clears the user session to log out the user. Redirects to the login page after logout.

web.app.record_interactions()

Endpoint for recording user interactions with recommendations in the system.

Returns:

  • JSON response indicating the status of the interaction recording.

  • If the user is not authenticated, returns a 401 Unauthorized error.

Verifies if the user is authenticated by checking the session. Parses the JSON data from the POST request, which includes interaction details (user ids, like, dislike, etc.). Calls the record_interaction function to update the database with these interactions.

web.app.remove_match()

Endpoint to remove a match from the user’s list.

Returns:

  • JSON: Response indicating the status of the match removal.

Checks if the user is authenticated. Processes the removal request and updates the database to reflect the match removal by calling “remove_matches”. Returns a JSON response indicating the result of the removal process.

web.app.report()

Endpoint for users to report other users or interactions.

Returns:

  • JSON: Response indicating the status of the report submission.

Verifies if the user is authenticated. Processes the report details from the POST request. Calls record_report to log the report in the database. Returns a JSON response indicating the result of the report process.

web.app.report_match()

Endpoint for users to report matches.

Returns:

  • JSON: Response indicating the status of the match report submission.

Similar to /report, but specifically handles reporting of matches. Verifies authentication, processes the report, and logs it in the database.

web.app.show_matches()

Route to display match recommendations for the authenticated user.

Returns:

  • Rendered HTML: Match recommendations page for the authenticated user.

  • Redirects to the login page if the user is not authenticated.

Verifies if the user is logged in and has a valid session. Renders the matches template for the logged-in user.

web.app.show_recommendations()

Route to display recommendations for the authenticated user.

Returns:

  • Rendered HTML: Recommendations page for the authenticated user.

  • Redirects to the login page if the user is not authenticated.

Verifies if the user is logged in and has a valid session. Renders the recommendations template for the logged-in user.

web.app.update_user()

Endpoint for updating the user’s profile information.

Returns:

  • Redirect: To the user’s recommendations page after the profile is updated.

Calls update_user_data to process the form data submitted by the user and update their profile in the database. Redirects the user to the recommendations page upon successful update.

web.app.verify_token()

Endpoint to verify the Firebase token for user authentication.

Returns:

  • JSON: Response with success status and redirection URL.

Parses the ID token from the POST request. Verifies the token using Firebase authentication. Updates the session with the Firebase UID and checks if the user exists in the database. Redirects the user based on their authentication status.

See Also

Note

For a complete overview of all modules, visit the modules overview page.