Пример #1
0
def login():
    form = LoginForm()
    username_not_recognised = None
    password_does_not_match_username = None

    if form.validate_on_submit():
        try:
            user = services.get_user(form.username.data, repo.repo_instance)

            services.authenticate_user(user['username'], form.password.data,
                                       repo.repo_instance)

            session.clear()
            session['username'] = user['username']
            return redirect(url_for('home_bp.home'))

        except services.UnknownUserException:
            username_not_recognised = 'Username not recognised - please supply another'

        except services.AuthenticationException:
            password_does_not_match_username = '******'

    return render_template(
        'authentication/credentials.html',
        title='Login',
        username_error_message=username_not_recognised,
        password_error_message=password_does_not_match_username,
        form=form,
    )
def login():
    form = utilities.LoginForm()

    if form.validate_on_submit():
        print(form.username.data, form.password.data)
        # Successful POST, i.e. the username and password have passed validation checking.
        # Use the service layer to lookup the user.
        try:
            user = services.get_user(form.username.data, repo.repo_instance)

            # Authenticate user.
            services.authenticate_user(user['username'], form.password.data,
                                       repo.repo_instance)

            # Initialise session and redirect the user to the home page.
            session.clear()
            session['username'] = user['username']
            return redirect(url_for('home_bp.home'))

        except services.UnknownUserException:
            # Username not known to the system, set a suitable error message.
            flash('Username not recognised - please supply another')

        except services.AuthenticationException:
            # Authentication failed, set a suitable error message.
            flash(
                'Password does not match supplied username - please check and try again'
            )

    # For a GET or a failed POST, return the Login Web page.
    return redirect(url_for("home_bp.home"))
Пример #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, '123545354', in_memory_repo)
Пример #4
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
Пример #5
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)
Пример #6
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, '2579643678',
                                        in_memory_repo)
Пример #7
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
Пример #8
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
Пример #9
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
Пример #10
0
def login():
    form = LoginForm()
    username_not_recognised = None
    password_does_not_match_username = None

    if form.validate_on_submit():
        # Successful POST, i.e. the username and password have passed validation checking.
        # Use the service layer to lookup the user.
        try:
            user = services.get_user(form.username.data, repo.repo_instance)

            # Authenticate user.
            services.authenticate_user(user['username'], form.password.data, repo.repo_instance)

            # Initialise session and redirect the user to the home page.
            session.clear()
            session['username'] = user['username']
            return redirect(url_for('home_bp.home'))


        except services.UnknownUserException:
            # Username not known to the system, set a suitable error message.
            username_not_recognised = 'Username not recognised - please supply another'

        except services.AuthenticationException:
            # Authentication failed, set a suitable error message.
            password_does_not_match_username = '******'

    # For a GET or a failed POST, return the Login Web page.
    return render_template(
        'authentication/credentials.html',
        title='Login',
        username_error_message=username_not_recognised,
        password_error_message=password_does_not_match_username,
        form=form,
        # selected_articles=utilities.get_selected_articles(),
        # tag_urls=utilities.get_tags_and_urls()
    )