Turbogears change user through function calls

In TG1, you can change the registered user by doing something like:

identity.set_current_identity(identity)

Is it possible to do something like this in TG2? It seems repoze.who should provide something like this, but I cannot find the magic words.

Alternatively, is there any documentation on how to use repoze.who in any way other than the usual approach, asking for a username and password, and then sending this data to / login _handler. Where is the code handling login_handler?

Thank!

+3
source share
1 answer

. TurboGears2 , .

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
+3

Source: https://habr.com/ru/post/1783042/


All Articles