Coverage for seedboxsync/front/views/settings/authentication.py: 86%
22 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-26 17:14 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-26 17:14 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""SeedboxSync Flask view for settings authentication."""
9from flask import render_template
10from seedboxsync.core import current_app
11from seedboxsync.front.babel import gettext as _
12from seedboxsync.front.forms import SettingsAuthenticationForm
13from seedboxsync.front.login_manager import login_required
14from seedboxsync.front.oauth2 import init_oauth2
15from seedboxsync.front.utils import save_settings_form, toast
16from seedboxsync.front.views import bp_settings as bp
19@bp.route("/authentication", methods=("GET", "POST"))
20@login_required # type: ignore[untyped-decorator]
21def authentication() -> str:
22 """
23 Render and process the authentication configuration form.
25 Manages access control and authentication provider settings.
27 Returns:
28 str: Rendered HTML template for the authentication settings page.
29 """
30 form = SettingsAuthenticationForm(data=current_app.seedboxsync_config)
32 current_app.logger.info(current_app.seedboxsync_config)
33 if form.validate_on_submit():
34 try:
35 save_settings_form(form)
36 init_oauth2(current_app)
37 toast(_("Configuration saved successfully."), _("Authentication"), "success")
38 except Exception as e:
39 current_app.logger.exception("Failed to save configuration.", exc_info=e)
40 toast(_("Failed to save configuration."), _("Authentication"), "danger")
42 return render_template("settings/authentication.html", form=form)