Adding email lookup to forgot password flow.

This commit is contained in:
Samuel Clay 2013-01-05 10:23:44 -08:00
parent 2792ccd076
commit cbd99b7462

View file

@ -9,20 +9,33 @@ class Command(BaseCommand):
)
def handle(self, *args, **options):
username = options['username']
username = options.get('username')
email = options.get('email')
user = None
try:
user = User.objects.get(username__icontains=username)
except User.MultipleObjectsFound:
user = User.objects.get(username__iexact=username)
except User.DoesNotExist:
user = User.objects.get(email__icontains=username)
except User.DoesNotExist:
print " ---> No user/email found at: %s" % username
if username:
try:
user = User.objects.get(username__icontains=username)
except User.MultipleObjectsFound:
user = User.objects.get(username__iexact=username)
except User.DoesNotExist:
user = User.objects.get(email__iexact=username)
except User.DoesNotExist:
print " ---> No user found at: %s" % username
elif email:
try:
user = User.objects.get(email__icontains=email)
except User.MultipleObjectsFound:
user = User.objects.get(email__iexact=email)
except User.MultipleObjectsFound:
users = User.objects.filter(email__iexact=email)
user = users[0]
except User.DoesNotExist:
print " ---> No email found at: %s" % email
if user:
email = options.get("email") or user.email
user.profile.send_forgot_password_email(email)
else:
print " ---> No user/email found at: %s/%s" % (username, email)