-
-
Save rainerborene/586056 to your computer and use it in GitHub Desktop.
from django.contrib.auth.backends import ModelBackend | |
from django.contrib.auth.models import User | |
class EmailBackend(ModelBackend): | |
def authenticate(self, **credentials): | |
if 'username' in credentials: | |
return super(EmailBackend, self).authenticate(**credentials) | |
try: | |
user = User.objects.get(email=credentials.get('email')) | |
if user.check_password(credentials.get('password')): | |
return user | |
except User.DoesNotExist: | |
return None | |
on the settings.py , i created:
AUTHENTICATION_BACKENDS = (
'myAutenticate',
'django.contrib.auth.backends.ModelBackend',
)
then, i created an app named myAutenticate. After, i created the backends.py inside the folder myAutenticate and placed the that you suggested on this gist topic.
now, i'm getting the following error message: "Error importing authentication backend myAutenticat: "No module named myAutenticat"
do i miss something?
Yes, you missed the complete path of your backend. You should use the following pattern: projectname.applicationname.backends.EmailBackend
. Remember that Google is your friend ;-)
thanks dude,
Now i'm getting this(I swear I have researched this one enough on the internet before ask you ;) ):
Exception Value:
Module "goow.myAutenticate" does not define a "EmailBackend" authentication backend
Maybe you'll need:
Django Version: 1.2.5
Exception Type: ImproperlyConfigured
Exception Location: /usr/local/lib/python2.6/dist-packages/django/contrib/auth/init.py in load_backend, line 22
Python Executable: /usr/bin/python2.6
Python Version: 2.6.6
I really appreciate.
All you have to do is change the
AUTHENTICATION_BACKENDS
onsettings.py
. Read the [documentation](http://docs.djangoproject.com/en/1.3/ref/settings/#authentication-backends) for more information. Remember that you should save this file (normally named backend.py) in any Django app you want.