login and logout works .
from django.contrib.auth.models import User
from django import forms
from django.contrib.auth import authenticate
class LoginForm(forms.Form):
""" a form to handle login.
"""
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput)
def clean_email(self):
""" see if a user exists for this email.
"""
email = self.cleaned_data['email']
password = self.data['password']
try:
username = User.objects.get(email__iexact=email).username
except User.DoesNotExist:
raise forms.ValidationError("Incorrect e-mail or password")
user = authenticate(username=username, password=password)
if not user:
raise forms.ValidationError("Incorrect e-mail or password")
return email