Beispiel #1
0
def create_user():
    user_info = request.get_json()
    user = User.query.filter_by(email=user_info.get("email")).first()
    if user:
        return jsonify(msg="exists"), HTTPStatus.BAD_REQUEST
    try:
        user = UserSchema().load(user_info)
        response = requests.get(
            f"http://127.0.0.1:5002/car/{user_info.get('car_id')}")
        response_book = requests.get(
            f"http://127.0.0.1:5003/books/{user_info.get('book_id')}")
        if user:
            user.generate_password()
            user.save_db()
            if response.status_code == 200:
                user_car = UserCar()
                user_car.user_id = user.id
                user_car.car_id = response.json().get('id')
                user_car.save_db()
                user_book = UserBook()
                user_book.user_id = user.id
                user_book.book_id = response_book.json().get('id')
                user_book.save_db()
        else:
            return jsonify(msg="Not found"), HTTPStatus.NOT_FOUND

    except ValidationError as err:
        return jsonify(err.messages), HTTPStatus.BAD_REQUEST
    return UserSchema(exclude=["password"]).jsonify(user), HTTPStatus.OK
Beispiel #2
0
def create_user():
    data = request.get_json()
    try:
        user = UserSchema().load(data)
        user.save_db()
    except ValidationError as err:
        return jsonify(err.messages), 400
    except Exception as err:
        return jsonify({"result": str(err)}), 400
    return UserSchema(exclude=("password", )).jsonify(user)
Beispiel #3
0
def create_user():
    user_data = request.get_json()
    user = User.query.filter_by(email=user_data.get("email")).first()
    if user:
        return jsonify(msg="User exsist"), HTTPStatus.BAD_REQUEST
    try:
        user = UserSchema().load(user_data)
        user.set_password()
        user.save_db()
    except ValidationError as err:
        return jsonify(err.messages), HTTPStatus.BAD_REQUEST
    return UserSchema().jsonify(user), HTTPStatus.OK
Beispiel #4
0
def register():
    user_info = request.get_json()
    user = User.query.filter_by(email = user_info.get("email")).first()
    if user:
        return jsonify(msg="User exsist"),HTTPStatus.BAD_REQUEST
    try:    
        user = UserSchema().load(user_info)
        response = requests.get(f"http://127.0.0.1:5002/books/{user_info.get('book_id')}")
        if user:  
            user.set_password()
            user = user.save_db()   
            if response.status_code == 200:
                user_books = UserBooks()
                user_books.user_id = user.id
                user_books.book_id = response.json().get('id')
                user_books.save_db()
            
        else:
            return jsonify(msg="Not found!"),HTTPStatus.NOT_FOUND
    except ValidationError as err:
        return jsonify(err.messages),HTTPStatus.BAD_REQUEST
    # user.set_password()
    # user.save_db()
    # user = User(**user)
    # db.session.add(user)
    # db.session.commit()
    return UserSchema(exclude=["password"]).jsonify(user),HTTPStatus.OK