Ejemplo n.º 1
0
});
$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()) {
    $data = $req->getParsedBody();
    $data['password'] = base64_encode(hash_hmac("sha256", isset($data['password']) ? $data['password'] : $this->get('initPWD'), $this->get('secret'), true));
    $data['id'] = $args['id'];
    $model = new userModel();
    $result = $model->update($data);
    return $res->write(json_encode($result));
    // } else {
    // 	return $res->withStatus(403)->write("No Post data!");
    // }
});
     }
     $isDisabled = "readonly";
     //On ne peut pas modifier la clé de la table
     $label = "Mise à jour";
     $submit = "Mettre à jour";
     $action = "confirmUpdate";
     $view = "formUser";
     break;
 case "confirmUpdate":
     if (!(isset($_GET['login']) && isset($_GET['name']) && isset($_GET['mail']))) {
         $view = "error";
         $pagetitle = "Controller = Certaines informations n'ont pas été correctement récupérées";
         break;
     }
     $data = array("pseudo" => escape($_GET["login"]), "name" => escape($_GET["name"]), "mail" => escape($_GET["mail"]));
     userModel::update($data);
     $confirmMessage = "L'utilisateur a été correctement mis à jour !";
     $allMovies = movieModel::selectAll();
     $icon = "glyphicon-ok";
     $alert = "alert-success";
     $view = "confirm";
     break;
 case "manageAsAdmin":
     if (isset($_SESSION['admin'])) {
         $allMovies = movieModel::selectAll();
         $allUsers = userModel::selectAll();
         $view = "admin";
     } else {
         $view = "error";
         $pagetitle = "Controller = Seul un administrateur peut gérer l'administration";
     }