import os from itertools import groupby from operator import itemgetter from functools import wraps from flask import request, session from app import rpc def split_group(dict_list, key): dict_list.sort(key=itemgetter(key)) tmps = groupby(dict_list, itemgetter(key)) result = [] for key, group in tmps: result.append({key: list(group)}) return result basedir = os.getcwd() def login_required(f): """ 登陆保护,验证用户是否登陆 """ @wraps(f) def wrapper(*args, **kwargs): token = request.headers.get("Authorization", default=None) if not token: return '请登陆' user_id = rpc.admin.identify(token) if not user_id: return '请登陆' session['user_id'] = user_id return f(*args, **kwargs) return wrapper