/**
  * 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();
                         }
                     }
                 }
             }
         }
     }
 }
     $_REQUEST = array_merge($_REQUEST, $_PUT);
     if (isset($request) && !empty($request) && $request[0] !== '') {
         if ($request[0] == 'account') {
             $id = $request[1];
             UsersController::updateAccount($id, $_REQUEST);
         } else {
             if ($request[0] == 'profile') {
                 $id = $request[1];
                 UsersController::updateProfile($id, $_REQUEST);
             } else {
                 if ($request[0] == 'privilege') {
                     $id = $request[1];
                     UsersController::updateAccess($id, $_REQUEST);
                 } else {
                     $id = $request[0];
                     UsersController::update($id, $_REQUEST);
                 }
             }
         }
     }
     break;
 case 'POST':
     UsersController::create($_POST);
     break;
 case 'GET':
     if (isset($request) && !empty($request) && $request[0] !== '') {
         if ($request[0] == 'auth') {
             UsersController::currentUser();
         } else {
             if ($request[0] == 'privilege') {
                 if (isset($request[1]) && !empty($request[1]) && $request[1] !== '') {
Esempio n. 3
0
    $username = decodeInput($_POST['username']);
    $password = decodeInput($_POST['password']);
    /* we assume that that the data has been verified from the from and the special characters */
    $userController = new UsersController();
    if ($user = $userController->getUser($username, $password)) {
        /* user login successful */
        /* check if remember flag is on */
        $_SESSION['userId'] = $user->getId();
        if (array_key_exists('remember_check', $_POST)) {
            if ($_POST['remember_check'] == "on") {
                setcookie("userId", $user->getId(), time() + 86400 * 30, "/");
            }
        }
        //update the users status to active
        $user->setStatus(1);
        $userController->update($user);
        /* finally */
        Route::getBackend("dashboard.php");
        exit;
    } else {
        /* user login failed */
        $error = true;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My Map | Log in</title>