class BaseHandler(RequestHandler):
async def get_current_user_async(self):
session_hash = self.get_secure_cookie("session_hash")
return session_hash
def authenticated_async(method):
@functools.wraps(method)
async def wrapper(self, *args, **kwargs):
if not await self.get_current_user_async():
if self.request.method in ("GET", "HEAD"):
url = self.get_login_url()
if "?" not in url:
if urlparse.urlsplit(url).scheme:
# if login url is absolute, make next absolute too
next_url = self.request.full_url()
else:
next_url = self.request.uri
url += "?" + urlencode(dict(expired=next_url))
self.redirect(url)
return
raise HTTPError(403)
return await method(self, *args, **kwargs)
return wrapper