Пример #1
0
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,
        },
    )
Пример #2
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))
Пример #3
0
def password_matches(username, password):
    """Returns True if the password matches the user account given"""

    validators.validate_username(username)
    validators.validate_password(username, password, strength_check=False)

    if not validators.user_exists(username):
        raise ValueError("User doesn't exist")

    cmd = 'kinit --no-forwardable -l0 {}@OCF.BERKELEY.EDU'.format(username)
    child = pexpect.spawn(cmd, timeout=10)

    child.expect("{}@OCF.BERKELEY.EDU's Password:".format(username))
    child.sendline(password)

    child.expect(pexpect.EOF)
    child.close()

    return child.exitstatus == 0
Пример #4
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,
        },
    )
Пример #5
0
def password_matches(username, password):
    """Returns True if the password matches the user account given"""

    validators.validate_username(username)
    validators.validate_password(username, password, strength_check=False)

    if not validators.user_exists(username):
        raise ValueError("User doesn't exist")

    cmd = 'kinit --no-forwardable -l0 {}@OCF.BERKELEY.EDU'.format(username)
    child = pexpect.spawn(cmd, timeout=10)

    child.expect("{}@OCF.BERKELEY.EDU's Password:".format(username))
    child.sendline(password)

    child.expect(pexpect.EOF)
    child.close()

    return child.exitstatus == 0
Пример #6
0
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
def login(request, user):
    """Log in a user. Doesn't do any kind of password validation (obviously)."""
    assert user_exists(user)
    request.session['ocf_user'] = user
Пример #8
0
 def test_exists(self, username):
     assert user_exists(username)
Пример #9
0
 def test_exists(self, username):
     assert user_exists(username)