Exemplo n.º 1
0
            echo json_encode($user);
        } else {
            throw new ResourceNotFoundException();
        }
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(404);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    } catch (Exception $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
});
$app->get('/login(/)', 'authenticate', function () use($app) {
    try {
        $us = new UsersService();
        $user = $us->getAllUsers();
        if ($user) {
            $app->response()->header('Content-Type', 'application/json');
            echo json_encode($user);
        } else {
            throw new ResourceNotFoundException();
        }
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(401);
    } catch (Exception $e) {
        $app->response()->status(404);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
});
$app->get('/login/:id(/)', 'authenticate', 'getuserbyid');
function getuserbyid($id)
Exemplo n.º 2
0
     if (count($request) > 1) {
         // if($request[0] == ''){
         // if(!empty($request[1])){
         // 	$rs = $sv->function($request[1],$user);
         // 	echo json_encode($rs);
         // } else {
         // 	throw new Exception('Error Message');
         // }
         // } else if($request[0] == ''){
         // 	$rs = $sv->function($request[1],$user);
         // 	echo json_encode($rs);
         // } else {
         // }
     } else {
         if (empty($request[0])) {
             echo json_encode($sv->getAllUsers($user));
         } else {
             echo json_encode($sv->getUsersByID($request[0], $user));
         }
     }
     break;
 case 'DELETE':
     try {
         if (!empty($request[0])) {
             $rs = $sv->deleteUsers($request[0], $user);
             echo json_encode($rs);
         } else {
             throw new Exception('No Id for Delete');
         }
     } catch (Exception $e) {
         http_response_code(500);