Esempio n. 1
0
 def test_backend_login(self):
     """ test if authenticates using the backend """
     from helios_auth.auth_systems.ldapbackend import backend
     auth = backend.CustomLDAPBackend()
     user = auth.authenticate(None,
                              username=self.username,
                              password=self.password)
     self.assertEqual(user.username, 'euclid')
Esempio n. 2
0
def ldap_login_view(request):
    from helios_auth.view_utils import render_template
    from helios_auth.views import after
    from helios_auth.auth_systems.ldapbackend import backend

    error = None

    if request.method == "GET":
        form = LoginForm()
    else:
        form = LoginForm(request.POST)

        request.session['auth_system_name'] = 'ldap'

        if request.POST.has_key('return_url'):
            request.session['auth_return_url'] = request.POST.get('return_url')

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

            auth = backend.CustomLDAPBackend()
            user = auth.authenticate(None,
                                     username=username,
                                     password=password)

            if user:
                request.session['ldap_user'] = {
                    'username': user.username,
                    'email': user.email,
                    'name': user.first_name + ' ' + user.last_name,
                }
                return HttpResponseRedirect(reverse(after))
            else:
                error = 'Bad Username or Password'

    return render_template(
        request, 'ldapauth/login', {
            'form': form,
            'error': error,
            'enabled_auth_systems': settings.AUTH_ENABLED_AUTH_SYSTEMS,
        })