예제 #1
0
$app->post('/{id:[0-9]+}', function ($req, $res, $args) {
    if ($req->getParsedBody()) {
        $data = $req->getParsedBody();
        $model = new userModel();
        // $data = isset($args['id']) ? $db->select('user', '*', ['id' => $args['id']]) : $db->select('user', '*', ['LIMIT' => 1]);
        $result = $model->update($data);
        return $res->write(json_encode($result));
    } else {
        return $res->withStatus(403)->write("No Post data!");
    }
});
$app->delete('/{id:[0-9]+}', function ($req, $res, $args) {
    // $db = $this->get('db');
    // $data = $db->delete('user', ['id' => $args['id']]);
    $model = new userModel();
    $result = $model->delete($args['id']);
    return $res->write(json_encode($result));
});
$app->get('/list[/{page:[0-9]+}[/{size:[0-9]+}]]', function ($req, $res, $args) {
    $page = isset($args['page']) ? $args['page'] : 0;
    $size = isset($args['size']) ? $args['size'] : 10;
    // var_dump($req->getQueryParams());
    // $db = $this->get('db');
    // $data = $db->select('user', '*', ['LIMIT' => [$page, $size]]);
    $option['where'] = ['LIMIT' => [$page, $size]];
    $model = new userModel();
    $result = $model->listData($option);
    return $res->write(json_encode($result));
});
$app->post('/pwd/{id:[0-9]+}', function ($req, $res, $args) {
    // if ($req->getParsedBody()) {
     $secureConfirmationMessage = "Voulez-vous vraiment supprimer le compte de cet utilisateur ?";
     $view = "secureConfirmation";
     break;
 case "deleteUser":
     if (!isset($_SESSION['admin'])) {
         $view = "error";
         $pagetitle = "Controller = Seul un administrateur peut supprimer un utilisateur définitivement.";
         break;
     }
     if (!isset($_GET['login'])) {
         $view = "error";
         $pagetitle = "Controller = L'utilisateur à supprimer n'a pas été correctement récupéré.";
         break;
     }
     $data = array("pseudo" => escape($_GET['login']));
     $userToDelete = userModel::delete($data);
     $confirmMessage = "Le compte de l'utilisateur n'existe plus";
     $allMovies = movieModel::selectAll();
     $icon = "glyphicon-remove";
     $alert = "alert-danger";
     $view = "confirm";
     break;
 case "deconnect":
     session_destroy();
     unset($_SESSION);
 default:
 case "readAll":
     $allMovies = movieModel::selectAll();
     $controller = "movie";
     $view = "home";
     break;