From 00b9c170f19c0819b43b15f6a63abb67ec84bd59 Mon Sep 17 00:00:00 2001 From: Michatec Date: Sat, 27 Sep 2025 21:12:45 +0200 Subject: [PATCH] Missing check oauth --- main.py | 12 +++++++++++- routes/discord.py | 5 +---- templates/login.html | 2 ++ templates/profile.html | 24 +++++++++++++----------- templates/register.html | 2 ++ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 7c73990..596ff60 100644 --- a/main.py +++ b/main.py @@ -52,7 +52,10 @@ if not os.path.exists('static/profile_pics'): os.makedirs('static/profile_pics') app.register_blueprint(admin_bp) -app.register_blueprint(discord_bp) +try: + app.register_blueprint(discord_bp) +except (NameError, ImportError, RuntimeError, LookupError): + pass app.register_blueprint(post_bp) app.register_blueprint(log_bp) app.register_blueprint(support_bp) @@ -103,6 +106,13 @@ babel.init_app(app, locale_selector=get_locale) def needs_admin_setup(): return db.session.query(User).filter_by(is_admin=True).count() == 0 +@app.context_processor +def inject_discord_available(): + try: + from routes.oauth import discord + except ImportError: + return dict(discord=None) + @app.context_processor def inject_user(): return dict(user=current_user if current_user.is_authenticated else None) diff --git a/routes/discord.py b/routes/discord.py index 362ad89..8d322df 100644 --- a/routes/discord.py +++ b/routes/discord.py @@ -6,12 +6,9 @@ from flask_babel import gettext as _ try: from routes.oauth import discord except ImportError: - discord = None + pass from routes.login import login_user -if discord is None: - abort("OAuth not configured. Please set up OAuth in routes/oauth.py") - discord_bp = Blueprint('discord', __name__) @discord_bp.route('/login/discord') diff --git a/templates/login.html b/templates/login.html index d3162f1..943e9c7 100644 --- a/templates/login.html +++ b/templates/login.html @@ -22,11 +22,13 @@ {{ _('Forgot password?') }} + {% if discord is not none %}
{{ _('Login with Discord') }}
+ {% endif %} diff --git a/templates/profile.html b/templates/profile.html index 98793b3..5bd0297 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -17,16 +17,18 @@
-{% if not user.discord_linked %} - - {{ _('Link Discord Account') }} - -{% else %} - {{ _('Discord Linked') }} -
- -
+{% if discord is not none %} + {% if not user.discord_linked %} + + {{ _('Link Discord Account') }} + + {% else %} + {{ _('Discord Linked') }} +
+ +
+ {% endif %} {% endif %} {% endblock %} \ No newline at end of file diff --git a/templates/register.html b/templates/register.html index b33da65..66f227b 100644 --- a/templates/register.html +++ b/templates/register.html @@ -29,11 +29,13 @@ {{ _('Already have an account?') }} {{ _('Login') }} + {% if discord is not none %}
{{ _('Login with Discord') }}
+ {% endif %}