Example #1
0
<?php

include_once '../../includes/easyparliament/init.php';
include_once '../../includes/postcode.inc';
include_once 'api_functions.php';
include_once '../../../../phplib/auth.php';
$a = auth_ab64_encode(random_bytes(32));
$this_page = 'api_key';
$PAGE->page_start();
$PAGE->stripe_start();
api_key_current_message();
echo '<p>TheyWorkForYou API calls require a key, so that we can monitor usage
of the service, and provide usage stats to you.';
if ($THEUSER->loggedin()) {
    if (get_http_var('create_key')) {
        create_key(get_http_var('commercial'), get_http_var('reason'));
    }
    $db = new ParlDB();
    $q = $db->query('SELECT api_key, commercial, created, reason FROM api_key WHERE user_id=' . $THEUSER->user_id());
    $keys = array();
    for ($i = 0; $i < $q->rows(); $i++) {
        $keys[] = array($q->field($i, 'api_key'), $q->field($i, 'commercial'), $q->field($i, 'created'), $q->field($i, 'reason'));
    }
    if ($keys) {
        echo '<h3>Your keys</h3> <ul>';
    }
    foreach ($keys as $keyarr) {
        list($key, $commercial, $created, $reason) = $keyarr;
        echo '<li><span style="font-size:200%">' . $key . '</span><br><span style="color: #666666;">';
        if ($commercial == 1) {
            echo 'Commercial key';
Example #2
0
$this_page = 'api_key';
$PAGE->page_start();
$PAGE->stripe_start();
?>

<h3>About API Keys</h3>
<p>TheyWorkForYou API calls require a key, so that we can monitor usage
of the service, and provide usage stats to you. Please see <a href="/api">the
API overview</a> for how to use your key.<br/><br/>

<?php 
if ($THEUSER->loggedin()) {
    if (get_http_var('create_key') && get_http_var('reason')) {
        $estimated_usage = (int) get_http_var('estimated_usage');
        $commercial = get_http_var('commercial');
        create_key($commercial, get_http_var('reason'), $estimated_usage);
        if ($commercial == '1' || $estimated_usage > 50000) {
            echo '<p><strong>It looks like your usage may fall outside of our free-of-charge bracket: if that\'s the case, this key might get blocked, so we\'d advise you to email us at <a href="*****@*****.**">enquiries@mysociety.org</a> to discuss licensing options.</strong></p>';
        }
    }
    $db = new ParlDB();
    $q = $db->query('SELECT api_key, commercial, created, reason, estimated_usage FROM api_key WHERE user_id=' . $THEUSER->user_id());
    $keys = array();
    for ($i = 0; $i < $q->rows(); $i++) {
        $keys[] = array($q->field($i, 'api_key'), $q->field($i, 'commercial'), $q->field($i, 'created'), $q->field($i, 'reason'), $q->field($i, 'estimated_usage'));
    }
    if ($keys) {
        echo '<h3>Your keys</h3> <ul>';
    }
    foreach ($keys as $keyarr) {
        list($key, $commercial, $created, $reason, $estimated_usage) = $keyarr;
Example #3
0
<?php

define('SESS_ROOT', __DIR__ . '/../');
require_once SESS_ROOT . 'main.php';
if (!empty($_POST['salt']) && strlen($_POST['salt']) >= 16) {
    $entry = create_key($_POST['salt']);
    if ($entry) {
        header('Content-type: text/plain; charset=UTF-8');
        print json_encode($entry);
    } else {
        header('HTTP/1.1 403 Forbidden');
        print json_encode(['error' => 'no-session']);
    }
} else {
    header('HTTP/1.1 403 Forbidden');
    print json_encode(['error' => 'no-request']);
}