Пример #1
0
<?php

require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/', function () {
    echo "Welcome to the nearby API, use /docs to see the documentation.";
});
/*USER*/
$app->post('/connect/', function () use($app) {
    $email = $app->request->post("email");
    $password = $app->request->post("password");
    $db = new dbHandler();
    if ($db->connect($email, $password)) {
        $user = $db->getUserByEmail($email);
        if ($user != NULL) {
            sendResponse(200, initBody(false, null), $user);
        } else {
            sendResponse(400, initBody(true, "An error occurred."), null);
        }
    } else {
        sendResponse(401, initBody(true, "Wrong email or password."), null);
    }
});
$app->post('/register/', function () use($app) {
    $username = $app->request->post("username");
    $password = $app->request->post("password");
    $email = $app->request->post("email");
    $db = new dbHandler();
    $result = $db->register($username, $password, $email);
    if ($result == SUCCESS) {