# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : auth.py
# @Time       : 2021/1/15 下午4:54
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------
from flask import request, g

from app.api.engine import redis


def login_require(func):
    def auth(*args, **kwargs):
        token = request.headers.get('Authorization', '')
        token = 's:sid:' + token.split(' ')[1]
        ifa_id = redis.get(token)
        if not ifa_id:
            return {"code": '9005', "message": "请登录", "attributes": []}
        g.ifa_id = ifa_id.decode().replace('\"', '')
        return func(*args, **kwargs)
    return auth