Beispiel #1
0
def get_job():
    """
    获取配置文件
    :return: json
    """
    err_data = {"data": {}, "error_code": 1}
    operator_code = request.values.get("operator_code", 0)
    if operator_code == 0:
        try:
            post = request.get_data().decode("utf-8")
            post = json.loads(post)
            operator_code = post['operator_code']
        except Exception as e:
            debug(e)
            return Reply.json(err_data)
    operator_code = "op_{operator_code}".format(operator_code=operator_code)
    data = redis.get(operator_code)
    if data is None:
        return Reply.json(err_data)
    try:
        data = json.loads(data)
    except Exception as e:
        data = err_data
        debug(e)
    return Reply.json(data)
Beispiel #2
0
def add_config():
    """
    添加配置
    :return:
    """
    post = request.values
    form = ConfigForm(post)
    if not form.validate():
        return Reply.error(form.errors)
    operator_code = "op_{operator_code}".format(
        operator_code=form.operator_code.data)
    return Reply.success("ok") if redis.set(
        operator_code, form.config.data) else Reply.error("failed")
Beispiel #3
0
def check_is_pin():
    """
    此接口用于
    根据传过来的code
    判断是否有pin码
    :return:
    """
    operator = request.values.get("operator", 0)
    if operator == 0:
        return Reply.error("参数传递出错")
    if str(operator) in current_app.config['PIN']:
        return Reply.success(current_app.config['PIN'][str(operator)])
    return Reply.error("无此 code, 请添加对应的code和类型")
Beispiel #4
0
def update_config():
    """
    更新配置
    :return:
    """
    post = request.values
    form = ConfigForm(post)
    if not form.validate():
        return Reply.error(form.errors)
    operator_code = "op_{operator_code}".format(
        operator_code=form.operator_code.data)
    data = redis.get(operator_code)
    if data is None:
        return Reply.error("此运营商code不存在")
    return Reply.success("ok") if redis.set(
        operator_code, form.config.data) else Reply.error("failed")
Beispiel #5
0
def search_by_code():
    """
    根据 operator_code 查询数据
    :return:
    """
    data = redis.keys()
    debug(data)
    operator_code = request.values.get("operator_code", 0)
    if operator_code == 0:
        return Reply.error("failed")
    data = redis.get("op_{operator_code}".format(operator_code=operator_code))
    return Reply.error("empty") if data is None else Reply.success(
        [{
            "operator_code": operator_code,
            "config": data
        }])
def unauthorized_handler():
    return Reply.error("请先登录")
Beispiel #7
0
def get_info():
    return Reply.success("ok")
Beispiel #8
0
def login():
    return Reply.success({"token": "super_admin"})