Commits

Tino de Bruijn  committed 7007d0e

Fix issue #3. All email will be saved lowercase, and lookups are iexact.

  • Participants
  • Parent commits 811b0f7

Comments (0)

Files changed (3)

File email_login/auth_backend.py

     
     def authenticate(self, email=None, password=None):
         try:
-            user = User.objects.get(email=email)
+            user = User.objects.get(email__iexact=email.lower())
             if user.check_password(password):
                 return user
         except User.DoesNotExist:

File email_login/forms.py

 from django.utils.translation import ugettext_lazy as _
 
 def email_to_username(email):
-    return base64.urlsafe_b64encode(hashlib.sha256(email).digest())[:30]
+    return base64.urlsafe_b64encode(hashlib.sha256(email.lower()).digest())[:30]
 
 class EmailAuthenticationForm(forms.Form):
     """
         super(EmailAuthenticationForm, self).__init__(*args, **kwargs)
 
     def clean(self):
-        email = self.cleaned_data.get('email')
+        email = self.cleaned_data.get('email').lower()
         password = self.cleaned_data.get('password')
 
         if email and password:
             self.user_cache = authenticate(email=email, password=password)
             if self.user_cache is None:
-                raise forms.ValidationError(_("Please enter a correct email address and password. Note that both fields are case-sensitive."))
+                raise forms.ValidationError(_("Please enter a correct email address and password."))
             elif not self.user_cache.is_active:
                 raise forms.ValidationError(_("This account is inactive."))
         self.check_for_test_cookie()
         
     def clean_email(self):
         """ Validates that the email address is not already in use. """
-        email = self.cleaned_data["email"]
+        email = self.cleaned_data["email"].lower()
         try:
-            User.objects.get(email=email)
+            User.objects.get(email__iexact=email)
         except User.DoesNotExist:
             return email
         raise forms.ValidationError(_("A user with that email address already exists."))
 
 class EmailUserChangeForm(forms.ModelForm):
     email = forms.EmailField(label=_("Email address"))
+
     class Meta:
         model = User
         exclude = ('username',)

File email_login/locale/nl/LC_MESSAGES/django.po

 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-12-28 17:41+0100\n"
+"POT-Creation-Date: 2012-04-02 16:35+0200\n"
 "PO-Revision-Date: 2010-12-28 13:53+0100\n"
 "Last-Translator: Tino de Bruijn <tinodb@gmaill.com>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
-#: forms.py:11 forms.py:57 forms.py:91 templates/email_login/login.html:33
+#: forms.py:16 forms.py:62 forms.py:96 templates/email_login/login.html:33
 msgid "Email address"
 msgstr "Emailadres"
 
-#: forms.py:12 forms.py:58 templates/email_login/login.html:37
+#: forms.py:17 forms.py:63 templates/email_login/login.html:37
 msgid "Password"
-msgstr ""
+msgstr "Wachtwoord"
 
-#: forms.py:32
-msgid ""
-"Please enter a correct email address and password. Note that both fields are "
-"case-sensitive."
-msgstr ""
-"Vul een juist emailadres en wachtwoord in. Beide velden zijn hoofdletter-"
-"gevoelig."
+#: forms.py:37
+#, fuzzy
+msgid "Please enter a correct email address and password."
+msgstr "Vul een juist emailadres en wachtwoord in."
 
-#: forms.py:34
+#: forms.py:39
 msgid "This account is inactive."
 msgstr "Dit account is in-actief "
 
-#: forms.py:41
+#: forms.py:46
 msgid ""
 "Your Web browser doesn't appear to have cookies enabled. Cookies are "
 "required for logging in."
 msgstr ""
 
-#: forms.py:59
+#: forms.py:64
 msgid "Password confirmation"
 msgstr ""
 
-#: forms.py:60
+#: forms.py:65
 msgid "Enter the same password as above, for verification."
 msgstr ""
 
-#: forms.py:73
+#: forms.py:78
 msgid "A user with that email address already exists."
 msgstr "Een gebruiker met dat emailadres bestaat al."
 
-#: forms.py:79
+#: forms.py:84
 msgid "The two password fields didn't match."
 msgstr ""