I'm struggling with getting/understanding the best approach for using
the authentication tools that come with Django.  I'm taking the
approach of writing my own form and my own view.  My form displays and
accepts input, but I'm not getting expected results once the "login"
button is clicked.  I'm sure I'm just not doing something exactly
right...

urls.py line:
(r'^accounts/login/$', login_page),
******************************************************
views.py line:
def login_page(request):
        if request.method == 'POST':
                form = LoginForm(request.POST)
                if form.is_valid():
                        username = form.cleaned_data['email']
                        password = form.cleaned_data['password']
                        user = authenticate(username=username, 
password=password)
                        if user is not None:
                                if user.is_active:
                                        login(request, user)
                                else:
                                        raise forms.ValidationError("Inactive 
user.")
                        else:
                                raise forms.ValidationError("Invalid login 
credentials.")
        else:
                form = LoginForm()
        variables = RequestContext(request, {'form': form})
        return render_to_response('accounts/login.html', variables)
******************************************************
forms.py:
from django import forms
from django.contrib.auth.models import User

class LoginForm(forms.Form):
        email           = forms.CharField(label=u'Email Address')
        password        = forms.CharField(
                label=u'Password',
                widget=forms.PasswordInput()
        )
******************************************************

So when I go to the form url in the browser, I punch in some
information and click "login".  I see the exception for invalid
credentials.  What I'm not sure is...

Should I be raising an exception?
What is the correct way to inform of bad credentials?

I was looking at this url as inspiration:
http://docs.djangoproject.com/en/1.2/topics/auth/#authentication-in-web-requests

Can someone help guide me towards my obvious blunder?  (and maybe give
this beginner some pointers on custom auth views/forms vs using
default?)

Thank you,
Jeremiah

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to