protected function hardRedirect($url = null) { if ($url == null) { header("Location: " . Request::getInstance()->getQuery()); } // @ todo extend it to handle other urls }
protected function __construct() { // get available modules $this->modules = Config::getInstance()->get("modules"); // get the router configurations $config = Config::getInstance()->get("router"); $this->routes = $config['routes']; // then get the query string $this->querystring = Request::getInstance()->getQuery(); $this->parseRequest(); }
/** * Logs in a user * @param array $user email, password, persist * @return boolean */ public function login($user) { if (!isset($user['logintype'])) { return false; } // we logged in via facebook so trust the credentials if ($user['logintype'] == "facebook") { $_SESSION['user']['lastname'] = $_POST['lastname']; $_SESSION['user']['firstname'] = $_POST['firstname']; $_SESSION['user']['email'] = $_POST['email']; return true; // we logging in via our form } elseif ($user['logintype'] == "normal") { // check the user in the database $result = $this->checkInDb(Request::getInstance()->getPost('email'), Request::getInstance()->getPost('password')); if (!$result) { return false; } else { foreach ($result as $record) { $_SESSION['user']['id'] = $record['id']; $_SESSION['user']['lastname'] = $record['lastname']; $_SESSION['user']['firstname'] = $record['firstname']; $_SESSION['user']['email'] = $record['email']; if (strtotime($record['lastmodification']) < time() - 90 * 24 * 1440) { $_SESSION['user']['passwordexpired'] = true; } else { $_SESSION['user']['passwordexpired'] = false; } } return true; } } elseif ($user['logintype'] == "googleplus") { $_SESSION['user']['lastname'] = $_POST['lastname']; $_SESSION['user']['firstname'] = $_POST['firstname']; $_SESSION['user']['email'] = $_POST['email']; return true; } return false; }
public function start() { try { // call the router and check whether the given url can be matched to any route $this->router = Router::getInstance(); // fill in the parameters $params = Params::getInstance(); $params->setRequest(Request::getInstance()); $params->setRouter(Router::getInstance()); // call the given controllers given action $controllerName = $this->router->getController(); $actionName = $this->router->getAction(); // instantiate the controller if (class_exists($controllerName)) { $controller = new $controllerName(); } else { throw new \Exception("The class '{$controllerName}' in routing configuration isn't exists", 404); } // call the given action and get the viewmodel from it if (in_array($actionName, get_class_methods($controllerName))) { $controller->onDispatch($this); $view = $controller->{$actionName}(); } else { throw new \Exception("The method '{$actionName}' isn't a callable!", 404); } if (is_object($view) && in_array('System\\StdLib\\View\\ViewInterface', class_implements($view))) { $controller->getLayout()->render($view); } else { throw new \Exception("No valid viewmodels returned. Returned viewmodels should implement 'System\\StdLib\\View\\ViewInterface'"); } } catch (\Exception $e) { die($e->getMessage()); $this->displayFatalErrors($e); } // end }