*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit e2fb0983 authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Add custom logic for login

* if local login is disabled and there is only one OAuth2 remote app
  defined, we redirect straight to that remote app's login page
parent 72181f10
Branches
Tags
No related merge requests found
......@@ -10,6 +10,7 @@
from flask_menu import current_menu
from . import config
from .views import auto_redirect_login
class InvenioConfigTUW(object):
......@@ -31,6 +32,10 @@ class InvenioConfigTUW(object):
# but hiding the menu entry doesn't hurt
current_menu.submenu("main.communities").hide()
if "security.login" in app.view_functions:
# override the default login view function with our smart logic
app.view_functions["security.login"] = auto_redirect_login
def init_config(self, app):
"""Initialize configuration."""
# Use theme's base template if theme is installed
......
......@@ -5,10 +5,28 @@
# Invenio-Config-TUW is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
from flask import Blueprint
from flask import Blueprint, current_app, redirect, url_for
from flask_security.views import anonymous_user_required, login
from invenio_oauthclient.proxies import current_oauthclient
blueprint = Blueprint(
"invenio_config_tuw",
__name__,
template_folder="templates",
)
@anonymous_user_required
@blueprint.route("/login")
def auto_redirect_login():
"""View function for login view"""
local_login = current_app.config["THEME_TUW_LOCAL_LOGIN_ENABLED"]
remote_apps = current_oauthclient.oauth.remote_apps
if not local_login and len(remote_apps) == 1:
# if local login is disabled and we only have one OAuth2 remote app
# defined, we forward directly to that
remote_app = list(remote_apps.keys())[0]
return redirect(url_for("invenio_oauthclient.login", remote_app=remote_app))
else:
return login()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment