-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new authentication backend for case-insensitive emails #31
Changes from 1 commit
c367c8a
2353bcb
999786e
23ec089
50aa976
70f8804
bfd7dd6
4ab3445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.contrib.auth.backends import ModelBackend | ||
|
||
|
||
class CaseInsensitiveEmailBackend(ModelBackend): | ||
""" | ||
This authentication backend assumes that usernames are email addresses and simply lowercases | ||
a username before an attempt is made to authenticate said username using Django's ModelBackend. | ||
|
||
Example usage: | ||
# In settings.py | ||
AUTHENTICATION_BACKENDS = ('authtools.backends.CaseInsensitiveEmailBackend',) | ||
""" | ||
def authenticate(self, username=None, password=None): | ||
username = username.lower() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I think this is going to raise an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This would require that a username is passed in. |
||
|
||
return super(CaseInsensitiveEmailBackend, self).authenticate( | ||
username=username, | ||
password=password | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an app that requires me to pass in the request to the authenticate calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rockymeza Are you saying this because of the method signature?
If so, django handles the
TypeError
https://github.com/django/django/blob/master/django/contrib/auth/__init__.py#L69There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He wants the
lower()
to be called, though, so this should just be changed to be**credentials
instead.