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.addAccessLog() pattern = re.compile("%s" % "|".join(ignore_urls)) if pattern.match(path): return if not user_info: return redirect(UrlManager.buildUrl("/user/login")) return
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() if not user_info : return redirect( UrlManager.buildUrl( "/SignIn" ) ) g.current_user = None if user_info: g.current_user = user_info #加入日志 LogService.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return return
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: # 对于api 请求 不处理。 转由api拦截器处理。 return user_info = check_login() g.current_user = None if user_info: g.current_user = user_info # app.logger.info(g.current_exam) # 加入访问记录日志 LogService.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return if not user_info: # 如果没有登录,就去登 return redirect(UrlManager.buildUrl("/user/login")) if not session.get("examid"): # 如果没有选择考试,就去选 return redirect(UrlManager.buildUrl("/exam/choose"))
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.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) # login页面无重定向 if pattern.match(path): return if not user_info: return redirect(UrlManager.build_url('/user/login')) return
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 # 请求里有api,不进行该拦截器处理 if "/api" in path: return user_info = check_login() g.current_user = None if user_info: g.current_user = user_info # 加入日志 LogService.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): # 则为登录页面不需跳转 return if not user_info: return redirect(UrlManager.buildUrl("/user/login")) return
def before_request(): # 不需要验证登录的url ignore_urls = app.config['IGNORE_URLS'] ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS'] path = request.path # 得到请求的url # 如果是静态文件就不要查询用户信息了 pattern = re.compile( '%s' % "|".join(ignore_check_login_urls)) # 正则表达式提取url,如果在配置忽略过滤中就直接返回 if pattern.match(path): return if '/api' in path: return user_info = check_login() # 检查是否登录,在下面定义了 g.current_user = None # flask的g变量用于记录用户登录标识(临时的) if user_info: g.current_user = user_info # 用户已经登录,改变为用户id # 加入日志。这里的逻辑说明是管理员了,就要把每一次需要权限的操作记录保存 LogService.addAccessLog() # 如果是规定的忽略url(如api)就不要拦截 pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return if not user_info: return redirect(UrlManager.buildUrl("/user/login")) return
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): # app.logger.info('这是静态文件和图标过滤' + path) return if '/api' in path: return # 判断是否已经登录 user_info = check_login() g.current_user = None if user_info: g.current_user = user_info # 加入日志 LogService.addAccessLog() pattern = re.compile('%s' % '|'.join(ignore_urls)) if pattern.match(path): # app.logger.info('这是登录过滤' + path) return if not user_info: return redirect(UrlManager.buildUrl('/user/login')) return
def before_request(): ignore_urls = app.config["IGNORE_URLS"] ignore_check_login_urls = app.config["IGNORE_CHECK_LOGIN_URLS"] path = request.path # 如果有/api路径则不进行判断, 以便将后端的登录和前端的登录进行分离 if "/api" in path: return # 判断是否是静态页面请求 pattern = re.compile("%s" % "|".join(ignore_check_login_urls)) if pattern.match(path): return user_info = check_login() g.current_user = None if user_info: g.current_user = user_info # 加入日志 LogService.addAccessLog() # 判断是否是登录页面请求, 不需要重定向 pattern = re.compile("%s" % "|".join(ignore_urls)) if pattern.match(path): return # 重定向到login界面 if not user_info: return redirect(UrlManager.buildUrl("/user/login")) return
def before_request(): # 对不需要验证的路径 进行正则处理 其他页面如果用户没登录 则跳转到登录页面 ignore_urls = app.config['IGNORE_URLS'] ignore_check_urls = app.config['IGNORE_CHECK_URLS'] pattern = re.compile('%s' % "|".join(ignore_check_urls)) # 验证用户是否登录 user_info = check_login() if user_info: g.current_user = user_info path = request.path if pattern.match(path): return if '/api' in path: return # 加入日志记录 LogService.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return # if not user_info: return redirect(UrlManager.buildUrl('/user/login')) return
def before_request(): ignore_urls = app.config['IGNORE_URLS'] ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS'] path = request.path # 检查是否是需要登录的url pattern = re.compile("%s" % "|".join(ignore_check_login_urls)) if pattern.match(path): return # 检查是否是登录页面的url pattern = re.compile("%s" % "|".join(ignore_urls)) if pattern.match(path): return # 判断用户是否已登录 user_info = check_login() g.current_user = None if user_info: g.current_user = user_info if not user_info: return redirect(UrlManager.buildUrl("/user/login")) # 加入日志 LogService.addAccessLog() return
def before_request(): # 请求之前的方法 """ 功能:在每一个请求到底controller方法之前,都被这个方法拦截。 思想:如果是请求登陆后的展示页面,通过 刚才设置的 cookie来验证。 """ ignore_urls = app.config['IGNORE_URLS'] ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS'] path = request.path # 当前页面 url 地址 # 通过正则表达式来判断 pattern = re.compile('%s' % "|".join(ignore_check_login_urls)) # 如果当前路径有这个,则不拦截 if pattern.match(path): return if "/api" in path: # 如果请求的地址有 api,就不进行拦截。拦截主要是针对后端admin return user_info = check_login() # 调用下面check_login()的方法 g.current_user = None if user_info: # 如果已经登录,就有 user_info g.current_user = user_info # g.current_user,就是当前用户信息 ## 拦截处理,加入日志(访问记录) LogService.addAccessLog() # 这里不需要任何参数,自定义的方法里面可以通过方式自己获取 pattern = re.compile('%s' % "|".join(ignore_urls)) # 如果是登录页面,则不拦截 if pattern.match(path): return if not user_info: # 如果没有 user_info,则重新登录 return redirect(UrlManager.buildUrl("/user/login")) return
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 # 如果是API接口,不需要进行认证 if '/api' in path: return # 检查用户是否已经登录,如果登录则返回对应的用户信息 user_info = check_login() # 将用户信息赋值给g.current_user g.current_user = None if user_info: g.current_user = user_info # 加入用户访问日志 LogService.addAccessLog() # 如果是登录页面,也不需要授权校验 pattern = re.compile('%s' % '|'.join(ignore_urls)) if pattern.match(path): return if not user_info: return redirect(UrlManager.buildUrl('/user/login')) return
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 user_info = check_login() g.current_user = None if user_info: g.current_user = user_info LogService.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return if not user_info: return redirect(UrlManager.buildUrl('/user/login')) return
def before_request(): path = request.path ignore_urls = app.config['IGNORE_URLS'] ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS'] pattern = re.compile("%s" % "|".join(ignore_check_login_urls)) if pattern.match(path): return pattern = re.compile("%s" % "|".join(ignore_urls)) if pattern.match(path): return if '/api' in path: return user_info = if_login() g.current_user = None if user_info: g.current_user = user_info # 加入日志 LogService.addAccessLog() else: return redirect(UrlManager.buildUrl('/user/login')) return
# 如果是静态文件就不要查询用户信息了 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.addAccessLog() pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return if not user_info : return redirect( UrlManager.buildUrl( "/user/login" ) ) return ''' 判断用户是否已经登录 ''' def check_login(): cookies = request.cookies