Commits

Maarten Draijer  committed c15916d

Fix NoneType bug when logging in without entering an email address and make both email and password fields required.

  • Participants
  • Parent commits 597732d

Comments (0)

Files changed (1)

File email_login/forms.py

     """
     Form for authenticating users by their email address.
     """
-    email = forms.EmailField(label=_("Email address"))
-    password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
+    email = forms.EmailField(label=_("Email address"), required=True)
+    password = forms.CharField(label=_("Password"), required=True, widget=forms.PasswordInput)
 
     def __init__(self, request=None, *args, **kwargs):
         """
         super(EmailAuthenticationForm, self).__init__(*args, **kwargs)
 
     def clean(self):
-        email = self.cleaned_data.get('email').lower()
+        email = self.cleaned_data.get('email')
         password = self.cleaned_data.get('password')
 
         if email and password:
-            self.user_cache = authenticate(email=email, password=password)
+            self.user_cache = authenticate(email=email.lower(), password=password)
             if self.user_cache is None:
                 raise forms.ValidationError(_("Please enter a correct email address and password."))
             elif not self.user_cache.is_active:
     class Meta:
         model = User
         fields = ("email",)
-        
+
     def clean_email(self):
         """ Validates that the email address is not already in use. """
         email = self.cleaned_data["email"].lower()
         except User.DoesNotExist:
             return email
         raise forms.ValidationError(_("A user with that email address already exists."))
-    
+
     def clean_password2(self):
         password1 = self.cleaned_data.get("password1", "")
         password2 = self.cleaned_data["password2"]
         if password1 != password2:
             raise forms.ValidationError(_("The two password fields didn't match."))
         return password2
-        
+
     def save(self, commit=True):
         user = super(EmailUserCreationForm, self).save(commit=False)
         user.username = email_to_username(user.email)
         f = self.fields.get('user_permissions', None)
         if f is not None:
             f.queryset = f.queryset.select_related('content_type')
-            
+
     def save(self, commit=True):
         user = super(EmailUserChangeForm, self).save(commit=False)
         user.username = email_to_username(user.email)
         if commit:
             user.save()
-        return user
+        return user