sdi/forms.py
branchanoop
changeset 68 b0e630caa6e6
parent 56 7dfacad8adee
child 71 c736873f35cb
equal deleted inserted replaced
67:b9690fbf78af 68:b0e630caa6e6
     1 from django import forms
     1 from django import forms
       
     2 from django.contrib.auth import authenticate
     2 
     3 
     3 from sage_days.sdi.models import Registrant, TOPICS_CHOICES
     4 from sage_days.sdi.models import Registrant, TOPICS_CHOICES
     4 from captcha.fields import CaptchaField
     5 from captcha.fields import CaptchaField
     5 
     6 
     6 class RegisterForm(forms.ModelForm):
     7 class RegisterForm(forms.ModelForm):
   145         emails = self.cleaned_data['emails']
   146         emails = self.cleaned_data['emails']
   146 
   147 
   147         to_emails = [csv_list.split(',') for csv_list in emails.split()]
   148         to_emails = [csv_list.split(',') for csv_list in emails.split()]
   148         return to_emails
   149         return to_emails
   149 
   150 
       
   151 class LoginForm(forms.form):
       
   152     """ login form.
       
   153     """
       
   154 
       
   155     username = forms.CharField()
       
   156     password = forms.CharField(widget=forms.PasswordInput)
       
   157 
       
   158     def clean_username(self):
       
   159         username = self.cleaned_data['username']
       
   160         password = self.clean_password()
       
   161 
       
   162         if not authenticate(username=username, password=password):
       
   163             raise forms.ValidationError("Invalid username or password")
       
   164 
       
   165         return username
       
   166 
       
   167     def clean_password(self):
       
   168         return self.cleaned_data['password']