def auth_user(user_name: str, password: str, repo: AbstractRepository): auth = False user = repo.get_user(user_name) if user is not None: auth = check_password_hash(user.password, password) if not auth: raise AuthenticationException
def get_watchlist(user_name: str, repo: AbstractRepository): user = repo.get_user(user_name) watchlist = user.watchlist watchlist_dict = util_services.movies_to_dict(watchlist.watchlist) for movie in watchlist_dict: movie['rm_url'] = url_for('watchlist_bp.remove_from_watchlist', id=movie['id']) movie['review_url'] = url_for('review_bp.submit_review', id=movie['id']) return watchlist_dict
def add_review(movie_id: int, review_text: str, rating: int, user_name: str, repo: AbstractRepository): movie = repo.get_movie_by_id(movie_id) if movie is None: raise NonExistentMovieException user = repo.get_user(user_name) if user is None: raise UnknownUserException review = Review(movie=movie, review_text=review_text, rating=rating, user=user) repo.add_review(review)
def add_to_watchlist(movie_id: int, user_name: str, repo: AbstractRepository): user = repo.get_user(user_name) movie = repo.get_movie_by_id(movie_id) user.watchlist.add_movie(movie)
def remove_from_watchlist(movie_id: int, user_name: str, repo: AbstractRepository): user = repo.get_user(user_name) movie = repo.get_movie_by_id(movie_id) user.watchlist.remove_movie(movie)
def get_user(user_name: str, repo: AbstractRepository): user = repo.get_user(user_name) if user is None: raise UnknownUserException return util_services.user_to_dict(user)
def add_user(user_name: str, password: str, first_name: str, last_name: str, repo: AbstractRepository): if repo.get_user(user_name) is not None: raise NameNotUniqueException password_hash = generate_password_hash(password) repo.add_user(User(user_name, password_hash, first_name, last_name))