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.
        # User 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 try another'

    # For a GET or a failed POST request, return the Registration Web page.
    return render_template(
        'authentication/credentials.html',
        title='Register',
        form_login=form,
        form=SearchForm(),
        handler_url=url_for('movies_bp.search'),
        title_form=SearchByTitleForm(),
        handler_url_title=url_for('movies_bp.search_by_title'),
        username_error_message=username_not_unique,
        handler_url_login=url_for('authentication_bp.register'),
        selected_movies=utilities.get_selected_movies(),
        genre_urls=utilities.get_genres_and_urls())
Ejemplo n.º 2
0
def test_authentication_with_invalid_credentials():
    mem_repo = MemoryRepository()
    new_user_name = "lumehtial"
    new_password = "******"
    auth_services.add_user(new_user_name, new_password, mem_repo)
    with pytest.raises(auth_services.AuthenticationException):
        auth_services.authenticate_user(new_user_name, '0987654321', mem_repo)
Ejemplo n.º 3
0
def test_cannot_add_user_with_existing_name():
    mem_repo = MemoryRepository()
    user_name = "annab3ll3"
    password = "******"
    auth_services.add_user(user_name, password, mem_repo)
    with pytest.raises(auth_services.NameNotUniqueException):
        auth_services.add_user(user_name, password, mem_repo)
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)
Ejemplo n.º 5
0
def test_authentication_with_valid_credentials():
    mem_repo = MemoryRepository()
    new_user_name = "ecartman"
    new_password = "******"
    auth_services.add_user(new_user_name, new_password, mem_repo)
    try:
        auth_services.authenticate_user(new_user_name, new_password, mem_repo)
    except AuthenticationException:
        assert False
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
Ejemplo n.º 7
0
def test_can_add_user():
    mem_repo = MemoryRepository()
    new_user_name = "kelly007"
    new_password = "******"
    auth_services.add_user(new_user_name, new_password, mem_repo)
    user_as_dict = auth_services.get_user(new_user_name, mem_repo)
    assert user_as_dict["username"] == new_user_name

    # check that password has been encrypted.
    assert user_as_dict["password"].startswith("pbkdf2:sha256:")
Ejemplo n.º 8
0
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:')
Ejemplo n.º 9
0
def register():
    form = RegistrationForm()
    username_not_unique = None

    if form.validate_on_submit():
        try:
            services.add_user(form.username.data, form.password.data,
                              repo.repository_instance)
            return redirect(url_for('authentication_bp.login'))
        except services.NameNotUniqueError:
            username_not_unique = 'The username is already taken.'
    return render_template('credentials.html',
                           title='Register',
                           form=form,
                           username_error_message=username_not_unique,
                           handler_url=url_for('authentication_bp.register'))
Ejemplo n.º 10
0
def register():
    form = RegistrationForm()
    username_not_unique = None

    if form.validate_on_submit():
        try:
            services.add_user(form.username.data, form.password.data, repo.repo_instance)
            return redirect(url_for('authentication_bp.login'))
        except services.NameNotUniqueException:
            username_not_unique = 'Your username is already taken - please supply another'

    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()
    )
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(
        'First/authentication/credentials.html',
        title='Sign Up',
        form=form,
        username_error_message=username_not_unique,
        handler_url=url_for('authentication_bp.register')
    )
Ejemplo n.º 12
0
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)