Beispiel #1
0
def get_perms(ser):
    """
    获取数据库中的所有权限
    :return:
    """
    session = ser.session
    perms = session.query(Perm).all()
    perms = [object_to_dict(perm) for perm in perms]

    return json.dumps(perms)
Beispiel #2
0
def get_account_info(service):
    """
    获取当前账户信息
    :param service:
    :return:
    """
    session = service.session
    acc = session.query(Admin).get(current_user.id)
    res_dict = object_to_dict(acc)

    return res_dict
Beispiel #3
0
def post_message_detail(ser):
    """
    获取留言详情
    :param ser:
    :return:
    """

    session = ser.session
    message_id = request.form.get('message_id')

    message = session.query(Message).filter(Message.id == message_id).first()
    res = {
        'status': 1,
        'message': object_to_dict(message),
        'user_info': object_to_dict(message.admin)
    }
    del res['user_info']['password']
    del res['user_info']['auth_key']

    logger.info(res)

    return json.dumps(res)
Beispiel #4
0
def post_role_perms(ser):
    """
    获取角色对应的权限
    :param ser:
    :return:
    """
    session = ser.session
    slug = request.form.get('slug')
    perms = session.query(Role).filter(Role.slug == slug).first().perms
    res = {
        'status': 1,
        'perms': [object_to_dict(perm) for perm in perms],
    }

    return json.dumps(res)
Beispiel #5
0
def get_roles(ser):
    """
    获取数据库中的所有角色
    :return:
    """
    session = ser.session
    roles = session.query(Role).all()

    res = [{
        'id': role.id,
        'name': role.name,
        'slug': role.slug,
        'perms': [object_to_dict(perm) for perm in role.perms]
    } for role in roles]

    return json.dumps(res)
Beispiel #6
0
def get_admins(ser):
    """
    获取管理员分配的角色情况
    :return:
    """
    session = ser.session
    admins = session.query(Admin).all()

    res = [{
        'id': admin.id,
        'username': admin.username,
        'create_time': admin.create_time.strftime("%Y-%m-%d %H:%M:%S"),
        'active': admin.active,
        'roles': [object_to_dict(role) for role in admin.roles],
    } for admin in admins]

    return json.dumps(res)
Beispiel #7
0
def post_user_roles(ser):
    """
    获取用户所拥有的角色
    :param ser:
    :return:
    """
    session = ser.session

    user = session.query(Admin).get(request.form.get('user_id'))
    user_roles = [object_to_dict(role) for role in user.roles]

    res = {
        'status': 1,
        'roles': user_roles,
    }

    return json.dumps(res)
Beispiel #8
0
def post_check(service):
    """
    测试代理
    :param service:
    :return:
    """
    session = service.session

    proxy_id = request.form.get('proxyId')
    proxy = session.query(Proxy).get(proxy_id)

    proxy = check_proxy(proxy)
    res = object_to_dict(proxy)

    proxy.area = res['area']
    proxy.speed = res['speed']
    proxy.origin = res['origin']
    proxy.protocol = res['protocol']
    proxy.nick_type = res['nick_type']
    session.commit()

    def get_speed_map(sd):
        if int(sd) == -1:
            return '不可用'
        if 0 < int(sd) <= 1:
            return '极快'
        elif 1 < int(sd) <= 3:
            return '优等'
        elif 3 < int(sd) <= 6:
            return '良好'
        else:
            return '较慢'

    res = {
        'status': 1,
        'ip': res['ip'],
        'port': res['port'],
        'origin': res['origin'],
        'area': '未知' if res['area'].startswith('\n') else res['area'],
        'protocol': protocol_map[res['protocol']],
        'nick_type': nick_type_map[res['nick_type']],
        'speed': get_speed_map(res['speed'])
    }

    return json.dumps(res)
Beispiel #9
0
def get_announcement_message(ser):
    """
    获取公告信息
    :param ser:
    :return:
    """

    session = ser.session
    announcement = session.query(Message).filter(
        Message.admin_id == 1).order_by(Message.create_time.desc()).first()
    if announcement:
        res = {
            'status': 1,
            'message': object_to_dict(announcement),
            'username': announcement.admin.username,
            'header': announcement.admin.header
        }
    else:
        res = {'status': 0}

    return json.dumps(res)
Beispiel #10
0
def get_user_info(ser):
    """
    获取用户信息
    :param ser:
    :return:
    """
    session = ser.session
    user = session.query(Admin).get(current_user.id)

    res = {
        'status':
        1,
        'user_info': [object_to_dict(user)],
        'identity':
        sorted([(role.slug, role.name) for role in user.roles],
               key=lambda x: x[0],
               reverse=True)[0][1]
    }

    del res['user_info'][0]['password']

    return json.dumps(res)