Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
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))