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
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)
def add_review(rank: int, review_txt: str, rating: int, username: str, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie(rank) if movie is None: raise NonExistentMovieException user = repo.get_user(username) if user is None: raise UnknownUserException # Create review. review = Review(movie, review_txt, rating) # Update the repository. repo.add_review(review)
def add_review(review_text: str, username: str, movie_id: int, rating: int, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie_by_index(movie_id) if movie is None: raise NonExistentMovieException # Check that the user exists user = repo.get_user(username) if user is None: raise UnknownUserException # Create review review = make_review(review_text=review_text, user=user, movie=movie, rating=rating) # Update the repository repo.add_review(review)
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)
def add_review(rate: int, rank: int, review_text: str, username: str, repo: AbstractRepository): # Check that the article exists. movie = repo.get_movie(int(rank)) print(movie) if movie is None: raise NonExistentMovieException user = repo.get_user(username) if user is None: raise UnknownUserException timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") print(timestamp) # Create comment. review = make_review(review_text, user, movie, timestamp, rate) # Update the repository. repo.add_review(review)
def get_user(username: str, repo: AbstractRepository): user = repo.get_user(username) if user is None: raise UnknownUserException return user_to_dict(user)