コード例 #1
0
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_articles=utilities.get_selected_movies(),
    )
コード例 #2
0
def test_authentication_with_invalid_credentials(memory_repo):
    username = '******'
    password = '******'

    auth_services.add_user(username, password, memory_repo)

    with pytest.raises(auth_services.AuthenticationException):
        auth_services.authenticate_user(username, '0987654321', memory_repo)
コード例 #3
0
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)
コード例 #4
0
def test_cannot_add_user_with_existing_name(memory_repo):
    username = '******'
    password = '******'

    with pytest.raises(auth_services.DuplicatedUsernameException):
        auth_services.add_user(username, password, memory_repo)

    with pytest.raises(auth_services.DuplicatedUsernameException):
        auth_services.add_user(username.lower(), password, memory_repo)
コード例 #5
0
def test_authentication_with_valid_credentials(memory_repo):
    username = '******'
    password = '******'

    auth_services.add_user(username, password, memory_repo)

    try:
        auth_services.authenticate_user(username, password, memory_repo)
    except AuthenticationException:
        assert False
コード例 #6
0
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
コード例 #7
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:')
コード例 #8
0
def test_can_add_user(memory_repo):
    username = '******'
    password = '******'
    auth_services.add_user(username, password, memory_repo)
    user_dict = auth_services.get_user(username, memory_repo)
    assert user_dict['username'] == 'TestUser'
    assert user_dict['password'].startswith('pbkdf2:sha256:')

    user_dict = auth_services.get_user(username.lower(), memory_repo)
    assert user_dict['username'] == 'TestUser'
    assert user_dict['password'].startswith('pbkdf2:sha256:')
コード例 #9
0
def test_can_save_user(memory_repo):
    # add and save user to disk
    username = '******'
    password = '******'
    auth_services.add_user(username, password, memory_repo)

    tmp_file = tempfile.NamedTemporaryFile(delete=False)
    auth_services._save_users_to_disk(tmp_file.name, memory_repo)

    with open(tmp_file.name, 'r') as f:
        file_content = ''.join(f.readlines())
        assert 'TestUser' in file_content
コード例 #10
0
def register():
    form = RegistrationForm()
    username_error_msg = None
    password_error_msg = None

    if form.validate_on_submit():
        try:
            services.add_user(form.username.data, form.password.data,
                              repo.repo_instance)
            return redirect(url_for(AUTH_BP + '.' + LOGIN_ENDPOINT))
        except services.DuplicatedUsernameException as e:
            username_error_msg = 'Username is not unique, please try another one'

    return render_template('credentials.html',
                           title='Movie Register',
                           form=form,
                           username_error_msg=username_error_msg,
                           password_error_msg=password_error_msg,
                           handler_url=url_for(AUTH_BP + '.' +
                                               REGISTER_ENDPOINT))
コード例 #11
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)

            # redirect to login
            return redirect(url_for('authentication_bp.login'))
        except services.NameNotUniqueException:
            username_not_unique = 'Username already taken'

    # GET request
    return render_template(
        'authentication/credentials.html',
        title='Register',
        form=form,
        username_error_message=username_not_unique,
        handler_url=url_for('authentication_bp.register')
    )
コード例 #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)