Exemplo n.º 1
0
 public function setRequest(\System\Http\Request $request)
 {
     $this->files = $request->getFiles();
     $this->posts = $request->getPosts();
     $this->headers = $request->getHeaders();
     $this->getparams = $request->getQueryParams();
 }
 protected function hardRedirect($url = null)
 {
     if ($url == null) {
         header("Location: " . Request::getInstance()->getQuery());
     }
     // @ todo extend it to handle other urls
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 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
 }
Exemplo n.º 6
0
 public function send_request(\System\User $user, \System\Template\Renderer $ren, \System\Http\Request $request)
 {
     return \Impro\User\Request::for_user($user, array("text" => stprintf($ren->locales()->trans('intra_team_member_add_text'), array("link_team" => $this->to_html_link($ren), "link_user" => \Impro\User::link($ren, $request->user()))), "id_author" => $request->user()->id, "id_team" => $this->id, "callback" => 'JoinTeam', "redirect_yes" => $ren->uri('team', array($this)), "allow_maybe" => false))->mail($ren);
 }
Exemplo n.º 7
0
 /**
  * General exception handler - Catches exception and displays error
  *
  * @param \Exception $e
  * @param bool $debug
  */
 public static function filterException($e, $debug = false)
 {
     if ($e instanceof \System\Error\Request && $e::REDIRECTABLE && $e->location) {
         header('Location: ' . $e->location);
         exit(0);
     }
     if (!$debug) {
         header('HTTP/1.1 500 Internal Server Error');
         echo "Fatal error";
         exit(1);
     }
     if (!$e instanceof \System\Error) {
         return;
     }
     // Get error display definition
     try {
         $errors = \System\Settings::get('output', 'errors');
         $cfg_ok = true;
     } catch (\System\Error\Config $exc) {
         return;
     }
     // Find error display template
     if (array_key_exists($e->get_name(), $errors)) {
         $errorPage = $errors[$e->get_name()];
     } else {
         return;
     }
     if (self::on_cli()) {
         return;
     }
     // Setup output format for error page
     $errorPage['format'] = 'html';
     $errorPage['render_with'] = 'basic';
     if (!is_array($errorPage['partial'])) {
         $errorPage['partial'] = array($errorPage['partial']);
     }
     $request = \System\Http\Request::from_hit();
     $response = $request->create_response($errorPage);
     $response->create_renderer();
     foreach ($errorPage['partial'] as $partial) {
         $response->renderer->partial($partial, array('status' => $e->get_http_status(), 'desc' => $e, 'message' => $e->get_explanation(), 'wrap' => false));
     }
     $response->status($e->get_http_status())->render()->send_headers()->send_content();
     exit(1);
 }