Esempio n. 1
0
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
Esempio n. 2
0
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()
Esempio n. 3
0
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)
Esempio n. 4
0
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()
Esempio n. 5
0
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)
Esempio n. 6
0
def missing_auth(handler: ZoeRequestHandler):
    """Redirect to login page."""
    handler.redirect(handler.get_argument('next', u'/login'))