在TG1中,您可以通过执行以下操作来更改登录的用户:
identity.set_current_identity(identity)在TG2中有可能做类似的事情吗?看起来repoze.who应该提供类似的东西,但我似乎找不到神奇的词。
或者,除了通常的要求登录和密码,然后将数据提交给/login_handler的方法之外,他们还提供了关于如何以任何方式使用repoze.who的任何文档。处理login_handler的代码在哪里?
谢谢!
发布于 2011-07-10 01:09:19
您可以使用标识符来记住新用户。默认情况下,在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:
passhttps://stackoverflow.com/questions/4576486
复制相似问题