On Sat, Dec 15, 2012 at 7:18 PM, <sebastien.mor...@gmail.com> wrote: > Hi, i've an authenticate problem with Django 1.5 > All informations are here > http://stackoverflow.com/questions/13883539/authenticate-with-django-1-5but > 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 ?
Well, no, there isn't a special Django 1.5 solution -- what you've described here (calling authenticate() with the email address as the username argument) should be all you need to do. My initial guess would be that you're not calling the right authenticate method; you haven't included your imports, but based on the fact that you're calling "login()", in a view called "login()", I'm going to guess there might be some import conflicts going on. I'd try starting in a shell trying to manually authenticate a user - if: >>> from django.contrib.auth import authenticate >>> authenticate(username='t...@example.com', password='s3kr1t') works, but your view doesn't, then the problem will be with imports. If it doesn't work, then the probably will probably be with the list of authentication backends -- I'm guessing the ModelBackend isn't being installed correctly. However, without more details, it's hard to tell. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.