Question

I have a working repoze.who/what setup (on a Pylons app). I now want to automatically log new users in after signup, without them having to use the login form. I've browsed the repoze.who docs and source code and, maybe I'm just missing it, but I can't find out how to set the logged-in user from code, without a new post request going through the middleware. Is this possible?

Was it helpful?

Solution

I have been with similar issue all the morning and this is what I found: You must know that right now there's two versions of repoze.who (1 and 2):

In v 1.x:

rememberer = request.environ['repoze.who.plugins']['cookie']
identity = {'repoze.who.userid': user.username}
response.headerlist = response.headerlist + \
        rememberer.remember(request.environ, identity) 

In v 2.x (it's easier because it provide and api):

from repoze.who.api import get_api

who_api = get_api(request.environ)
creds = {}
creds['login'] = yourusername
creds['password'] = yourpassword
authenticated, headers = who_api.login(creds)

Resources: For v1: http://www.deanlee.cn/programming/repoze-who-perform-login-programmatically/ For v2: http://docs.repoze.org/who/2.0/api.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top