def register(): form = RegistrationForm() username_not_unique = None if form.validate_on_submit(): # Successful POST, i.e. the username and password have passed validation checking. # Use the service layer to attempt to add the new user. try: services.add_user(form.username.data, form.password.data, repo.repo_instance) # All is well, redirect the user to the login page. return redirect(url_for('authentication_bp.login')) except services.NameNotUniqueException: username_not_unique = 'Your username is already taken - please supply another' # For a GET or a failed POST request, return the Registration Web page. return render_template('authentication/credentials.html', title='Register', form=form, username_error_message=username_not_unique, handler_url=url_for('authentication_bp.register'), selected_movies=utilities.get_selected_movies(), genre_urls=utilities.get_genres_and_urls(), director_urls=utilities.get_directors_and_urls(), actor_urls=utilities.get_actors_and_urls(), title_urls=utilities.get_titles_and_urls(), date_urls=utilities.get_dates_and_urls())
def test_authentication_with_invalid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) with pytest.raises(auth_services.AuthenticationException): auth_services.authenticate_user(new_username, '0987654321', in_memory_repo)
def test_authentication_with_valid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) try: auth_services.authenticate_user(new_username, new_password, in_memory_repo) except AuthenticationException: assert False
def test_can_add_user(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) user_as_dict = auth_services.get_user(new_username, in_memory_repo) assert user_as_dict['username'] == new_username # Check that password has been encrypted. assert user_as_dict['password'].startswith('pbkdf2:sha256:')
def test_cannot_add_user_with_existing_name(in_memory_repo): username = '******' password = '******' with pytest.raises(auth_services.NameNotUniqueException): auth_services.add_user(username, password, in_memory_repo)