reg/forms.py
author nishanth
Fri, 09 Apr 2010 13:21:46 +0530
changeset 5 37e4027fba48
parent 4 ededea9ad08b
child 6 057498d12450
permissions -rw-r--r--
submit and list feedback done

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