test_sessionauthenticate.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:watcher 作者: nosmokingbandit 项目源码 文件源码
def setup_server():

        def check(username, password):
            # Dummy check_username_and_password function
            if username != 'test' or password != 'password':
                return 'Wrong login/password'

        def augment_params():
            # A simple tool to add some things to request.params
            # This is to check to make sure that session_auth can handle
            # request params (ticket #780)
            cherrypy.request.params["test"] = "test"

        cherrypy.tools.augment_params = cherrypy.Tool(
            'before_handler', augment_params, None, priority=30)

        class Test:

            _cp_config = {
                'tools.sessions.on': True,
                'tools.session_auth.on': True,
                'tools.session_auth.check_username_and_password': check,
                'tools.augment_params.on': True,
            }

            @cherrypy.expose
            def index(self, **kwargs):
                return "Hi %s, you are logged in" % cherrypy.request.login

        cherrypy.tree.mount(Test())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号