Esempio n. 1
0
def authenticate_user(username: str, password: str, repo: AbstractRepository):
    authenticated = False

    user = repo.get_user(username)
    if user is not None:
        authenticated = check_password_hash(user.password, password)
    if not authenticated:
        raise AuthenticationException
Esempio n. 2
0
def add_user(username: str, password: str, repo: AbstractRepository):
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    password_hash = generate_password_hash(password)

    user = User(username, password_hash)
    repo.add_user(user)
Esempio n. 3
0
def add_user(username: str, password: str, repo: AbstractRepository):
    # Check that the given username is available.
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    # Encrypt password so that the database doesn't store passwords 'in the clear'.
    password_hash = generate_password_hash(password)

    # Create and store the new User, with password encrypted.
    user = User(username, password_hash)
    repo.add_user(user)
Esempio n. 4
0
def add_review(movie_id: int, review_text: str, username: str, rating: int, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentArticleException
    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    review = Review(movie, review_text, user, rating)
    review.movie = movie
    movie.add_review(review)
    user.add_review(review)
    repo.add_review(review)
Esempio n. 5
0
def add_comment(article_id: int, comment_text: str, username: str, repo: AbstractRepository):
    # Check that the article exists.
    article = repo.get_article(article_id)
    if article is None:
        raise NonExistentArticleException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create comment.
    comment = make_comment(comment_text, user, article)

    # Update the repository.
    repo.add_comment(comment)
Esempio n. 6
0
def add_comment(title: str, comment_text: str, username: str, repo: AbstractRepository):
    # Check that the article exists.
    movie = repo.get_movies_by_title(title)
    if movie is None:
        raise NonExistentArticleException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create comment.
    comment = make_review(movie, comment_text)

    # Update the repository.
    repo.add_review(comment)
Esempio n. 7
0
def add_review(movie_id: int, review_text: str, username: str,
               repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create review.
    review = make_review(review_text, user, movie)

    # Update the repository.
    repo.add_review(review)
Esempio n. 8
0
def get_user(username: str, repo: AbstractRepository):
    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    return user_to_dict(user)