Exemplo n.º 1
0
def follow_or_unfollow(uid):
    received_user = User.query.get_or_404(uid)
    if g.user.is_following(received_user):
        g.user.unfollow(received_user)
    else:
        g.user.follow(received_user)
    db_handler(g.user)
    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 2
0
def report_manage(uid):
    is_banned = request.json.get('is_banned')
    if is_banned:
        user = User.query.get_or_404(uid)
        user.is_banned = True
        db_handler(user)
    elif is_banned is None:
        abort(400)
    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 3
0
def change_avatar():
    """
    保存头像至OSS
    """
    avatarUrl = request.json.get('avatarUrl')
    if avatarUrl is None:
        abort(400)
    g.user.avatarUrl = avatarUrl
    db_handler(g.user)

    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 4
0
def cancel_user_order(order_id):
    order = Order.query.get_or_404(order_id)
    if g.user.id != order.seller_id:
        # 若当前用户不是订单的卖家,则无法被取消
        abort(403)
    if order.status != 1:
        # 若当前订单未被接受, 则无法被取消
        abort(400)
    order.status = 2
    db_handler(order)
    # 向顾客发送消息
    push_message_to_user(order.customer_id,
                         '您的订单被{seller}取消'.format(seller=g.user.name))
    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 5
0
def report(uid):
    reason = request.json.get('reason')
    if reason is None:
        abort(400)
    reported_user = User.query.get_or_404(uid)
    try:
        report_message = ReportMessage(reason=reason,
                                       reported=reported_user,
                                       reporter=g.user)
    except Exception as e:
        current_app.logger.error(e)
        abort(500)
    db_handler(report_message)
    return jsonify({'message': '举报成功'}), 200
Exemplo n.º 6
0
    def put(self, uid):
        # 取消/降级用户设计师资格
        user = User.query.get_or_404(uid)
        if user.is_designer():
            # 设计师-->普通用户
            user.role = Role.query.filter_by(permission=0x03ff).first()
            content = '根据系统判决,您的身份降为普通用户'
        elif user.is_super_designer():
            # 特约设计师-->设计师
            user.role = Role.query.filter_by(permission=0x3fff).first()
            content = '根据系统判决,您的身份降为设计师'
        else:
            return abort(404)

        db_handler(user)
        # 向用户推送的取消/降级消息
        push_message_to_user(user.id, content)
        return jsonify({'message': '操作成功'}), 200
Exemplo n.º 7
0
def confirm_user_order(order_id):
    # 是否接受订单
    is_agree = request.json.get('is_agree')
    if is_agree is None:
        abort(400)

    order = Order.query.get_or_404(order_id)
    if g.user.id != order.seller_id:
        # 若当前用户不是订单的卖家,则无法接受订单
        abort(403)
    if is_agree:
        order.status = 1
        content = '{seller}已接受您的订单'.format(seller=g.user.name)
    else:
        order.status = 2
        content = '{seller}拒绝了您的订单'.format(seller=g.user.name)
    push_message_to_user(order.customer_id, content)
    db_handler(order)
    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 8
0
def apply():
    detail = request.json.get('detail')
    if detail is None:
        abort(400)
    user = g.user
    if user.is_designer():
        apply_type = '特约设计师'
    elif not user.is_super_designer():
        apply_type = '设计师'
    else:
        return jsonify({'error': '您已经是特约设计师了,无需再进行申请'}), 404
    try:
        apply_message = ApplyMessage(applicant=user,
                                     detail=detail,
                                     apply_type=apply_type)
    except Exception as e:
        current_app.logger.error(e)
        abort(500)
    db_handler(apply_message)
    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 9
0
def generate_user_order():
    data = request.json

    seller_id = data.get('seller_id')
    if seller_id is None:
        abort(400)
    try:
        new_order = Order(customer_id=g.user.id, seller_id=seller_id)
    except Exception as e:
        current_app.logger.error(e)
        abort(500)
    db_handler(new_order)

    type = data.get('type')
    if type is None:
        abort(400)
    order_extra = OrderExtra(order=new_order)
    if type == 'shoot':
        set_value_from_request(new_order, data, [
            'time', 'content', 'thinking', 'requirements', 'is_take_deposit',
            'customer_weixin'
        ])
        set_value_from_request(
            order_extra, data,
            ['gender', 'age', 'location', 'late_protocol', 'is_solve_eat'])
    else:
        set_value_from_request(new_order, data, [
            'time', 'content', 'thinking', 'requirements', 'is_take_deposit',
            'customer_weixin'
        ])

    # 向设计师发送消息
    return jsonify({
        'id':
        new_order.id,
        'detail_url':
        url_for('user_blueprint.get_user_order_detail',
                uid=new_order.id,
                _external=True)
    }), 200
Exemplo n.º 10
0
def apply_manage(uid):
    is_passed = request.json.get('is_passed')
    if is_passed:
        user = User.query.get_or_404(uid)
        if user.role.permission == 0x03ff:
            # 普通用户-->设计师
            user.role = Role.query.filter_by(permission=0x3fff).first()
        else:
            # 设计师-->特约设计师
            user.role = Role.query.filter_by(permission=0x1fff).first()
        db_handler(user)
        if user.role.permission == 0x3fff:
            content = '申请通过, 您已成为设计师'
        else:
            content = '申请通过, 您已成为特约设计师'
        # 推送消息
        push_message_to_user(uid, content)
    elif is_passed is None:
        abort(400)
    else:
        content = '很遗憾,申请未通过'
        push_message_to_user(uid, content)
    message_confirm(ApplyMessage)
    return jsonify({'message': '操作成功'}), 200
Exemplo n.º 11
0
def login():
    data = request.json

    code = data.get('code')
    if code is None:
        abort(400)

    session_key, openid = get_session_key_and_openid(code)
    if session_key is None or openid is None:
        return abort(400)

    user = User.query.filter_by(openid=openid).first()

    if user is None:
        # user为空,说明为新用户,获取其信息录入数据库
        try:
            user = User(openid=openid)
        except Exception as e:
            current_app.logger.error(e)
            abort(500)
        db_handler(user)
        # 让用户成为他自己的粉丝
        db_handler(user.follow(user))

    user.last_login = datetime.datetime.utcnow()
    db_handler(user)

    token = generate_3rd_session(session_key, openid)

    return jsonify({
        'token':
        token,
        'uid':
        user.id,
        'detail_url':
        url_for('user_blueprint.get_user_info', uid=user.id, _external=True)
    }), 200
Exemplo n.º 12
0
 def post(self, uid):
     # 将用户加入/移除黑名单
     user = User.query.get_or_404(uid)
     user.is_banned = not user.is_banned
     db_handler(user)
     return jsonify({'message': '操作成功'}), 200