def get_locale(): if "LANGUAGES" not in app.config: return "en" if user_utils.isUserLoginEnabled( ) and current_user.is_authenticated and current_user.lang in list( app.config["LANGUAGES"].keys()): return current_user.lang if current_user.lang != None else "en" elif 'lang' in session and session['lang'] in list( app.config["LANGUAGES"].keys()): return session['lang'] else: result = request.accept_languages.best_match( list(app.config["LANGUAGES"].keys())) return result if result != None else "en"
from flask_dance.consumer.storage.sqla import SQLAlchemyStorage from flask_dance.contrib.google import make_google_blueprint, google from flask_babel import _ from sqlalchemy.orm.exc import NoResultFound auth_blueprint = Blueprint('auth', __name__, template_folder='templates') if app.config['OAUTHLIB_INSECURE_TRANSPORT']: os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' login_manager.login_view = 'google.login' login_manager.login_message = '' @auth_blueprint.route('/logout') @utils.condec(login_required, user_utils.isUserLoginEnabled()) def logout(): logout_user() return redirect(url_for('index')) google_blueprint = make_google_blueprint(scope=[ "openid", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" ]) if user_utils.isUserLoginEnabled(): app.register_blueprint(google_blueprint, url_prefix='/auth') google_blueprint.storage = SQLAlchemyStorage(OAuth, db.session, user=current_user)
from flask import render_template, url_for, redirect from flask_login import current_user from app import app, login_manager, flash, db from app.utils import utils, user_utils, lang_utils from app.config import Config from .models import User app.jinja_env.globals.update( **{ "get_locale": lang_utils.get_locale, "user_login_enabled": user_utils.isUserLoginEnabled(), "get_user": user_utils.get_user, "is_admin": user_utils.is_admin, "is_expert": user_utils.is_expert, "is_normal": user_utils.is_normal, "get_uid": user_utils.get_uid, "int": int, "Flash": flash.Flash, "len": len, "infix": app.config['INFIX'], "ADMIN_EMAIL": app.config['ADMIN_EMAIL'] }) @app.route('/') @app.route('/index') def index(): if current_user.is_authenticated: return redirect(url_for('library.library_corpora')) else: return render_template('index.html.jinja2')