예제 #1
0
    def test_crud(self):
        with self.app_context():
            user = UserModel("ipo", "kk")

            self.assertIsNone(UserModel.find_by_username("ipo"))
            self.assertIsNone(UserModel.find_by_id(1))

            user.save_to_db()
            self.assertIsNotNone(UserModel.find_by_username("ipo"))
            self.assertIsNotNone(UserModel.find_by_id(1))
예제 #2
0
 def delete(self, user_id):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Admin Privileges required for this operation'}
     user = UserModel.find_by_id(user_id)
     if (not user):
         return {'message': 'User not found'}, 404
     elif user.id == 1:
         return {'message': 'Can not delete admin'}, 500
     user.delete_from_db()
     return {'message': 'User {} deleted'.format(user.username)}, 200
예제 #3
0
 def post(self, user_id):
     data = self.parser.parse_args()
     if UserModel.find_by_id(user_id):
         favorite_games = FavoriteGamesModel.find_favorite_games_by_user_id(user_id)
         for favorite_game in favorite_games:
             if favorite_game.game_url_id == data['game_url_id']:
                 return {"message": "This game ID is already in your list of favorites"}
         new_favorite_game = FavoriteGamesModel(user_id, **data)
         new_favorite_game.save_favorite_game_id()
         return {"message": f"Favorite game was save to user_id: {user_id}"}
     return{"message": "User do not exist"}
예제 #4
0
 def delete(self, user_id):
     game_url_id = request.args.get('game_url_id')
     if not game_url_id:
         return {"message": "Please provide a (game_url_id = ? ) as query parameter to remove it from the list"}
     if UserModel.find_by_id(user_id):
         favorite_games = FavoriteGamesModel.find_favorite_games_by_user_id(user_id)
         for favorite_game in favorite_games:
             if favorite_game.game_url_id == int(game_url_id):
                 favorite_game.remove_favorite_game()
                 return {"message":"Game was removed from the list of favorites"},202
         return {"message":"Game is not in the list of favorites"}
     return{"message": "User do not exist"}
예제 #5
0
 def test_register_user(self):
     with self.app() as client:
         with self.app_context():
             response = client.post("/register",
                                    data={
                                        "username": "******",
                                        "password": "******"
                                    })
             self.assertEqual(response.status_code, 201)
             self.assertIsNotNone(UserModel.find_by_username("ipo"))
             self.assertIsNotNone(UserModel.find_by_id(1))
             self.assertDictEqual(
                 {"message": "the account register successfully"},
                 json.loads(response.data))
예제 #6
0
 def put(self):
     parser = reqparse.RequestParser()
     parser.add_argument("username",
                         type=str,
                         required=True,
                         help="Username required to update the  account")
     parser.add_argument("password",
                         type=str,
                         required=True,
                         help="Password required to update the account")
     data = parser.parse_args()
     user_id = get_jwt_identity()
     user = UserModel.find_by_id(user_id)
     if safe_str_cmp(user.password, data['password']):
         return {"message": "You are using the same password please change it"}
     user.username = data['username']
     user.password = data['password']
     user.save_to_db()
     return {"message": "User name and password have been changed"}
예제 #7
0
 def get(cls, user_id: int):
     user = UserModel.find_by_id(user_id)
     if not user:
         return {'message': 'User Not Found'}, 404
     return user.json(), 200
예제 #8
0
 def get(self, user_id):
     user = UserModel.find_by_id(user_id)
     if (not user):
         return {'message': 'User not found'}, 404
     return user.json()
예제 #9
0
 def delete(self):
     user_id = get_jwt_identity()
     user = UserModel.find_by_id(user_id)
     user.delete_from_db()
     return {"message": "User was deleted"}
예제 #10
0
 def get(self):
     user_id = get_jwt_identity()
     user = UserModel.find_by_id(user_id)
     return user.json()
 def get(cls, user_id):
     user = UserModel.find_by_id(user_id)
     if user:
         return user.json()
     return {"message": "User not found"}, 404
예제 #12
0
def security(payload):
    """
    Parses the payload data for the user Identity
    """
    user_id = payload['identity']
    return UserModel.find_by_id(user_id)
 def delete(cls, user_id):
     user = UserModel.find_by_id(user_id)
     if user:
         user.delete_from_db()
         return {"message": "User deleted successfully"}, 200
     return {"message": "User not found"}, 404
예제 #14
0
 def delete(cls, user_id: int):
     user = UserModel.find_by_id(user_id)
     if not user:
         return {'message': 'User Not Found'}, 404
     user.delete_from_db()
     return {'message': 'User deleted.'}, 200
예제 #15
0
def identity(payload):
    userid = payload['identity']
    return UserModel.find_by_id(userid)
예제 #16
0
def identity(payload):
    id_user = payload['identity']
    return UserModel.find_by_id(id_user)
예제 #17
0
def identity(payload):
    """if the user is authenticated, Flask-JWT is verified their authorization header is correct"""
    user_id = payload["identity"]
    return UserModel.find_by_id(user_id)