Пример #1
0
def before_request():
    ignore_urls = app.config['IGNORE_URLS']
    ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS']
    path = request.path

    # 如果是静态文件就不要查询用户信息了
    pattern = re.compile('%s' % "|".join(ignore_check_login_urls))
    if pattern.match(path):
        return

    if '/api' in path:
        return

    user_info = check_login()
    g.current_user = None
    if user_info:
        g.current_user = user_info

    # 加入日志
    LogService.add_access_log()
    pattern = re.compile('%s' % "|".join(ignore_urls))
    if pattern.match(path):
        return

    if not user_info:
        return redirect(UrlManager.build_url("/user/login"))

    return
Пример #2
0
def before_request():
    ignore_urls = app.config['IGNORE_URLS']
    ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS']
    path = request.path
    # 如果是静态文件就不用查询用户信息
    pattern = re.compile('|'.join(ignore_check_login_urls))
    if pattern.match(path):
        return
    user_info = check_login()

    # 登录成功之后设置一个user_info对象全局变量
    g.current_user = None
    if user_info:
        g.current_user = user_info
    # 登录之后url加入日志
    LogService.add_access_log()
    pattern = re.compile('%s' % "|".join(ignore_urls))
    if pattern.match(path):
        return
    if not user_info:
        return redirect(UrlManager.buildUrl('/user/login'))
    return