maeser.controllers.login_api module#

Module for handling login and GitHub OAuth2 authorization controllers.

maeser.controllers.login_api.github_auth_callback_controller(current_user: User, auth_manager: UserManager, login_redirect: str = 'maeser.login') flask.Response[source]#

Redirects the user after authentication is complete. Handles cases where authentication is unsuccessful.

Redirects the user back to the login page if authentication fails or the home page if authentication is successful.

Parameters:
  • current_user (User) – The user being authenticated.

  • auth_manager (UserManager) – The user manager for the Maeser application.

  • login_redirect (str, optional) – The URL to redirect to if authentication fails. Defaults to ‘maeser.login’.

Returns:

The corresponding URL to redirect to.

Return type:

Response

maeser.controllers.login_api.github_authorize_controller(current_user: User, github_authenticator: GithubAuthenticator) flask.Response[source]#

Handles GitHub OAuth2 authorization.

Updates ‘oauth2_state’ in the Flask session and redirects the user to the GitHub authorization url.

Parameters:
  • current_user (User) – The currently logged-in user.

  • github_authenticator (GitHubAuthenticator) – The GitHub authenticator to get OAuth2 info.

Returns:

The response object to redirect to the OAuth2 provider.

Return type:

Response

maeser.controllers.login_api.is_safe_url(target: str) bool[source]#

Checks if a URL is safe for redirection.

Parameters:

target (str) – The target URL to check.

Returns:

True if the URL is safe, False otherwise.

Return type:

bool

maeser.controllers.login_api.login_controller(auth_manager: UserManager, app_name: str | None = None, main_logo_login: str | None = None, main_logo_chat: str | None = None, favicon: str | None = None) flask.Response | str[source]#

Handles user login.

Parameters:
  • auth_manager (UserManager) – The authentication manager to handle user authentication.

  • app_name (str | None) – The display name of the Maeser application. This will be populated into the page’s title element. Defaults to None.

  • main_logo_login (str | None) – The main logo to display on the login page. Defaults to None, in which case it will use maeser/data/static/maeser.png.

  • main_logo_chat (str | None) – Currently unused. This logo would populate into the page header, but the login page currently does not have a page header. This may change in the future.

  • favicon (str | None) – The favicon for the page. Defaults to None, in which case it will use maeser/data/static/maeser.png.

Returns:

A redirect to home if the user is authenticated, or the rendered login page if the user is not authenticated.

Return type:

Response | str