Ejemplo n.º 1
0
 public function put_login()
 {
     $auth = API::post(array('auth', 'login'), Input::all());
     if ($auth->code == 400) {
         return Redirect::to(prefix('admin') . 'auth/login')->with('errors', new Messages($auth->get()))->with_input('except', array());
     }
 }
Ejemplo n.º 2
0
<?php

require 'common.php';
require '../includes/classes/API.php';
header("Access-Control-Allow-Origin: *");
$sql->options['error_handling'] = 'die';
$api = new API();
$api->post('/donation/add', function () {
    global $QUERY;
    if (isset($QUERY['created_at']) and $QUERY['created_at']) {
        $QUERY['created_at'] = date("Y-m-d", strtotime($QUERY['created_at']));
    } else {
        $QUERY['created_at'] = date('Y-m-d H:i:s');
    }
    if (isset($QUERY['donation_type']) and $QUERY['donation_type'] == 'gg') {
        $QUERY['donation_type'] = 'globalgiving';
    }
    $donations = new Donation();
    $donation_id = $donations->add($QUERY);
    if ($donation_id) {
        showSuccess("Donation inserted succesfully : Donation ID '.{$donation_id}.'", array("donation" => array("id" => $donation_id)));
    } else {
        showError("Failure in insterting dontaion at server. Try again after some time.");
    }
});
$api->get('/donation/get_donations_for_approval/{poc_id}', function ($poc_id) {
    $donation = new Donation();
    $donations_for_approval = $donation->getDonationsForApproval($poc_id);
    if ($donations_for_approval) {
        showSuccess(count($donations_for_approval) . " donation(s) waiting for approval", array('donations' => $donations_for_approval));
    } else {
        $error = $donation->error;
Ejemplo n.º 3
0
 public function testListWithPaginate()
 {
     $test = new API($this);
     for ($i = 1; $i <= 10; $i++) {
         $test->post('/posts', '{"user_id":"1","category_id":"1","content":"#' . $i . '"}');
         $test->expect(4 + $i);
     }
     $test->get('/posts?page=2,2&order=id');
     $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[["5","1","1","#1"],["6","1","1","#2"]],"results":12}}');
 }
Ejemplo n.º 4
0
 public function testErrorOnFailingForeignKeyConstraint()
 {
     $test = new API($this);
     $test->post('/posts', '{"user_id":"3","category_id":"1","content":"fk constraint"}');
     $test->expect('null');
 }
Ejemplo n.º 5
0
// Load Composer autoload file
include "../vendor/autoload.php";
$platforms = ["oauth1" => ["twitter"], "oauth2" => ["facebook"]];
$fakeSessionID = "fakesessionid";
$http = new API();
if (isset($_GET["platform"])) {
    $platform = $_GET["platform"];
    // If OAuth 1 use oauth_token + oauth_verifier
    if (in_array($platform, $platforms["oauth1"])) {
        $code = "{$_GET["oauth_token"]}:{$_GET["oauth_verifier"]}";
        // If OAuth 2 use code + state
    } else {
        $code = "{$_GET["code"]}:{$_GET["state"]}";
    }
    $authDetails = $http->post("/v1/auth/social", ["session_id" => $fakeSessionID, "code" => $code, "platform" => $platform]);
    if ($authDetails) {
        $auth = $http->post("/v1/auth", ["client_id" => "oauthclientid", "client_secret" => "blahblahblah", "grant_type" => "password", "username" => $authDetails->user_id, "password" => $authDetails->token]);
    }
    var_dump($auth);
} else {
    $socialLoginUrls = $http->get("/v1/auth/social/urls", ["session_id" => $fakeSessionID]);
    ?>

    <h1>Logins</h1>

    <ul>
    <?php 
    foreach ($socialLoginUrls as $platform => $url) {
        ?>
        <li><a href="<?php 
Ejemplo n.º 6
0
        if ($value != $expected) {
            failed("{$testName} - Expected '{$expected}', Got: '{$value}'");
        } else {
            logMessage("  Passed: {$testName} - value '{$value}'");
        }
    }
}
$API = new API();
echo "\nStarting Tests...\n";
$Warren = array('firstname' => 'Warren', 'lastname' => 'Sharpe', 'address' => '890 Fake Street', 'city' => 'Dennington', 'state' => 'Victoria', 'postcode' => 3280);
$Bradly = array('firstname' => 'Bradly', 'lastname' => 'Sharpe', 'address' => '123 Fake Street', 'city' => 'Dennington', 'state' => 'Victoria', 'postcode' => 3280);
$Car = array('owner' => null, 'make' => 'Holden Commodore', 'model' => 'VE Wagon', 'registration' => rand(100, 999) . 'XYZ');
/*
 Create Customer - Warren
*/
$result = $API->post('customer', $Warren, "Creating Warren");
if ($result->error) {
    failed("Didn't return customer: " . $result->message . "\n" . json_encode($result->data));
}
foreach ($Warren as $key => $value) {
    $API->test($result->data->{$key}, $value, $key);
}
$Warren['id'] = $result->data->id;
/*
 Create Customer - Bradly
*/
$result = $API->post('customer', $Bradly, "Creating Bradly");
if ($result->error) {
    failed("Didn't return customer: " . $result->message . "\n" . json_encode($result->data));
}
foreach ($Bradly as $key => $value) {
Ejemplo n.º 7
0
/* API root
 **********************************************************************************************************************/
$app->get('/', function () use($app) {
    $app->render_json(["message" => "SoccerWars API v0.1"]);
});
/* Check login credentials
 **********************************************************************************************************************/
$app->post('/login', function () use($app) {
    $data = json_decode($app->request->getBody(), true);
    if ($user_id = User::Login($data['email'], $data['password'])) {
        $user = User::Get($user_id);
        // Activate account if it's the first login and forbid inactive accounts
        if ($user->status == 'pending') {
            $user->setStatus('active');
        } else {
            if ($user->status != 'active') {
                throw new Exception("This account is not active", 401);
            }
        }
        // Return data
        $app->render_json(['name' => $user->name, 'avatar' => $user->avatar, 'token' => $user->getToken()]);
    } else {
        throw new Exception("Invalid credentials", 401);
    }
});
/* Password reset
 **********************************************************************************************************************/
$app->post('/login/reset', function () use($app) {
    $data = json_decode($app->request->getBody(), true);
    $email = $data['email'];
    $captcha = $data['captcha'];
    if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {