Esempio n. 1
0
/*
 * Main path
 */
$app->get('/', function (Request $request) use($app, $UsersController) {
    return $app->redirect('doc/index.html');
});
/*
 * Users
 */
$app->get($basePath . '/userInfos', function (Request $request) use($app, $UsersController, $UserModel) {
    $params = $request->query->all();
    $errorMessage = $UserModel->validate($params, "index");
    if ($errorMessage) {
        return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage);
    } else {
        return $UsersController->index($params);
    }
});
$app->get($basePath . '/users/login', function (Request $request) use($app, $UsersController, $UserModel) {
    $params = $request->query->all();
    $errorMessage = $UserModel->validate($params, 'login');
    if ($errorMessage) {
        return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage);
    } else {
        return $UsersController->login($params);
    }
});
$app->post($basePath . '/users/create', function (Request $request) use($app, $UsersController, $UserModel) {
    $params = $request->query->all();
    $errorMessage = $UserModel->validate($params, 'create');
    if ($errorMessage) {
$routes->post('/profile/update', 'auth', function () {
    ProfileController::edit();
});
$routes->get('/profile/password', 'auth', function () {
    ProfileController::password();
});
$routes->post('/profile/password/update', 'auth', function () {
    ProfileController::updatePassword();
});
// Controlpanel
$routes->get('/controlpanel', 'admin', function () {
    AuthController::controlpanel();
});
// Users
$routes->get('/users', 'admin', function () {
    UsersController::index();
});
$routes->get('/users/create', 'admin', function () {
    UsersController::create();
});
$routes->post('/users/store', 'admin', function () {
    UsersController::store();
});
$routes->get('/users/:id/destroy', 'admin', function ($id) {
    UsersController::destroy($id);
});
// Roles
$routes->get('/roles', 'admin', function () {
    RolesController::index();
});
$routes->get('/roles/create', 'admin', function () {
 /**
  * Aca tenemos que definir todas las rutas que la aplicación va a aceptar.
  */
 public static function init()
 {
     // Esta seria la pagina de incio
     if ($_SERVER['REQUEST_URI'] == '/electiva_php_ude_2015/') {
         $controller = new HomeController();
         $controller->index();
     } else {
         if (strpos($_SERVER['REQUEST_URI'], 'sessions')) {
             $controller = new SessionsController();
             if (strpos($_SERVER['REQUEST_URI'], 'login') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                 $controller->modal();
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], 'login') && $_SERVER['REQUEST_METHOD'] == 'POST') {
                     $controller->login();
                 } else {
                     if (strpos($_SERVER['REQUEST_URI'], 'logout') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                         $controller->logout();
                     } else {
                         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                             $controller->index();
                         }
                     }
                 }
             }
         } else {
             if (strpos($_SERVER['REQUEST_URI'], 'users')) {
                 $controller = new UsersController();
                 if (strpos($_SERVER['REQUEST_URI'], 'create') && $_SERVER['REQUEST_METHOD'] == 'POST') {
                     $controller->create();
                 } else {
                     if (strpos($_SERVER['REQUEST_URI'], 'new') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                         $controller->form();
                     } else {
                         if (strpos($_SERVER['REQUEST_URI'], 'delete') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                             $controller->delete();
                         } else {
                             if (strpos($_SERVER['REQUEST_URI'], 'modify') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                                 $controller->modify();
                             } else {
                                 if (strpos($_SERVER['REQUEST_URI'], 'update') && $_SERVER['REQUEST_METHOD'] == 'POST') {
                                     $controller->update();
                                 } else {
                                     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                                         $controller->index();
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], 'polyclinics')) {
                     $controller = new PolyclinicsController();
                     if (strpos($_SERVER['REQUEST_URI'], 'create') && $_SERVER['REQUEST_METHOD'] == 'POST') {
                         $controller->create();
                     } else {
                         if (strpos($_SERVER['REQUEST_URI'], 'new') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                             $controller->form();
                         } else {
                             if (strpos($_SERVER['REQUEST_URI'], 'delete') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                                 $controller->delete();
                             } else {
                                 if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                                     $controller->index();
                                 }
                             }
                         }
                     }
                 } else {
                     if (strpos($_SERVER['REQUEST_URI'], 'reports')) {
                         $controller = new ReportsController();
                         if (strpos($_SERVER['REQUEST_URI'], 'index') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                             $controller->index();
                         } else {
                             if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                                 $controller->index();
                             }
                         }
                     } else {
                         if (strpos($_SERVER['REQUEST_URI'], 'bookings')) {
                             $controller = new BookingsController();
                             if (strpos($_SERVER['REQUEST_URI'], 'create') && $_SERVER['REQUEST_METHOD'] == 'POST') {
                                 $controller->create();
                             } else {
                                 if (strpos($_SERVER['REQUEST_URI'], 'new') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                                     $controller->form();
                                 } else {
                                     if (strpos($_SERVER['REQUEST_URI'], 'delete') && $_SERVER['REQUEST_METHOD'] == 'GET') {
                                         $controller->delete();
                                     } else {
                                         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                                             $controller->index();
                                         }
                                     }
                                 }
                             }
                         } else {
                             $controller = new HomeController();
                             $controller->index();
                         }
                     }
                 }
             }
         }
     }
 }