Ejemplo n.º 1
0
def captcha_public():
    """
    Returns the reCAPTCHA public key, or None if CAPTCHA verification
    is disabled.
    """
    if config_read_bool("captcha_disable_verification", value=False):
        return None

    return config_obj.get(_captcha_section(), 'public_key')
Ejemplo n.º 2
0
def captcha_verify(captcha_response):
    if config_read_bool("captcha_disable_verification", value=False):
        return True
    if not captcha_response:
        return False

    data = dict(secret=config_obj.get(_captcha_section(), 'private_key'),
                response=captcha_response,
                remoteip=get_address())
    response = http_post('https://www.google.com/recaptcha/api/siteverify',
                         data=data)
    captcha_validation_result = response.json()
    return captcha_validation_result['success']
Ejemplo n.º 3
0
def captcha_verify(form):
    if config_read_bool("captcha_disable_verification", value=False):
        return True
    if not form.g_recaptcha_response:
        return False

    data = dict(
        secret=config_obj.get(_captcha_section(), 'private_key'),
        response=form.g_recaptcha_response['g-recaptcha-response'],
        remoteip=get_address())
    response = http_post('https://www.google.com/recaptcha/api/siteverify', data=data)
    captcha_validation_result = response.json()
    return captcha_validation_result['success']
Ejemplo n.º 4
0
def captcha_verify(form):
    if config_read_bool("captcha_disable_verification", value=False):
        return True
    if not form.recaptcha_response_field:
        return False

    data = dict(
        privatekey=config_obj.get(_captcha_section(), 'private_key'),
        remoteip=get_address(),
        challenge=form.recaptcha_challenge_field.encode('utf-8'),
        response=form.recaptcha_response_field.encode('utf-8'))

    response = http_post('https://www.google.com/recaptcha/api/verify', data=data)
    result = response.text.splitlines()
    return result[0] == 'true'
Ejemplo n.º 5
0
def _load_resources():
    global resource_paths

    with open(os.path.join(macro.MACRO_APP_ROOT, 'build/rev-manifest.json'), 'r') as f:
        resource_paths = json.loads(f.read())


_load_resources()


def record_timing(func):
    return func


_sqlalchemy_url = config_obj.get('sqlalchemy', 'url')
if config._in_test:
    _sqlalchemy_url += '_test'
engine = meta.bind = sa.create_engine(_sqlalchemy_url, max_overflow=25, pool_size=10)
sessionmaker = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine, autocommit=True))


def connect():
    """
    Returns the current request's db connection or one from the engine.
    """
    request = get_current_request()
    if request is not None:
        return request.pg_connection
    # If there's no threadlocal request, we're probably operating in a cron task or the like.
    # Return a connection from the pool. n.b. this means that multiple calls could get different
Ejemplo n.º 6
0
def record_timing(func):
    key = 'timing.{0.__module__}.{0.__name__}'.format(func)

    @functools.wraps(func)
    def wrapper(*a, **kw):
        start = time.time()
        try:
            return func(*a, **kw)
        finally:
            delta = time.time() - start
            metric('timing', key, delta)

    return wrapper


_sqlalchemy_url = config_obj.get('sqlalchemy', 'url')
if config._in_test:
    _sqlalchemy_url += '_test'
engine = meta.bind = sa.create_engine(_sqlalchemy_url, max_overflow=25, pool_size=10)
sessionmaker = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine, autocommit=True))


def connect():
    if 'pg_connection' not in web.ctx:
        web.ctx.pg_connection = db = sessionmaker()
        try:
            # Make sure postgres is still there before issuing any further queries.
            db.execute('SELECT 1')
        except sa.exc.OperationalError:
            log_exc = web.ctx.env.get('raven.captureException', traceback.print_exc)
            log_exc()