def decorator(*args, **kwargs): token = None if 'Authorization' in request.headers: header_value = request.headers['Authorization'] if header_value.find(' ') != -1: array = header_value.split(' ') if array[0] == 'token': token = array[1] if not token: return jsonify({'message': 'Missing token', 'code': 12}), 403 user_repo = UserRepository(MySQLFactory.get()) current_user = user_repo.get_active_by_token(token) if None is current_user: return jsonify({'message': 'Token is invalid', 'code': 13}), 403 # This method is the only one to need the current_user if 'renew_token' == decorated_function.__name__: return decorated_function(current_user, *args, **kwargs) return decorated_function(*args, **kwargs)
def get_user(): """Returns the user according to one filter""" controller = UserController return controller.get_by_filter(MySQLFactory.get(), request.args.get('filter', ''), request.args.get('value', ''))
def get_transactions(): """Get the transactions""" controller = TransactionController return controller.get_list(MySQLFactory.get())
def create_transaction(): """Create a transaction""" controller = TransactionController return controller.create(MySQLFactory.get())
def get_stories(): """Get the stories""" controller = StoryController return controller.get_list(MySQLFactory.get())
def create_story(): """Create a story""" controller = StoryController return controller.create(MySQLFactory.get())
def get_copies(): """Get the copies""" controller = CopyController return controller.get_list(MySQLFactory.get())
def create_copy(): """Create a copy""" controller = CopyController return controller.create(MySQLFactory.get())
def get_platforms(): """Get the platforms""" controller = PlatformController return controller.get_list(MySQLFactory.get())
def delete_platform(entity_id): """Delete the platform according to its id""" controller = PlatformController return controller.delete(MySQLFactory.get(), entity_id)
def create_platform(): """Create a platform""" controller = PlatformController return controller.create(MySQLFactory.get())
def get_platform_by_id(entity_id): """Returns the platform according to its id""" controller = PlatformController return controller.get_by_id(MySQLFactory.get(), entity_id)
def renew_token(current_user): """Renew the API token of the current user""" controller = UserController return controller.renew_token(MySQLFactory.get(), current_user)
def update_user(entity_id): """Updates a user""" controller = UserController return controller.update(MySQLFactory.get(), entity_id)
def create_user(): """Creates a user""" controller = UserController return controller.create(MySQLFactory.get())
def get_versions(): """Get the versions""" controller = VersionController return controller.get_list(MySQLFactory.get())
def get_copy_by_id(entity_id): """Returns the copy according to its id""" controller = CopyController return controller.get_by_id(MySQLFactory.get(), entity_id)
def get_game_by_id(entity_id): """Returns the game according to its id""" controller = GameController return controller.get_by_id(MySQLFactory.get(), entity_id)
def delete_copy(entity_id): """Delete the copy according to its id""" controller = CopyController return controller.delete(MySQLFactory.get(), entity_id)
def create_game(): """Create a game""" controller = GameController return controller.create(MySQLFactory.get())
def get_story_by_id(entity_id): """Returns the story according to its id""" controller = StoryController return controller.get_by_id(MySQLFactory.get(), entity_id)
def delete_game(entity_id): """Delete the game according to its id""" controller = GameController return controller.delete(MySQLFactory.get(), entity_id)
def delete_story(entity_id): """Delete the story according to its id""" controller = StoryController return controller.delete(MySQLFactory.get(), entity_id)
def get_games(): """Get the games""" controller = GameController return controller.get_list(MySQLFactory.get())
def get_transaction_by_id(entity_id): """Returns the transaction according to its id""" controller = TransactionController return controller.get_by_id(MySQLFactory.get(), entity_id)
def get_version_by_id(entity_id): """Returns the version according to its id""" controller = VersionController return controller.get_by_id(MySQLFactory.get(), entity_id)
def delete_transaction(entity_id): """Delete the transaction according to its id""" controller = TransactionController return controller.delete(MySQLFactory.get(), entity_id)
def create_version(): """Create a version""" controller = VersionController return controller.create(MySQLFactory.get())
def delete_version(entity_id): """Delete the version according to its id""" controller = VersionController return controller.delete(MySQLFactory.get(), entity_id)
def authenticate_user(): """Returns the token of the given user""" controller = UserController return controller.authenticate(MySQLFactory.get())