當前位置: 首頁>>代碼示例>>Python>>正文


Python handlers.cookie2user方法代碼示例

本文整理匯總了Python中handlers.cookie2user方法的典型用法代碼示例。如果您正苦於以下問題:Python handlers.cookie2user方法的具體用法?Python handlers.cookie2user怎麽用?Python handlers.cookie2user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在handlers的用法示例。


在下文中一共展示了handlers.cookie2user方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: auth_factory

# 需要導入模塊: import handlers [as 別名]
# 或者: from handlers import cookie2user [as 別名]
def auth_factory(app, handler):
    @asyncio.coroutine
    def auth(request):
        logging.info('check user: %s %s' % (request.method, request.path))
        request.__user__ = None  # ?????__user__????None
        cookie_str = request.cookies.get(COOKIE_NAME)  # ??cookie?????cookie????COOKIE_NAME??headlers??????
        if cookie_str:
            user = yield from cookie2user(cookie_str)  # ??cookie????????
            if user:
                logging.info('set current user: %s' % user.email)
                request.__user__ = user  # ???????????
        # ???????????????????????????????
        if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
            return web.HTTPFound('/signin')
        return (yield from handler(request))
    return auth

# ????????POST????????? 
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:20,代碼來源:app.py

示例2: auth_factory

# 需要導入模塊: import handlers [as 別名]
# 或者: from handlers import cookie2user [as 別名]
def auth_factory(app, handler):
    '''
    middleware(???)???cookie?????????
    '''
    async def auth(request):
        logging.info('check user: %s %s' % (request.method, request.path))
        request.__user__ = None
        cookie_str = request.cookies.get(COOKIE_NAME)
        if cookie_str:
            # ??cookie???????????
            user = await cookie2user(cookie_str)
            if user:
                logging.info('set current user:%s' % user.email)
                request.__user__ = user
        if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
            # HTTPFound: Exception->HTTPRedirection->302
            return web.HTTPFound('/signin')
        return (await handler(request)) 
    return auth 
開發者ID:chenpengcong,項目名稱:python3-webapp,代碼行數:21,代碼來源:app.py

示例3: auth_factory

# 需要導入模塊: import handlers [as 別名]
# 或者: from handlers import cookie2user [as 別名]
def auth_factory(app,handler):
	async def auth(request):
		request.__user__ = None
		cookie_str = request.cookies.get(COOKIE_NAME)
		if cookie_str:
			user = await cookie2user(cookie_str)
			if user:
				logging.info('set current user :%s' % user.email)
				request.__user__ = user
		if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
			return web.HTTPFound('/signin')
		return	await handler(request)
	return auth

# ?????? 
開發者ID:syusonn,項目名稱:awesome-python3-webapp,代碼行數:17,代碼來源:app.py

示例4: auth_factory

# 需要導入模塊: import handlers [as 別名]
# 或者: from handlers import cookie2user [as 別名]
def auth_factory(app, handler):
    @asyncio.coroutine
    def auth(request):
        logging.info('check user: {} {}'.format(request.method, request.path))
        request.__user__ = None
        cookie_str = request.cookies.get(COOKIE_NAME)
        if cookie_str:
            user = yield from cookie2user(cookie_str)
            if user:
                logging.info('set current user: {}'.format(user.email))
                request.__user__ = user
        if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
            return web.HTTPFound('/signin')
        return (yield from handler(request))
    return auth 
開發者ID:tianzhenyun,項目名稱:python-awesome-web,代碼行數:17,代碼來源:app.py

示例5: auth_factory

# 需要導入模塊: import handlers [as 別名]
# 或者: from handlers import cookie2user [as 別名]
def auth_factory(app, handler):
	async def auth(request):
		logging.info('check user: %s %s' % (request.method, request.path))
		request.__user__ = None
		cookie_str = request.cookies.get(COOKIE_NAME)
		if cookie_str:
			user = await cookie2user(cookie_str)
			if user:
				logging.info('set current user: %s' % user.email)
				request.__user__ = user
		if request.path.startswith('/manage/') and (request.__user__ is None or not request.__user__.admin):
			return web.HTTPFound('/signin')
		return (await handler(request))
	return auth 
開發者ID:TsangTen,項目名稱:awesome-webapp,代碼行數:16,代碼來源:app.py


注:本文中的handlers.cookie2user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。