Exemple #1
0
});
// Pages
$app->group('/users', function () use($app, $view) {
    $app->get('/', function () use($app, $view) {
        $users = g::findUsers();
        $data = array('users' => $users->toArray(true));
        echo $view->render('users/index.php', $data);
    });
    $app->post('/add', function () use($app, $view) {
        $data = $app->request->post();
        try {
            // Verify the emails match
            if ($data['password'] !== $data['password-confirm']) {
                throw new \Exception('Password mismatch!');
            }
            $result = g::createUser(array('username' => $data['username'], 'password' => $data['password'], 'email' => $data['email'], 'first_name' => $data['first-name'], 'last_name' => $data['last-name']));
            if ($result === false) {
                throw new \Exception('Error creating user');
            }
        } catch (\Exception $e) {
            if (ACCEPT_JSON) {
                $app->response->setStatus(400);
            }
            $data = array('message' => $e->getMessage());
        }
        echo $view->render('users/add.php', $data);
    });
    $app->get('/view/:userId', function ($userId) use($app, $view) {
        try {
            $user = g::findUserById($userId);
            $data = array('user' => $user->toArray(), 'groups' => $user->groups->toArray(true), 'permissions' => $user->permissions->toArray(true));