Beispiel #1
0
class CommentSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Comment
        load_instance = True

    user = fields.Nested(UserSchema(only=("username", "id")))
    reviewee = fields.Nested(UserSchema(only=("username", "id")))
Beispiel #2
0
class ReviewSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Review
        load_instance = True

    author = fields.Nested(UserSchema(only=("username", "id")))
    user = fields.Nested(UserSchema(only=("username", "id")))
Beispiel #3
0
from flask import Blueprint, request
from models.user import User
from serializers.user import UserSchema
from marshmallow.exceptions import ValidationError
from decorators.secure_route import secure_route
user_schema = UserSchema()

router = Blueprint(__name__, "users")


@router.route("/signup", methods=["POST"])
def signup():

    try:
        user = user_schema.load(request.json)
        print(request.json)

    except ValidationError as e:
        return {'errors': e.messages, 'messages': 'Something went wrong.'}, 401

    user.save()

    return user_schema.jsonify(user)


@router.route('/login', methods=['POST'])
def login():
    # ! 1) Get that user by their email/username, check if they exist.
    user = User.query.filter_by(email=request.json['email']).first()

    if not user:
Beispiel #4
0
class ImageSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Image
        load_instance = True

    user = fields.Nested(UserSchema(only=("username", "id")))