Turbogears通过函数调用改变用户

2024-05-18 08:19:05 发布

您现在位置:Python中文网/ 问答频道 /正文

在TG1中,您可以通过执行以下操作来更改登录用户:

identity.set_current_identity(identity)

有没有可能在TG2中做类似的事情?看起来好像休息。谁应该提供一些类似的东西,但我似乎找不到神奇的词。在

或者,他们是否有关于如何使用的文档休息。谁以任何方式,而不是通常的方法,即请求登录名和密码,然后将数据提交给/login_处理程序。处理登录处理程式的程式码在哪里?在

谢谢!在


Tags: 数据方法用户文档处理程序密码方式login
1条回答
网友
1楼 · 发布于 2024-05-18 08:19:05

您可以使用标识符来记住新用户。默认情况下,在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

相关问题 更多 >