Example #1
0
def target_history():
    error = Error(0, 'success')
    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()
    target_info = Target_Info.get_target_info_by_uid(uid)
    return target_info
Example #2
0
def set_privacy():
    error = Error(0, 'success')
    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 = 8
        error.err_msg = "token error"
        return error.make_json_response()
    target_id = int(
        request.args.get('target_id')) if request.args.get('target_id') else 0
    privacy_status = int(request.args.get(
        'privacy_status')) if request.args.get('target_id') else 0
    if all([target_id, privacy_status]):
        error.err_code = 7
        error.err_msg = '参数缺失,提交失败!'
        return error.make_json_response()
    target = Target_Info.get_target_one_info(uid, target_id)
    if target is None:
        error.err_code = 6
        error.err_msg = '未找该flag,请确认后提交!'
        return error.make_json_response()

    update_data = {
        'privacy': privacy_status,
    }
    update_status = Target_Info.update_target(uid, target_id, update_data)
    if update_status:
        return error.make_json_response()
    else:
        error.err_code = 5
        error.err_msg = '提交失败,请重试!'
        return error.make_json_response()
Example #3
0
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()
Example #4
0
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()
Example #5
0
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()
Example #6
0
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()
Example #7
0
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()
Example #8
0
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()
Example #9
0
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()
Example #10
0
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()
Example #11
0
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()
Example #12
0
def send_email():
    error = Error(0, 'success')
    info = request.json
    if info is None:
        error.err_code = '9',
        error.err_msg = '请填写邮箱信息'
    email = info.get('email')
    forget = info.get('forget')
    # verify_email = info.get('verify')
    # if verify_email:
    check_status = User.check_email(email)
    if type(check_status) is int and forget is None:
        error.err_code = 9
        error.err_msg = '该邮箱已注册过.'
        return error.make_json_response()
    elif type(check_status) is not int and forget:
        error.err_code = 9
        error.err_msg = '该邮箱未注册过,请注册后,登陆.'
        return error.make_json_response()
    verification = create_veri()
    # 限制用户发送邮件的次数。
    redis_client.set(email, verification)
    msg = {
        's':
        "WelCome TO Join Us!,啦啦啦~",
        'r':
        email,
        'c':
        "[FLAG]<br>尊敬的用户</br>您的校验码:{0}<br>工作人员不会索取,请勿泄露!</br>\n".format(
            verification),
        # 'c': verification
    }
    # 停止发送注册,直供开发人员使用
    # send_status = tasks.send_mail(msg)
    send_status = 2
    if send_status != 1:
        error.err_code = 9
        error.err_msg = '发送邮箱失败!'
        return error.make_json_response()
    else:
        return error.make_json_response()
Example #13
0
def forget_passwd():
    error = Error(0, '人生需要目标,有了目标才有奋斗的方向!')
    forget_info = request.json
    email = forget_info.get('email')
    passwd = forget_info.get('password')
    verify = forget_info.get('verify')
    if not (email and verify):
        error.err_code = 9
        error.err_msg = "参数为空"
        return error.make_json_response()
    user = User.get_user_by_email(email)
    if user is None:
        error.err_code = 9
        error.err_msg = '该邮箱填写错误'
    new_veri_code = redis_client.get(email)
    if new_veri_code is None:
        error.err_code = 9
        error.err_msg = '请获取邮箱验证码'
        return error.make_json_response()
    if str(new_veri_code, encoding='utf-8') != str(verify):
        error.err_code = 9
        error.err_msg = '该验证码错误,请尝试重新获取'
        return error.make_json_response()
    passwd = render_password(passwd)
    acc = {'password': passwd}
    add_status = User.update_user(user.id, acc)
    if add_status:
        return error.make_json_response()
    else:
        error.err_code = 0
        error.err_msg = "修改成功"
        return error.make_json_response()
Example #14
0
def account_register():
    if request.method == 'POST':
        error = Error(0, '人生需要目标,有了目标才有奋斗的方向!')
        info = request.json
        if info is None:
            error.err_code = 9
            error.err_msg = "参数为空1"
            return error.make_json_response()
        name = info.get('name')
        pass_word = info.get('password')
        # phone = info.get('phone')
        email = info.get('email')
        # verification = request.form.get('verify')
        verification = info.get('verify')  # 验证码
        if not (name and pass_word and email and verification):
            error.err_code = 9
            error.err_msg = "参数为空2"
            return error.make_json_response()
        check_name = User.get_user_by_name(name)
        if check_name:
            error.err_code = 8
            error.err_msg = "该用户名已存在"
            return error.make_json_response()
        acc = {
            'name': name,
            'password': pass_word,
            'email': email,
            'status': 1
        }
        new_verification = redis_client.get(email)
        if new_verification is None:
            error.err_code = 3
            error.err_msg = '请获取邮箱验证码'
            return error.make_json_response()
        if str(verification) != str(new_verification, encoding='utf-8'):
            error.err_code = 4
            error.err_msg = '该验证码错误,请尝试重新获取'
            return error.make_json_response()
        add_status = User.add_user(acc)
        if add_status:
            return error.make_json_response()
        else:
            error.err_code = 5
            error.err_msg = "创建失败"
            return error.make_json_response()