Example #1
0
def test_token():
    user = User.verify_auth_token(
        request.headers.get('Authentication-Token'))
    if user is not None:
        return jsonify(user.get_dict()), 201
    else:
        return jsonify({}), 403
Example #2
0
def get_user_info():
    user = User.verify_auth_token(
        request.headers.get('Authentication-Token'))
    if user == -1:
        return jsonify({'error': '未登录'}), 401
    if user is not None:
        return jsonify(user.get_dict()), 201
    else:
        return jsonify({}), 403
Example #3
0
def update_user(username):
    user = User.verify_auth_token(
        request.headers.get('Authentication-Token'))
    if user.username == username:
        new_user = json.loads(request.get_data())
        user.update_with_dict(new_user)
        return jsonify(user.get_dict()), 201
    else:
        return 403
Example #4
0
def delete_reservation(r_id):
    user = User.verify_auth_token(request.headers.get('Authentication-Token'))
    if user is not None:
        r = Reservation.objects(id=r_id)
        if len(r) == 0:
            return jsonify({}), 404
        if r[0].owner == user:
            r.delete()
            return jsonify({}), 204
    return jsonify({"msg": "Not permitted"}), 403
Example #5
0
def create_reservation():
    """Apply for a reservation"""
    user = User.verify_auth_token(request.headers.get('Authentication-Token'))
    if user is not None:
        data = json.loads(request.get_data())
        r = Reservation.reserve(user, data['start_time'], data['end_time'], data['detail'])
        if r is not None:
            return jsonify(r.get_dict()), 201
        return jsonify({"error": "预约失败,时间冲突"}), 403
    else:
        return jsonify({}), 403
Example #6
0
def reject(r_id):
    user = User.verify_auth_token(request.headers.get('Authentication-Token'))
    if user is not None:
        if user.privilege > 0:  # Check if user is an administrator.
            r = Reservation.objects(id=r_id)
            if len(r) == 0:
                return jsonify({"msg": "Id not exist"}), 404
            else:
                r[0].reject()
                return jsonify(r[0].get_dict()), 201
        else:
            return jsonify({"msg": "Not permitted"}), 403