Permalink
Browse files

Merge pull request #3 from coulix/master

Support for email login
  • Loading branch information...
2 parents 06fcc3c + 8970941 commit 0aa36a82ab0226085b815faea65affd2c6a3d242 @samastur committed Jul 14, 2011
Showing with 11 additions and 2 deletions.
  1. +4 −1 impostor/backend.py
  2. +7 −1 impostor/tests.py
View
@@ -36,7 +36,10 @@ def authenticate(self, username=None, password=None):
# Check if admin exists and authenticates
admin_obj = User.objects.get(username=admin)
if admin_obj.is_staff and admin_obj.check_password(password):
- auth_user = User.objects.get(username=uuser)
+ try:
+ auth_user = User.objects.get(username=uuser)
+ except User.DoesNotExist:
+ auth_user = User.objects.get(email=uuser)
if auth_user:
# Try to find request object and maybe be lucky enough to find IP address there
View
@@ -8,6 +8,7 @@
admin_username = 'real_test_admin'
admin_pass = 'admin_pass'
user_username = 'real_test_user'
+user_email = 'real@mail.com'
user_pass = 'user_pass'
class TestImpostorLogin(TestCase):
@@ -17,7 +18,7 @@ def setUp(self):
real_admin.set_password(admin_pass)
real_admin.save()
- real_user = User.objects.create(username=user_username, password=user_pass)
+ real_user = User.objects.create(username=user_username, email=user_email, password=user_pass)
real_user.set_password(user_pass)
real_user.save()
@@ -28,6 +29,11 @@ def test_login_user(self):
self.failUnlessEqual(u, real_user)
+ def test_login_user_with_email(self):
+ u = authenticate(email=user_email, password=user_pass)
+ real_user = User.objects.get(email=user_email)
+
+ self.failUnlessEqual(u, real_user)
def test_login_admin(self):
u = authenticate(username=admin_username, password=admin_pass)

0 comments on commit 0aa36a8

Please sign in to comment.