Esempio n. 1
0
    return new Response($result, 200);
});
// Get admin by auth
$app->GET('/adminlogin', function (Application $app, Request $request) {
    $admin_id = getAdminIdByLogin();
    if ($admin_id == -1) {
        return new Response('Unauthorized', 401);
    }
    $handler = new AdminHandler();
    $result = $handler->get($admin_id);
    return new Response($result, 200);
});
// Get admin by id
$app->GET('/admin/{admin_id}', function (Application $app, Request $request, $admin_id) {
    $handler = new AdminHandler();
    $result = $handler->get($admin_id);
    return new Response($result, 200);
});
// Create admin
$app->PUT('/admin', function (Application $app, Request $request) {
    if (!authenticate('1', null)) {
        return new Response('Unauthorized', 401);
    }
    $object = array('username' => $request->get('username'), 'password' => $request->get('password'), 'first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'role_id' => $request->get('role_id'));
    $handler = new AdminHandler();
    $result = $handler->add($object);
    return new Response($result['message'], $result['status_code']);
});
// Update admin
$app->POST('/admin/{admin_id}', function (Application $app, Request $request, $admin_id) {
    if (!authenticate('user', $admin_id)) {