コード例 #1
0
ファイル: utils_test.py プロジェクト: chriskuehl/ocflib
    def test_calls_pexpect_correctly(self, spawn, __):
        password_matches('ckuehl', 'hunter2')
        spawn.assert_called_with(
            'kinit --no-forwardable -l0 [email protected]',
            timeout=10,
        )

        child = spawn.return_value

        assert child.expect.mock_calls == [
            mock.call.first('[email protected]\'s Password:'******'hunter2')
        assert child.close.called
コード例 #2
0
ファイル: utils_test.py プロジェクト: wilswu/ocflib
    def test_calls_pexpect_correctly(self, spawn, __):
        password_matches('ckuehl', 'hunter2')
        spawn.assert_called_with(
            'kinit --no-forwardable -l0 [email protected]',
            timeout=10,
        )

        child = spawn.return_value

        assert child.expect.mock_calls == [
            mock.call.first('[email protected]\'s Password:'******'hunter2')
        assert child.close.called
コード例 #3
0
ファイル: ocf.py プロジェクト: andycui97/ocfweb
def login(request):
    error = None

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            try:
                if (validators.user_exists(username)
                        and utils.password_matches(username, password)):
                    request.session['ocf_user'] = username
                    return redirect_back(request)
                else:
                    error = (
                        'Authentication failed. Did you type the wrong username or password?'
                    )
            except ValueError as ex:
                error = 'Authentication failed: {error}'.format(
                    error=str(ex), )
    else:
        form = LoginForm()

    return render(
        request,
        'login/ocf/login.html',
        {
            'title': 'OCF Login',
            'form': form,
            'error': error,
        },
    )
コード例 #4
0
ファイル: views.py プロジェクト: ocf/atool
def login(request):
    error = None

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            try:
                if (validators.user_exists(username) and
                        utils.password_matches(username, password)):
                    request.session['ocf_user'] = username
                    return redirect_back(request)
                else:
                    error = 'Authentication failed. Did you type the wrong' + \
                        'username or password?'
            except ValueError as ex:
                error = 'Authentication failed: {error}'.format(
                    error=str(ex),
                )
    else:
        form = LoginForm()

    return render_to_response('login.html', {
        'form': form,
        'error': error
    }, context_instance=RequestContext(request))
コード例 #5
0
def login(request: HttpRequest) -> Union[HttpResponseRedirect, HttpResponse]:
    error = None

    return_to = request.GET.get('next')
    if return_to and _valid_return_path(return_to):
        request.session['login_return_path'] = return_to

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            try:
                if (
                        validators.user_exists(username) and not
                        user_is_sorried(username) and
                        utils.password_matches(username, password)
                ):
                    session_login(request, username)
                    return redirect_back(request)
                else:
                    error = (
                        'Authentication failed. Your account may be disabled, '
                        'or you may have typed the wrong username or password.'
                    )
            except ValueError as ex:
                error = 'Authentication failed: {error}'.format(
                    error=str(ex),
                )
    else:
        form = LoginForm()

    return render(
        request,
        'login/ocf/login.html',
        {
            'title': 'OCF Login',
            'form': form,
            'error': error,
        },
    )
コード例 #6
0
ファイル: ocf.py プロジェクト: jvperrin/ocfweb
def login(request):
    error = None

    return_to = request.GET.get('next')
    if return_to and _valid_return_path(return_to):
        request.session['login_return_path'] = return_to

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            try:
                if (
                        validators.user_exists(username) and
                        utils.password_matches(username, password)
                ):
                    session_login(request, username)
                    return redirect_back(request)
                else:
                    error = (
                        'Authentication failed. Did you type the wrong username or password?'
                    )
            except ValueError as ex:
                error = 'Authentication failed: {error}'.format(
                    error=str(ex),
                )
    else:
        form = LoginForm()

    return render(
        request,
        'login/ocf/login.html',
        {
            'title': 'OCF Login',
            'form': form,
            'error': error,
        },
    )
コード例 #7
0
ファイル: utils_test.py プロジェクト: wilswu/ocflib
 def test_returns_correctly(self, spawn, __, exitstatus, success):
     spawn.return_value.exitstatus = exitstatus
     assert password_matches('ckuehl', 'hunter2') == success
コード例 #8
0
ファイル: utils_test.py プロジェクト: wilswu/ocflib
 def test_fails_if_user_does_not_exist(self, __):
     with pytest.raises(ValueError):
         password_matches('ckuehl', 'hunter2')
コード例 #9
0
ファイル: utils_test.py プロジェクト: wilswu/ocflib
 def test_fails_with_bad_password(self, password):
     with pytest.raises(ValueError):
         password_matches('ckuehl', password)
コード例 #10
0
ファイル: utils_test.py プロジェクト: wilswu/ocflib
 def test_fails_with_bad_username(self, user):
     with pytest.raises(ValueError):
         password_matches(user, 'hunter2')
コード例 #11
0
ファイル: utils_test.py プロジェクト: chriskuehl/ocflib
 def test_returns_correctly(self, spawn, __, exitstatus, success):
     spawn.return_value.exitstatus = exitstatus
     assert password_matches('ckuehl', 'hunter2') == success
コード例 #12
0
ファイル: utils_test.py プロジェクト: chriskuehl/ocflib
 def test_fails_if_user_does_not_exist(self, __):
     with pytest.raises(ValueError):
         password_matches('ckuehl', 'hunter2')
コード例 #13
0
ファイル: utils_test.py プロジェクト: chriskuehl/ocflib
 def test_fails_with_bad_password(self, password):
     with pytest.raises(ValueError):
         password_matches('ckuehl', password)
コード例 #14
0
ファイル: utils_test.py プロジェクト: chriskuehl/ocflib
 def test_fails_with_bad_username(self, user):
     with pytest.raises(ValueError):
         password_matches(user, 'hunter2')