reg/forms.py
changeset 7 af9ab5ad2786
parent 6 057498d12450
child 8 e2699e042129
equal deleted inserted replaced
6:057498d12450 7:af9ab5ad2786
     1 import string
     1 import string
     2 
     2 
       
     3 from django import forms
     3 from django.contrib.auth.models import User
     4 from django.contrib.auth.models import User
     4 from django import forms
       
     5 
       
     6 from django.contrib.auth import authenticate
     5 from django.contrib.auth import authenticate
     7 
     6 
     8 from workshop.reg.models import Profile
     7 from workshop.reg.models import Profile
     9 
     8 
    10 class LoginForm(forms.Form):
     9 class LoginForm(forms.Form):
    45     class Meta:
    44     class Meta:
    46         model = Profile
    45         model = Profile
    47         fields = ['email', 'password', 'confirm_password', 'first_name', 'last_name', 'gender', 'profession', 'affiliated_to', 'interests']
    46         fields = ['email', 'password', 'confirm_password', 'first_name', 'last_name', 'gender', 'profession', 'affiliated_to', 'interests']
    48 
    47 
    49     def clean_email(self):
    48     def clean_email(self):
       
    49         """ check if a user exists with same email.
       
    50         """
       
    51 
    50         email = self.cleaned_data['email']
    52         email = self.cleaned_data['email']
    51         try:
    53         try:
    52             User.objects.get(email__iexact=email)
    54             User.objects.get(email__iexact=email)
    53             raise forms.ValidationError("An account already exists with this email.\
    55             raise forms.ValidationError("An account already exists with this email.\
    54                                         Click on forgot password if you have forgotten your password")
    56                                         Click on forgot password if you have forgotten your password")
    55         except User.DoesNotExist:
    57         except User.DoesNotExist:
    56             return email
    58             return email
    57 
    59 
    58     def clean_password(self):
    60     def clean_password(self):
       
    61         """ check if the password contains only alphabets or digits or punctuation.
       
    62         then check if the size of the password is optimal.
       
    63         then check if both the given passwords match.
       
    64         """
       
    65 
    59         password = self.cleaned_data['password']
    66         password = self.cleaned_data['password']
    60 
    67 
    61         if password.strip(string.ascii_letters+string.punctuation+string.digits):
    68         if password.strip(string.ascii_letters+string.punctuation+string.digits):
    62             raise forms.ValidationError("Only alphabets, digits and punctuation symbols are allowed in password")
    69             raise forms.ValidationError("Only alphabets, digits and punctuation symbols are allowed in password")
    63 
    70