Example #1
0
<?php

$userDAO = new UserDAO();
$app->post('/login/?', function () use($app, $userDAO) {
    header("Content-Type: application/json");
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    if (!empty($post['email']) && !empty($post['password'])) {
        $user = $userDAO->selectByEmail($post['email']);
        if (!empty($user)) {
            $hasher = new \Phpass\Hash();
            if ($hasher->checkPassword($post['password'], $user['password'])) {
                $user = $userDAO->selectById($user['id']);
                $user["loggedIn"] = true;
                $_SESSION['user'] = $user;
                echo json_encode($user, JSON_NUMERIC_CHECK);
            } else {
                echo '{"error":"Fout wachtwoord."}';
            }
        } else {
            echo '{"error":"Foute gebruiker."}';
        }
    } else {
        echo '{"error":"Vul alles in..."}';
    }
});
Example #2
0
<?php

$userDAO = new UserDAO();
$app->get('/users/?', authorize(), function () use($userDAO) {
    header("Content-Type: application/json");
    echo json_encode($userDAO->selectAll(), JSON_NUMERIC_CHECK);
    exit;
});
$app->get('/users/self/?', authorize(), function () use($userDAO) {
    header("Content-Type: application/json");
    echo json_encode($userDAO->selectByUserId($_SESSION['user']['id']), JSON_NUMERIC_CHECK);
    exit;
});
$app->get('/users/:id/?', authorize(), function ($id) use($userDAO) {
    header("Content-Type: application/json");
    echo json_encode($userDAO->selectById($id), JSON_NUMERIC_CHECK);
    exit;
});
$app->get('/users/login/:mail/?', authorize(), function ($mail) use($userDAO) {
    header("Content-Type: application/json");
    echo json_encode($userDAO->selectByMail($mail), JSON_NUMERIC_CHECK);
    exit;
});
$app->post('/users/?', authorize(), function () use($app, $userDAO) {
    header("Content-Type: application/json");
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    echo json_encode($userDAO->insert($post), JSON_NUMERIC_CHECK);
    exit;
Example #3
0
    $data = $userDAO->selectAll();
    $fail = "failed";
    foreach ($data as $key => $value) {
        unset($data[$key]['email']);
        unset($data[$key]['password']);
    }
    if (!empty($_SESSION['user'])) {
        echo json_encode($data, JSON_NUMERIC_CHECK);
    } else {
        echo json_encode($fail, JSON_NUMERIC_CHECK);
    }
    exit;
});
$app->get('/users/:id/?', function ($id) use($userDAO) {
    header("Content-Type: application/json");
    $data = $userDAO->selectById($id);
    foreach ($data as $key => $value) {
        unset($data['email']);
        unset($data['password']);
    }
    echo json_encode($data, JSON_NUMERIC_CHECK);
    exit;
});
$app->put('/users/:id/?', function ($id) use($app, $userDAO) {
    header("Content-Type: application/json");
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    echo json_encode($userDAO->update($id, $post), JSON_NUMERIC_CHECK);
    exit;