zoukankan      html  css  js  c++  java
  • repoze.what.plugins.quickstart调用流程解析

    repoze.what.plugins.quickstart调用流程解析
    在使用repoze.what.plugins的时候曾碰到这样的情况:
    用户A已经登录,此时用户在用户A没有关闭浏览器的情况下(即session没有失效)再次登录,显示登录成功,但登录的用户还是A而不是B,究其原因,应该是cookie中的用户A的信息没有删除。怎样才能不显式调用logout url(如果调用logout会导致页面跳转)而实现清空上一用户信息的效果?为搞清楚这一问题,就有必要探究一下repoze.what.plugins.quickstart的调用次序。
    repoze.what.plugins.quickstart setup_sql_auth调用repoze.what.middleware setup_auth 调用repoze.who.plugins.testutil make_middleware,make_middleware根据是否skip_authentication,决定是调用AuthenticationForgerMiddleware还是repoze.who.middleware的PluggableAuthenticationMiddleware,实际使用中调用的应该是PluggableAuthenticationMiddleware
    setup_sql_auth中创建cookie
    cookie = AuthTktCookiePlugin(cookie_secret, cookie_name,
                                     timeout=cookie_timeout,
                                     reissue_time=cookie_reissue_time)
    然后将cookie保存在who_args['identifiers'].append(('cookie', cookie))中。
    who_args从repoze.what.plugins.quickstart setup_sql_auth一直传递到repoze.who.middleware的PluggableAuthenticationMiddleware中。
    在PluggableAuthenticationMiddleware中通过
    iregistry, nregistry = make_registries(identifiers, authenticators,
                                                   challengers, mdproviders)
    self.name_registry = nregistry
    environ['repoze.who.plugins'] = self.name_registry
    等操作将setup_sql_auth中创建cookie保存于environ['repoze.who.plugins']['cookie']中
    AuthTktCookiePlugin的定义在repoze.who.plugins.auth_tk中,AuthTktCookiePlugin有一方法定义如下:
    # IIdentifier
        def forget(self, environ, identity):
            # return a set of expires Set-Cookie headers
            return self._get_cookies(environ, 'INVALID', 0)
    调用该forget方法即可将相关cookie清除,从而达到清除上一用户信息的目的。
    在pylons中的调用示例如下:
    def change_account(self):
            # Change another account, clear the original cookie
            if request.environ['repoze.who.plugins']['cookie']:
                headers = request.environ['repoze.who.plugins']['cookie'].forget(request.environ, None)
                response.headerlist.extend(headers)
            redirect(url('/account/login'))

  • 相关阅读:
    Windows10切换其他用户身份运行程序
    管理Windows功能
    如何暂时锁定您的键盘
    判断远程计算机基于x64或x86处理器
    复制文件而不在命令行中覆盖它们
    解决IDEA Gradle工程控制台输出乱码
    jquery 选择器、属性和CSS、文档处理、筛选、事件、动画效果
    IDEA炫酷主题推荐!(转)
    Windows 查看端口占用进程并关闭(转)
    JVM(二)--运行时数据区
  • 原文地址:https://www.cnblogs.com/Jerryshome/p/2030770.html
Copyright © 2011-2022 走看看