コード例 #1
0
ファイル: audience.py プロジェクト: saltedfist/flag_IT
def audience_add():
    error = Error(0, '关注成功')
    token = request.headers.get("Access-Token")
    if not token:
        error.err_code = 9
        error.err_msg = "token is None"
        return error.make_json_response()
    uid = verify_token(token)
    if uid is None:
        error.err_code = 9
        error.err_msg = "token error"
        return error.make_json_response()
    user = User.get_user_by_id(uid)
    if user is None:
        error.err_code = 9
        error.err_msg = "登陆时间已过期,请重启登陆"
        return error.make_json_response()
    json_data = request.json
    by_uid = json_data.get('by_uid')
    status = json_data.get('status') if json_data.get('status') else 1
    if not all([by_uid]):
        error.err_code = 9
        error.err_msg = "提交数据缺失,请确认后重新提交."
        return error.make_json_response()
    audience_data = {'by_uid': by_uid, 'status': status, 'uid': uid}
    add_status = Audience.add(audience_data)
    if add_status is True:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '关注失败,请重新关注.'
    return error.make_json_response()
コード例 #2
0
ファイル: api_docs.py プロジェクト: saltedfist/flag_IT
def api_update():
    error = Error(0, 'success')
    access_token = request.headers.get("Access-Token")
    uid = redis_client.get(access_token)
    if not uid:
        error.err_msg = 9
        error.err_code = 'access token 为空'
        return error.make_json_response()
    user = User.get_user_by_id(int(uid))
    if user.id != 1:
        error.err_code = 9
        error.err_msg = '该用户暂无此权限,请联系管理员。'
        return error.make_json_response()
    update_info = request.json if request.json else None
    docs_id = update_info.get('docs_id')
    if docs_id is None:
        error.err_code = 9
        error.err_msg = '缺少参数。'
        return error.make_json_response()
    docs_id = update_info.pop("docs_id")
    parameter = json.dumps(update_info.get('parameter'))
    update_info['parameter'] = parameter
    re_info = json.dumps(update_info.get('re_info'))
    update_info['re_info'] = re_info
    update_status = ApiDocs.update_docs(docs_id, update_info)
    if update_status:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '更新失败,请重试。'
    return error.make_json_response()
コード例 #3
0
ファイル: target.py プロジェクト: saltedfist/flag_IT
    def change_target(cls, target_id: int, uid: int):

        target = DB.session.query(cls).filter(cls.target_id == target_id, cls.status == 0).one_or_none()
        if target.id != uid:
            return False
        challenge_gold = target.challenge_gold
        gold_type = target.gold_type
        target_id = target.id
        if target.insist_day + 1 >= target.number_of_days:
            target.status = 1
            target.end_time = timemac.today()
            DB.session.commit()
            # 挑战成功: 缺少给用户加金币,或者退还钱逻辑. 还需要在user表中 对积分或者rmb 进行修改.
            user = User.get_user_by_id(uid)
            user.update_time = timemac.today()
            if gold_type == 1: #1:金额   2:积分 待rmb与积分表建完,再完善逻辑.
                user.money = user.money + challenge_gold
                DB.session.commit()
                temp = {
                    'uid': user.id,
                    'money': user.money,
                    'type': 1,
                    'status': 1,
                    'target_id': target_id,
                    'create_time': timemac.today(),
                    'source_info': 1
                }
                add_status = Money_Detail.add_money_detail(temp)
                if add_status is False:
                    return False
                return True
            elif gold_type == 2:
                user.money = user.integral + target.challenge_gold
                DB.session.commit()
                temp = {
                    'uid': user.id,
                    'money': user.money,
                    'type': 1,
                    'status': 1,
                    'target_id': target_id,
                    'create_time': timemac.today(),
                    'source_info': 1
                }
                add_status = Integral_Detail.add_integral_detail(temp)
                if add_status is False:
                    return False
                return True
            else:
                return False
        else:
            target.insist_day = target.insist_day + 1
        DB.session.commint()
        return True
コード例 #4
0
ファイル: sign.py プロジェクト: saltedfist/flag_IT
def sign_add():
    error = Error(0, '签到成功')
    token = request.headers.get("Access-Token")
    if not token:
        error.err_code = 9
        error.err_msg = "token is None"
        return error.make_json_response()
    uid = verify_token(token)
    if uid is None:
        error.err_code = 9
        error.err_msg = "token error"
        return error.make_json_response()
    user = User.get_user_by_id(uid)
    if user is None:
        error.err_code = 9
        error.err_msg = "登陆时间已过期,请重启登陆"
        return error.make_json_response()
    json_data = request.json
    target_name = json_data.get('target_name') if json_data.get('target_name') else None
    target_id = json_data.get('target_id')
    content = json_data.get('content') if json_data.get('content') else None
    img = request.files.get('img')
    insist_day = json_data.get('insist_day') if json_data.get('insist_day') else 0
    status = json_data.get('status') if json_data.get('status') else 1
    if not all([target_id, img]):
        error.err_code = 9
        error.err_msg = "提交数据缺失,请确认后重新提交."
        return error.make_json_response()
    target = Target_Info.change_target(target_id, uid)
    if target is False:
        error.err_code = 9
        error.err_msg = '提交参数错误!,请确认后重新提交!'
        return error.make_json_response()

    sign_data = {
        'target_name': target_name,
        'target_id': target_id,
        'content': content,
        'img': img,
        'insist_day': insist_day,
        'status': status,
        'uid': uid
    }
    add_status = Sign.add(sign_data)

    if add_status is True:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '签到失败,请重新提交!'
    return error.make_json_response()
コード例 #5
0
ファイル: comment.py プロジェクト: saltedfist/flag_IT
def comment_add():
    error = Error(0, '评论成功')
    token = request.headers.get("Access-Token")
    if not token:
        error.err_code = 9
        error.err_msg = "token is None"
        return error.make_json_response()
    uid = verify_token(token)
    if uid is None:
        error.err_code = 9
        error.err_msg = "token error"
        return error.make_json_response()
    user = User.get_user_by_id(uid)
    if user is None:
        error.err_code = 9
        error.err_msg = "登陆时间已过期,请重启登陆"
        return error.make_json_response()
    json_data = request.json
    sign_id = json_data.get('sign_id')
    by_uid = json_data.get('by_uid')
    comment_id = json_data.get('comment_id') if json_data.get(
        'comment_id') else 0
    comment = json_data.get('comment')  # 前端得传html格式,后端直接存储
    type = json_data.get('type') if json_data.get('type') else 1
    status = json_data.get('status') if json_data.get('status') else 1
    if not all([sign_id, by_uid, comment_id, comment, type]):
        error.err_code = 9
        error.err_msg = "提交数据缺失,请确认后重新提交."
        return error.make_json_response()
    comment_data = {
        'sign_id': sign_id,
        'by_uid': by_uid,
        'comment_id': comment_id,
        'comment': comment,
        'type': type,
        'status': status,
        'uid': uid
    }
    add_status = Comment.add(comment_data)
    if add_status is True:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '评论失败,请重新评论.'
    return error.make_json_response()
コード例 #6
0
ファイル: like.py プロジェクト: saltedfist/flag_IT
def like_add():
    error = Error(0, '点赞成功')
    token = request.headers.get("Access-Token")
    if not token:
        error.err_code = 9
        error.err_msg = "token is None"
        return error.make_json_response()
    uid = verify_token(token)
    if uid is None:
        error.err_code = 9
        error.err_msg = "token error"
        return error.make_json_response()
    user = User.get_user_by_id(uid)
    if user is None:
        error.err_code = 9
        error.err_msg = "登陆时间已过期,请重启登陆"
        return error.make_json_response()
    json_data = request.json
    related_id = json_data.get('related_id')
    by_uid = json_data.get('by_uid')
    comment_id = json_data.get('comment_id') if json_data.get(
        'comment_id') else 0
    type = json_data.get('type') if json_data.get('type') else 1
    status = json_data.get('status') if json_data.get('status') else 1
    if not all([related_id, by_uid, comment_id, type]):
        error.err_code = 9
        error.err_msg = "提交数据缺失,请确认后重新提交."
        return error.make_json_response()
    like_data = {
        'related_id': related_id,
        'by_uid': by_uid,
        'comment_id': comment_id,
        'type': type,
        'status': status,
        'uid': uid
    }
    add_status = Like.add(like_data)
    if add_status is True:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '点赞失败,请重新点赞.'
    return error.make_json_response()
コード例 #7
0
ファイル: api_docs.py プロジェクト: saltedfist/flag_IT
def api_add():
    error = Error(0, 'success')
    access_token = request.headers.get("Access-Token")
    uid = redis_client.get(access_token)
    if not uid:
        error.err_code = 9
        error.err_msg = 'access token 为空'
        return error.make_json_response()
    user = User.get_user_by_id(int(uid))
    if user.id != 1:
        error.err_code = 9
        error.err_msg = '该用户暂无此权限,请联系管理员。'
        return error.make_json_response()
    api_info = request.json if request.json else {}
    api_name = api_info.get('api_name')
    api_url = api_info.get('api_url')
    request_mothod = api_info.get('request_mothod')
    parameter = api_info.get('parameter')
    re_example = api_info.get('re_example')
    re_info = api_info.get('re_info')
    if not all(
        [api_name, api_url, request_mothod, parameter, re_example, re_info]):
        error.err_code = 9
        error.err_msg = "数据不全,提交失败!"
        return error.make_json_response()
    kwargs = {
        'api_name': api_name,
        'api_url': api_url,
        'request_mothod': request_mothod,
        'parameter': json.dumps(parameter),
        're_example': re_example,
        're_info': json.dumps(re_info),
        'create_time': time.strftime('%y-%m-%d %H:%M:%S'),
        'modified_time': time.strftime('%y-%m-%d %H:%M:%S'),
        'status': 1
    }
    add_status = ApiDocs.add_apidocs(kwargs=kwargs)
    if add_status:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '存储文档失败。'
    return error.make_json_response()
コード例 #8
0
ファイル: api_docs.py プロジェクト: saltedfist/flag_IT
def api_history():
    error = Error(0, 'success')
    access_token = request.headers.get("Access-Token")
    uid = redis_client.get(access_token)
    if not uid:
        error.err_msg = 9
        error.err_code = 'access token 为空'
        return error.make_json_response()
    user = User.get_user_by_id(int(uid))
    if user.id != 1:
        error.err_code = 9
        error.err_msg = '该用户暂无此权限,请联系管理员。'
        return error.make_json_response()
    docs_id = request.args.get('docs_id')
    if docs_id:
        docs_info = ApiDocs.get_docs_info(int(docs_id))
    else:
        docs_info = ApiDocs.get_docs_info()
    error.set_data(docs_info)
    return error.make_json_response()
コード例 #9
0
ファイル: api_docs.py プロジェクト: saltedfist/flag_IT
def api_del():
    error = Error(0, 'success')
    access_token = request.headers.get("Access-Token")
    uid = redis_client.get(access_token)
    if not uid:
        error.err_msg = 9
        error.err_code = 'access token 为空'
        return error.make_json_response()
    user = User.get_user_by_id(int(uid))
    if user.id != 1:
        error.err_code = 9
        error.err_msg = '该用户暂无此权限,请联系管理员。'
        return error.make_json_response()
    del_info = request.json
    docs_id = del_info.get('id')
    update_info = {'status': 0}
    update_status = ApiDocs.update_docs(docs_id, update_info)
    if update_status:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '删除失败,请重试。'
    return error.make_json_response()
コード例 #10
0
ファイル: target.py プロジェクト: saltedfist/flag_IT
def target_add():
    error = Error(0, '建立目标成功')
    token = request.headers.get("Access-Token")
    if not token:
        error.err_code = 9
        error.err_msg = "token is None"
        return error.make_json_response()
    uid = verify_token(token)
    if uid is None:
        error.err_code = 9
        error.err_msg = "token error"
        return error.make_json_response()
    user = User.get_user_by_id(uid)
    if user is None:
        error.err_code = 9
        error.err_msg = "登陆时间已过期,请重启登陆"
        return error.make_json_response()
    json_data = request.json
    target_name = json_data.get('target_name') if json_data.get(
        'target_name') else None
    number_of_days = json_data.get('number_of_days')
    day_off = json_data.get('day_off')
    annotation = json_data.get('annotation') if json_data.get(
        'annotation') else None
    challenge_gold = json_data.get('challenge_gold')
    insist_day = json_data.get('insist_day') if json_data.get(
        'insist_day') else 0
    privacy = json_data.get('privacy') if json_data.get('privacy') else 1
    reminder_time = json_data.get('reminder_time')
    pay_type = json_data.get('pay_type')  # 付钱有另外的接口提供.
    gold_type = json_data.get('gold_type')
    start_time = json_data.get('start_time')
    if not all([
            number_of_days, day_off, challenge_gold, reminder_time, pay_type,
            gold_type
    ]):
        error.err_code = 9
        error.err_msg = "提交数据缺失,请确认后重新提交."
        return error.make_json_response()

    # 缺少判断,之前是否存在未完成flag. 是否让用户有且仅能立一个flag的问题还需再讨论.
    target_data = {
        'target_name': target_name,
        'number_of_days': number_of_days,
        'day_off': day_off,
        'annotation': annotation,
        'challenge_gold': challenge_gold,
        'insist_day': insist_day,
        'privacy': privacy,
        'reminder_time': reminder_time,
        'pay_type': pay_type,
        'gold_type': gold_type,
        'start_time': start_time
    }
    task_data = {
        'uid': uid,
        'type': 1,
        'tk_time': reminder_time,
    }
    # tk_status = Timing_Task.add(task_data) # 将提示时间加入定时表.
    add_status = Target_Info.add(target_data)
    if add_status is True:
        return error.make_json_response()
    error.err_code = 9
    error.err_msg = '建立目标失败,请重新提交.'
    return error.make_json_response()