Django, overriding “is_authenticated()” when we have Email instead of username
-
15-06-2021 - |
Frage
I'm using the django-email-as-username
app for using email rather than username for authentication, and it works like a charm.
Now, in view I want to call
if request.user.is_authenticated()
but this method just authenticate users based upon (username+password) and not (email+password). How should I deal with this ?
Any suggestion ?
Lösung
In Django the is_authenticated()
always returns True
for User
instances and always returns False
for AnonymousUser
instances. It has nothing to do with username/password/email and django-email-as-username
does not change this behaviour.
See the Django's source code:
# In User class line 279
def is_authenticated(self):
"""
Always return True. This is a way to tell if the user has been
authenticated in templates.
"""
return True
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow