コード例 #1
0
def user_interceptor(next):
    cookie = ctx.request.cookies.get(LOGIN_COOKIE_NAME)
    ctx.request.user = None
    if cookie:
        user = parse_signed_cookie(cookie)
        if user and user.id:
            raise HttpError.seeother('/home')
    return next()
コード例 #2
0
ファイル: common.py プロジェクト: sfx478076717/python-admin
def check_login(next):
    logging.info('try to bind user from session cookie...')
    cookie = ctx.request.cookies.get(LOGIN_COOKIE_NAME)
    ctx.request.user = None
    if cookie:
        logging.info('parse session cookie...')
        user = parse_signed_cookie(cookie)

        if user and user.id and user.stillwork == 1:
            logging.info('bind user <%s> to session...' % user.mobile)
            ctx.request.user = user
            return next()
    raise HttpError.seeother('/login')
コード例 #3
0
def manage_interceptor(next):
    user = ctx.request.user
    if user and user.admin:
        return next()
    raise HttpError.seeother(path_join(_MODULE, '/signin'))
コード例 #4
0
def manage_index():
    raise HttpError.seeother(path_join(_MODULE, '/manage/comments'))
コード例 #5
0
def signout():
    ctx.response.delete_cookie(COOKIE_NAME)
    raise HttpError.seeother(path_join(_MODULE, '/'))
コード例 #6
0
def api_verify():
    verify_type = ctx.request.get('verifyType', None)
    object_id = ctx.request.get('objectId', None)
    verify_result = ctx.request.get('verifyResult', None)

    if not ctx.request.user.uid:
        raise HttpError.seeother('/login')

    # 如果缺少verify_type,或者object_id,或者verifyResult不等于1或2或3那么抛出参数错误
    if not verify_type or not object_id or (verify_result != '1'
                                            and verify_result != '2'
                                            and verify_result != '3'):
        error_code = ERROR_CODE['param_error']
        raise APIError(error_code, ERROR_MESSAGE[error_code], {})

    # 先查一次,看看这个ip是否有效,并且是否被评审过了,如果已经评审了,那么不能修改结果
    where = 'where `objectId` = ? and `verifyPerson` = ? and `verifyType` = ?'
    verify_data = IPSamplingVerify.select_by(
        where, [object_id, ctx.request.user.uid, verify_type],
        ['verifyResult'])

    if not verify_data or 'verifyResult' not in verify_data[
            0] or verify_data[0].verifyResult != 0:
        error_code = ERROR_CODE['not_allow_error']
        raise APIError(error_code, ERROR_MESSAGE[error_code], {})

    # 重新修改选题会作品的状态
    where = 'where objectId = ?'
    ip_info = IPPool.find_first(where, *[object_id])

    # 一抽过
    if verify_type == '1' and verify_result == '1':

        # 一审过(1,1)or 二审不过(3,2)or 二审复审不过(4,2) or 二评待审(3, 0 || 4, 0)
        if (ip_info.verifyType == 1 and ip_info.status == 1) or (
                ip_info.verifyType == 3 and ip_info.status
                == 2) or (ip_info.verifyType == 4 and ip_info.status == 2) or (
                    ip_info.verifyType == 3 and ip_info.status == 1) or (
                        ip_info.verifyType == 4 and ip_info.status
                        == 1) or (ip_info.verifyType == 3 and ip_info.status
                                  == 0) or (ip_info.verifyType == 4
                                            and ip_info.status == 0):
            pass

        # 一审不过(1,2)
        elif ip_info.verifyType == 1 and ip_info.status == 2:
            IPPool(status=1).update_by(where, *[object_id])

        else:
            raise APIError(99999991, '抽检数据存在异常!', {})

    # 一抽不过
    elif verify_type == '1' and verify_result == '2':

        # 一审过(1,1)or 二审不过(3,2)or 二审复审不过(4,2)or 二评待审(3, 0 || 4, 0)
        if (ip_info.verifyType == 1 and ip_info.status == 1) or (
                ip_info.verifyType == 3
                and ip_info.status == 2) or (ip_info.verifyType == 4
                                             and ip_info.status == 2):
            IPPool(verifyType=1, status=2).update_by(where, *[object_id])

        # 一审不过(1,2)
        elif (ip_info.verifyType == 1 and ip_info.status
              == 2) or (ip_info.verifyType == 3 and ip_info.status == 1) or (
                  ip_info.verifyType == 4 and ip_info.status == 1) or (
                      ip_info.verifyType == 3
                      and ip_info.status == 0) or (ip_info.verifyType == 4
                                                   and ip_info.status == 0):
            pass

        else:
            raise APIError(99999992, '抽检数据存在异常!', {})

    # 二抽过
    elif verify_type == '3' and verify_result == '1':

        # 一审不过(1,2)or 二审不过(3,2)
        if (ip_info.verifyType == 1 and ip_info.status == 2) or (
                ip_info.verifyType == 3
                and ip_info.status == 2) or (ip_info.verifyType == 4
                                             and ip_info.status == 2):
            ip_verify_type = 4 if ip_info.thirdOldStatus > 0 else 3
            IPPool(verifyType=ip_verify_type,
                   status=1).update_by(where, *[object_id])

        # 二审过(3,1)
        elif (ip_info.verifyType == 3
              and ip_info.status == 1) or (ip_info.verifyType == 4
                                           and ip_info.status == 1):
            pass

        else:
            raise APIError(99999993, '抽检数据存在异常!', {})

    # 二抽不过
    elif verify_type == '3' and verify_result == '2':

        # 一审不过(1,2)or 二审不过(3,2)
        if (ip_info.verifyType == 1 and ip_info.status == 2) or (
                ip_info.verifyType == 3
                and ip_info.status == 2) or (ip_info.verifyType == 4
                                             and ip_info.status == 2):
            pass

        # 二审过(2,1)
        elif (ip_info.verifyType == 3
              and ip_info.status == 1) or (ip_info.verifyType == 4
                                           and ip_info.status == 1):
            IPPool(status=2).update_by(where, *[object_id])

        else:
            raise APIError(99999994, '抽检数据存在异常!', {})

    # 复审二抽过
    elif verify_type == '4' and verify_result == '1':

        # 一审不过(1,2)or 二审复审不过(4,2)
        if (ip_info.verifyType == 1
                and ip_info.status == 2) or (ip_info.verifyType == 4
                                             and ip_info.status == 2):
            IPPool(verifyType=4, status=1).update_by(where, *[object_id])

        # 二审复审过(4,1)
        elif ip_info.verifyType == 4 and ip_info.status == 1:
            pass

        else:
            raise APIError(99999995, '抽检数据存在异常!', {})

    # 复审二抽不过
    elif verify_type == '4' and verify_result == '2':

        # 一审不过(1,2)or 二审复审不过(4,2)
        if (ip_info.verifyType == 1
                and ip_info.status == 2) or (ip_info.verifyType == 4
                                             and ip_info.status == 2):
            pass

        # 二审复审过(3,1)
        elif ip_info.verifyType == 4 and ip_info.status == 1:
            IPPool(status=2).update_by(where, *[object_id])

        else:
            raise APIError(99999996, '抽检数据存在异常!', {})

    where = 'where `objectId` = ? and `verifyPerson` = ? and `verifyType` = ?'
    ip_verify = IPSamplingVerify(verifyResult=verify_result,
                                 updateAt=time.time())
    res = ip_verify.update_by(where, object_id, ctx.request.user.uid,
                              verify_type)

    # 判断下返回的结果是不是存在问题
    if not hasattr(res, 'verifyResult') or res.verifyResult != verify_result:
        IPPool(verifyType=ip_info.verifyType,
               status=ip_info.status).update_by(where, *[object_id])
        error_code = ERROR_CODE['update_sql_error']
        raise APIError(error_code, ERROR_MESSAGE[error_code], {})

    return res
コード例 #7
0
def all_ip_list():
    if ctx.request.user.crm.find('4_1_5') == -1:
        raise HttpError.seeother('/sampling/myiplist')
    return _get_all_ip_sampling_list()
コード例 #8
0
def api_vote_result_list():
    if ctx.request.user.crm.find('4_1_10') == -1:
        raise HttpError.seeother('/home')

    return _get_votelist(is_admin=True)
コード例 #9
0
def api_package_list():
    if ctx.request.user.crm.find('4_1_9') == -1:
        raise HttpError.seeother('/home')

    return _get_package_list()
コード例 #10
0
def api_ip_list():
    if ctx.request.user.crm.find('4_1_8') == -1:
        raise HttpError.seeother('/home')

    return _get_votelist()
コード例 #11
0
def api_blacklist_list():
    if ctx.request.user.crm.find('4_1_8') == -1 and ctx.request.user.crm.find(
            '4_1_9') == -1 and ctx.request.user.crm.find('4_1_10') == -1:
        raise HttpError.seeother('/home')

    return _get_blacklist()
コード例 #12
0
def api_verify():
    verify_type = ctx.request.get('verifyType', None)
    object_id = ctx.request.get('objectId', None)
    verify_result = ctx.request.get('verifyResult', None)

    if not ctx.request.user.uid:
        raise HttpError.seeother('/login')

    # 如果缺少verify_type,或者object_id,或者verifyResult不等于1或2那么抛出参数错误
    if not verify_type or not object_id or (verify_result != '1'
                                            and verify_result != '2'):
        error_code = ERROR_CODE['param_error']
        raise APIError(error_code, ERROR_MESSAGE[error_code], {})

    # 先查一次,看看这个ip是否有效,并且是否被评审过了,如果已经评审了,那么不能修改结果
    where = 'where `objectId` = ? and `adminId` = ? and `verifyType` = ?'
    verify_data = IPVerify.select_by(
        where, [object_id, ctx.request.user.uid, verify_type],
        ['verifyResult'])

    if not verify_data or 'verifyResult' not in verify_data[
            0] or verify_data[0].verifyResult != 0:
        error_code = ERROR_CODE['not_allow_error']
        raise APIError(error_code, ERROR_MESSAGE[error_code], {})

    # 如果是未评审过的,那么可以放心大胆的修改状态了
    ip_verify = IPVerify(verifyResult=verify_result, updateAt=time.time())
    res = ip_verify.update_by(where, object_id, ctx.request.user.uid,
                              verify_type)

    # 判断下返回的结果是不是存在问题,好安心执行下面的操作
    if not hasattr(res, 'verifyResult') or res.verifyResult != verify_result:
        error_code = ERROR_CODE['update_sql_error']
        raise APIError(error_code, ERROR_MESSAGE[error_code], {})

    # 获取其他人的评审记录
    select_where = 'where `objectId` = ? and `adminId` != ? and `verifyType` = ?'
    verify_list = IPVerify.find_by(select_where, object_id,
                                   ctx.request.user.uid, verify_type)

    pass_count, not_pass_count = 0, 0

    if verify_result == '1':
        pass_count += 1
    else:
        not_pass_count += 1

    for item in verify_list:
        if item.verifyResult == 0:
            # 如果有没评审完的人,那么停止操作,返回上面的更新结果
            return res
        elif item.verifyResult == 1:
            pass_count += 1
        else:
            not_pass_count += 1

    # 计算下多人的评审结果,顺便将ipPools表的状态也改一下
    old_status_field = {
        '1': 'firstOldStatus',
        '3': 'secondOldStatus',
        '4': 'thirdOldStatus'
    }[verify_type]
    final_result = 1 if pass_count > not_pass_count else 2
    field = {
        'status': final_result,
        old_status_field: final_result,
        'updateAt': time.time()
    }

    where = 'where objectId = ? and verifyType = ?'
    update_info = IPPool(**field).update_by(where, object_id, verify_type)
    res.ipPoolsInfo = update_info
    return res
コード例 #13
0
def check_auth_interceptor(next):
    if ctx.request.user.crm.find('4_1_6') == -1 and ctx.request.user.crm.find(
            '4_1_7') == -1:
        raise HttpError.seeother('/home')

    return next()