开发者

Turbogears change user via function calls

In TG1, you could change the logged in user by doing something like:

identity.set_current_identity(identity)

Is it possible to do something similar in TG2? It seems like repoze.who should provide something similar, but I can't seem to find the magic words.

Alternatively, is their any documentation on how to use repoze.who in any way other than the usual approach of asking for a login and password, and then submitting that data to /login_handler. Where is the code that processe开发者_如何学Cs login_handler?

Thanks!


You can use the identifier to remember a new user. By default in TurboGears2 users are identified by their username, so you can switch them using the username.

def force_user(user_name):
    request = tg.request
    response = tg.response

    request.cookies.clear()
    authentication_plugins = request.environ['repoze.who.plugins']
    identifier = authentication_plugins['main_identifier']

    try:
        response.headers = identifier.remember(request.environ, {'repoze.who.userid':user_name})
    except:
        pass
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜