Take a look at the docs here:
https://docs.djangoproject.com/en/dev/ref/authbackends/
Here's an example of an auth backend that takes email/password instead of username/password:
https://github.com/dabapps/django-email-as-username/blob/master/emailusernames/backends.py
Hope that helps.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/csl1KBONlr4J.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Hi, i've an authenticate problem with Django 1.5
All informations are herehttp://stackoverflow.com/questions/13883539/authenticate-with-django-1-5 but i'll resume the situation :
I've a custum user model which looks like :
class User(AbstractBaseUser):
email = models.EmailField(unique=True)
activation_key = models.CharField(max_length=255)
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'username'
With a form, i can register users, and all is correct.
Now, i'd like to log the registred user with :
class LoginForm(forms.Form):
email = forms.EmailField()
password = forms.CharField(
label="Password",
widget=forms.PasswordInput()
)
The corresponding view is :
def login(request):
form = LoginForm()
if request.method == 'POST':
form = LoginForm(request.POST)
email = request.POST['email']
password = request.POST['password']
user = authenticate(username=email, password=password)
if user is not None:
if user.is_active:
login(user)
else:
message = 'disabled account, check validation email'
return render(
request,
'account-login-failed.html',
{'message': message}
)
return render(request, 'account-login.html', {'form': form})
The probleme is that user = authenticate(username=email, password=password) gives me None as return.
According to the doc, authenticate takes an usersname, not an email as arg. But how can i use authenticate because my User model desn't support Username.
Is there a solution with Django 1.5 ?