コード例 #1
0
    def post(self):
        args = auth_parser.parse_args()
        user = authentication_header_parser(args['Authorization'])

        if user:
            return {'Authorized': None}, http.client.OK

        return '', http.client.UNAUTHORIZED
コード例 #2
0
    def get(self):
        args = auth_parser.parse_args()
        user = authentication_header_parser(args['Authorization'])

        artist = ArtistModel.query.filter_by(user_id=user['id']).first()

        if not artist:
            return '', http.client.NOT_FOUND

        return artist
コード例 #3
0
    def get(self):
        args = auth_parser.parse_args()
        user_data = authentication_header_parser(args['Authorization'])

        user = UserModel.query.filter_by(id=user_data['id']).first()

        if not user:
            return '', http.client.NOT_FOUND

        return user
コード例 #4
0
    def delete(self):
        args = delete_parser.parse_args()
        user = authentication_header_parser(args['Authorization'])

        artist = ArtistModel.query.filter_by(user_id=user['id']).first()

        if artist:
            if not is_password_valid(artist.user, args['password']):
                return '', http.client.BAD_REQUEST

            db.session.delete(artist)
            db.session.commit()

        return '', http.client.NO_CONTENT
コード例 #5
0
    def delete(self):
        args = delete_parser.parse_args()
        user_data = authentication_header_parser(args['Authorization'])

        user = UserModel.query.filter_by(id=user_data['id']).first()

        if user:
            if not is_password_valid(user, args['password']):
                return '', http.client.BAD_REQUEST

            db.session.delete(user)
            db.session.commit()

        return '', http.client.NO_CONTENT
コード例 #6
0
    def patch(self):
        args = artist_parser.parse_args()
        user = authentication_header_parser(args['Authorization'])

        artist = ArtistModel.query.filter_by(user_id=user['id']).first()

        if not artist:
            return '', http.client.NOT_FOUND

        for key, val in args.items():
            if hasattr(artist, key):
                setattr(artist, key, val)

        db.session.commit()

        result = api_namespace.marshal(artist, artist_model)

        return result, http.client.OK
コード例 #7
0
    def post(self):
        args = artist_parser.parse_args()
        user = authentication_header_parser(args['Authorization'])

        new_artist = ArtistModel(
            name=args['name'],
            location=args['location'],
            bio=args['bio'],
            website=args['website'],
            user_id=user['id']
        )

        db.session.add(new_artist)
        db.session.commit()

        result = api_namespace.marshal(new_artist, artist_model)

        return result, http.client.CREATED