Exemplo n.º 1
0
def error_exception( e ):
    err_msg = getErrMsg()
    AppLogService.addErrLog( err_msg )
    if UtilHelper.isAjax():
        return UtilHelper.renderErrJSON( "系统错误,错误原因:%s<br/>%s"%( str( e.__class__).replace("<",""),str( e ) ) )

    return UtilHelper.renderView("home/error/error.html", {"status": 500, "msg": err_msg })
Exemplo n.º 2
0
def before_request():
    ignore_urls  = app.config['IGNORE_URLS_HOME']
    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 ) or "/home" not in path:
        return

    # 多查询一次数据也没有什么问题
    user_info = check_login()
    g.current_user = None
    if user_info:
        g.current_user = user_info

    #将忽略数组换成字符串
    pattern = re.compile('%s' % "|".join( ignore_urls ) )
    if pattern.match( path ):
        return

    if not user_info :
        response = make_response( redirect(GlobalUrlService.buildHomeUrl("/user/logout")))
        return response

    #判断RBAC的权限
    if not RBACService.checkPrivilege( path ):
        if UtilHelper.isAjax():
            return UtilHelper.renderErrJSON("无权限,请联系管理员" )
        response = make_response(redirect( GlobalUrlService.buildHomeUrl("/error/ban",{ "msg" : path }) ))
        return response

    g.menus = MenuService.getMenu()
    AppLogService.addAccessLog( user_info )
    return