Beispiel #1
0
 def get(self):
     user_id = get_jwt_identity()
     items = [item.json() for item in ItemModel.find_all()]
     if user_id:
         return {"items": items}, 200
     return {
         'items': [item['name'] for item in items],
         'message': "more data available if you log in."
     }, 200
Beispiel #2
0
    def get(self):
        user_token, error, code = validate_token(request.headers)
        if error:
            return error, code

        token = TokenModel.find_by_token(user_token)
        if not token:
            return {"message": "Token is incorrect"}, 403
        items = [item.json() for item in ItemModel.find_all(token.user_id)]
        if items:
            return items, 200
        return {"message": "You don't have items"}, 400
 def get(self):
     """
     Here we get the JWT identity, and then if the user is logged in (we were able to get an identity)
     we return the entire item list.
     Otherwise we just return the item names.
     This could be done with e.g. see orders that have been placed, but not see details about the orders
     unless the user has logged in.
     """
     user_id = get_jwt_identity()
     items = [item.json() for item in ItemModel.find_all()]
     if user_id:
         return {'items': items}, 200
     return {
         'items': [item['name'] for item in items],
         'message': 'More data available if you log in.'
         }, 200
Beispiel #4
0
 def get(self):
     user_id = get_jwt_identity()
     return {
         'items':
         [item.describe() for item in ItemModel.find_all(user_id=user_id)]
     }