I have a Django app where there are 2 use cases where I want a user to be able to login without a password.
- User registers and gets activation link in e-mail.
- User resets password and gets link to change password form in e-mail.
The links include a one-time-use key that I validate, and then I want to log the user in without using credentials.
# This raises an exception unless
# I call user.authenticate 1st.
auth.login(request, user)
How do I acheive this?
You can write your own authentication backend(s) which handles your two use cases. See the docs on writing and using a custom auth backend:
http://docs.djangoproject.com/en/1.2/topics/auth/#other-authentication-sources
EDIT:
There seems there might be some misconception about how difficult it might be to write your own auth backend. From the docs:
That’s right. It’s any class that implements two functions both which return
Userobjects.The OP has already stated that the links contain one-time keys that he validates (and presumably has associated with the user he wishes to log in). In other words he’s already written the business logic for the backend, he would just need to convert it into an appropirate class.
Custom authentication backends can do a number of awesome things in Django 1.2 like object level permissions but they don’t have to be that complicated. Plus they stack so you can mix in your token based authentication with the default model backend or OpenID or Facebook. But in the end an auth backend is just class with two methods and I don’t see how you can call that overkill.