コード例 #1
0
app.csrf = CsrfProtect(app)

# Use the custom CSRF token generation.
app.jinja_env.globals["csrf_token_r"] = generate_csrf_token

# Add the custom regular expression converter.
app.url_map.converters["regex"] = RegexConverter

# Initialize the app routes, config and other necessary stuff.
# The app context here is needed since we are using variables defined in the
# config files and we need to access them.
with app.app_context():
    import dashboard.utils.backend as backend
    import dashboard.utils.route as route

    route.init()


def handle_ajax_get(req, endpoint, timeout=None):
    if validate_csrf(req.headers.get(CSRF_TOKEN_H, None)):
        return backend.ajax_get(req, endpoint, timeout=timeout)
    else:
        abort(403)


@app.context_processor
def inject_variables():
    """Inject some often used variables."""
    return dict(analytics=app_conf_get("GOOGLE_ANALYTICS_ID"),
                is_mobile=backend.is_mobile_browser(request),
                is_old_browser=backend.is_old_browser(request),
コード例 #2
0
ファイル: __init__.py プロジェクト: joyxu/kernelci-frontend
app_conf_get = app.config.get

app.cache = Cache(app)
app.csrf = CsrfProtect(app)

# Use the custom CSRF token generation.
app.jinja_env.globals["csrf_token_r"] = generate_csrf_token

# Initialize the app routes, config and other necessary stuff.
# The app context here is needed since we are using variables defined in the
# config files and we need to access them.
with app.app_context():
    import utils.backend as backend
    import dashboard.utils.route as route

    route.init()


@app.context_processor
def inject_variables():
    return dict(
        analytics=app_conf_get("GOOGLE_ANALYTICS_ID"),
        is_mobile=backend.is_mobile_browser(request),
        is_old_browser=backend.is_old_browser(request),
        server_date=backend.today_date(),
        front_version=__version__,
        info_email=app_conf_get("INFO_EMAIL", "*****@*****.**")
    )


@app.errorhandler(404)