Exemple #1
0
def before_request():
    # 当用户未登录时,在列表中的请求将被重定向到登录界面
    filter_list = [
        "/", "/commodity/add", "/commodity/del", "/commodity/buy",
        "/commodity/send", "/commodity/trans", "/commodity/warehouse",
        "/commodity/distribution", "/commodity/sale"
    ]
    app.logger.info("--------before_request:%s--------" % (request.path))

    user_info = check_login()
    g.current_user = None
    app.logger.info("user_info:%s" % user_info)
    if user_info:
        g.current_user = user_info
        app.logger.info("current_user:%s" % g.current_user)
    if g.current_user is None:
        # 用户未登录
        app.logger.info("current_user is null,进行重定向")
        if request.path in filter_list:
            # 拦截普通请求
            response = make_response(
                redirect(UrlManager.build_url("/member/login")))
            response.delete_cookie(app.config["AUTH_COOKIE_NAME"])
            return response

    return
def logout():
    response = make_response(redirect(UrlManager.build_url("/member/login")))
    response.delete_cookie(app.config["AUTH_COOKIE_NAME"])
    return response