def get_auth(handler: ZoeRequestHandler): """Try to authenticate a request.""" if handler.get_secure_cookie('zoe'): cookie_val = str(handler.get_secure_cookie('zoe')) uid, role = cookie_val[2:-1].split('.') log.debug( 'Authentication done using cookie (user {} from {} for {})'.format( uid, handler.request.remote_ip, handler.request.path)) return uid, role else: return None, None
def missing_auth(handler: ZoeRequestHandler): """Sends a 401 response that enables basic auth""" handler.set_status( 401, 'Could not verify your access level for that URL. You have to login with proper credentials.' ) handler.set_header('WWW-Authenticate', 'Basic realm="Login Required"') handler.finish()
def error_page(handler: ZoeRequestHandler, error_message: str, status: int): """Generate an error page.""" handler.set_status(status) handler.render('error.html', error=error_message)
def missing_auth(handler: ZoeRequestHandler): """Sends a 401 response that enables basic auth""" handler.set_status(401, 'Could not verify your access level for that URL. You have to login with proper credentials.') handler.set_header('WWW-Authenticate', 'Basic realm="Login Required"') handler.finish()
def missing_auth(handler: ZoeRequestHandler): """Redirect to login page.""" handler.redirect(handler.get_argument('next', u'/login'))