public function __construct(\core\Request $request) { $this->_controller = $request->getController(); $this->_view = $request->getAction(); $objeto = new \core\Config(FILE_CONFIG_APP); $this->_config = $objeto->getConfig(); }
public function __construct() { $app = App::getInstance(); // On initialise l'objet Request if ($_ENV['USE_ROUTES']) { require '../Config/routes.php'; $this->request = Router::run(new Request($app)); } else { $this->request = new Request($app); } // On parse l'url (définition du controller, action,...) Router::parse($this->request); // On affiche les erreurs ? Debug::set(); // On charge le bon controller try { $controller = $this->loadController(); } catch (SwithException $e) { (new SwithError(['message' => "Le controller {$this->request->controller} est introuvable", "title" => "Controlleur introuvable"]))->display(); } if (method_exists($controller, "beforeRender")) { $controller->beforeRender(); } // On appelle la fonction $action = $this->request->getAction(); $availablesActions = array_diff(get_class_methods($controller), get_class_methods(get_parent_class($controller))); if (in_array($action, $availablesActions)) { call_user_func_array([$controller, $action], $this->request->params); } else { (new SwithError(['message' => "Le controller {$this->request->controller} n'a pas de methode {$action}", "title" => "Methode introuvable"]))->display(); } $controller->render($controller->view); }
public function handleRequest() { // Encapsulate an HTTP request $request = new Request(); // Don't show HTML errors for JSON if ($request->acceptJson()) { ini_set('html_errors', 0); } // Encapsulate the user session if (class_exists('App\\Session')) { $session = new App\Session($request); } else { $session = new Session($request); } $request->setSession($session); // Setup the dispatcher with App URL patterns $routes = self::getPatterns(); if (class_exists('App\\Route')) { $routes = array_merge(App\Route::getPatterns($request), $routes); } $dispatcher = new Dispatcher($request, $routes); // Process the request $response = $dispatcher->processRequest($request); $response->setHeaders($session->getHeaders()); // Render the response $response->respond(); }
/** * * Verifica se a requisição é compatível com a rota. * * @param Request $request Requisição HTTP. * * @param Route $route Rota. * * @return bool TRUE quando sucesso, FALSE quando falhar. * */ public function __invoke(Request $request, Route $route) { if (!$route->allows) { return TRUE; } $requestMethod = $request->getMethod() ?: 'GET'; return in_array($requestMethod, $route->allows); }
/** * Generate controllerName, controllerAction and arguments * @access public * @return void */ public function init() { $route = array(); $query = $this->request->getQuery(); $route['controllerName'] = '\\controllers\\' . ucfirst($query[0]) . 'Controller'; $route['controllerAction'] = $query[1] . 'Action'; $route['actionArgs'] = $this->request->getArgs(); if (file_exists(ROOT . $route['controllerName'] . '.php')) { $controllerObj = new $route['controllerName'](); call_user_func_array(array($controllerObj, $route['controllerAction']), $route['actionArgs']); } else { $studListControllerObj = new StudentsListController(); $studListControllerObj->studentsListAction(); } }
/** * Open a session * * @access public * @param string $base_path Cookie path */ public function open($base_path = '/') { // HttpOnly and secure flags for session cookie session_set_cookie_params(SESSION_DURATION, $base_path ?: '/', null, Request::isHTTPS(), true); // Avoid session id in the URL ini_set('session.use_only_cookies', '1'); // Enable strict mode ini_set('session.use_strict_mode', '1'); // Ensure session ID integrity ini_set('session.entropy_file', '/dev/urandom'); ini_set('session.entropy_length', '32'); ini_set('session.hash_bits_per_character', 6); // If the session was autostarted with session.auto_start = 1 in php.ini destroy it if (isset($_SESSION)) { session_destroy(); } // Custom session name session_name('__S'); // Start the session session_start(); // Regenerate the session id to avoid session fixation issue if (empty($_SESSION['__validated'])) { session_regenerate_id(true); $_SESSION['__validated'] = 1; } }
/** * Authenticate the user * * @access public * @param string $username Username * @param string $password Password * @return boolean */ public function authenticate($username, $password) { $result = $this->findUser($username, $password); if (is_array($result)) { $user = $this->user->getByUsername($username); if ($user) { // There is already a local user with that name if ($user['is_ldap_user'] == 0) { return false; } } else { // We create automatically a new user if ($this->createUser($username, $result['name'], $result['email'])) { $user = $this->user->getByUsername($username); } else { return false; } } // We open the session $this->user->updateSession($user); // Update login history $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent()); return true; } return false; }
public function __construct(Request $request, &$session = null) { // Attempt to load a Person object from the session cookie if ($accessToken = $request->cookie(self::COOKIE)) { $person = new Model\Person(); if ($person->loadByAccess_Token($accessToken)) { // Cache the logged in user object $this->user = $person; } } parent::__construct($request, $session); // Set backto from querystring if ($backto = $this->request->get('backto')) { $this->set('backto', $backto); } }
public function make() { $Request = new Request(); if (!$Request->isPost()) { return false; } $return = \Phpfox_Request::instance()->get('val'); if (!$return) { return false; } $gump = new Gump(); $gump->validation_rules(Validator\Rules::get()); if (!$gump->run($return)) { throw Error($gump->get_errors_array()); } return true; }
/** * Common method to get project filters * * @access protected */ protected function getProjectFilters($controller, $action) { $project = $this->getProject(); $search = $this->request->getStringParam('search', $this->userSession->getFilters($project['id'])); $board_selector = $this->projectPermission->getAllowedProjects($this->userSession->getId()); unset($board_selector[$project['id']]); $filters = array('controller' => $controller, 'action' => $action, 'project_id' => $project['id'], 'search' => urldecode($search)); $this->userSession->setFilters($project['id'], $filters['search']); return array('project' => $project, 'board_selector' => $board_selector, 'filters' => $filters, 'title' => $project['name']); }
/** * Common method to get a project * * @access protected * @param integer $project_id Default project id * @return array */ protected function getProject($project_id = 0) { $project_id = $this->request->getIntegerParam('project_id', $project_id); $project = $this->project->getById($project_id); if (!$project) { $this->session->flashError(t('Project not found.')); $this->response->redirect('?controller=project'); } return $project; }
/** * Common method to get a project with administration rights * * @access protected * @return array */ protected function getProjectManagement() { $project = $this->project->getById($this->request->getIntegerParam('project_id')); if (!$project) { $this->notfound(); } if ($this->acl->isRegularUser() && !$this->projectPermission->adminAllowed($project['id'], $this->acl->getUserId())) { $this->forbidden(); } return $project; }
/** * Controller constructor. * @param Request|NULL $request */ function __construct(Request $request = NULL) { $this->request = is_null($request) ? Request::getInstance() : $request; $this->config = Config::getInstance(); $this->router = new Router(); $this->route = $this->router; $this->load = new Load(); $this->startConnection(); $this->checkPermission(); Model::$controller = $this; }
/** * Authenticate a Google user * * @access public * @param string $google_id Google unique id * @return boolean */ public function authenticate($google_id) { $user = $this->user->getByGoogleId($google_id); if ($user) { // Create the user session $this->user->updateSession($user); // Update login history $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent()); return true; } return false; }
/** * Authenticate a user * * @access public * @param string $username Username * @param string $password Password * @return boolean */ public function authenticate($username, $password) { $user = $this->db->table(User::TABLE)->eq('username', $username)->eq('is_ldap_user', 0)->findOne(); if ($user && password_verify($password, $user['password'])) { // Update user session $this->user->updateSession($user); // Update login history $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent()); return true; } return false; }
public function handleRequest() { if (!$this->Loaded) { $this->loadRouterList(); } $requestPath = Request::getRequestPath(); $requestPath = ltrim($requestPath, '/'); if (!$requestPath) { $requestPath = '@Home'; } Filter::preRoute($requestPath); $this->findController($requestPath); }
public function actionShow($id) { $post = Post::instance()->findByPk((int) $id); if ($post && isset($post->title)) { $this->view->titlePage = "Блог - " . $post->title; } else { throw new HttpException(404, "Not found page."); } if (Request::isAjax()) { echo $this->view->render("show", ['post' => $post], false, false); exit; } $this->view->render("show", ['post' => $post]); }
/** * Authenticate the user with the HTTP header * * @access public * @return bool */ public function authenticate() { if (isset($_SERVER[REVERSE_PROXY_USER_HEADER])) { $login = $_SERVER[REVERSE_PROXY_USER_HEADER]; $user = $this->user->getByUsername($login); if (!$user) { $this->createUser($login); $user = $this->user->getByUsername($login); } // Create the user session $this->user->updateSession($user); // Update login history $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent()); return true; } return false; }
public function __construct(&$params = array()) { // reccup le id du module si envoyé en param if (isset($_REQUEST->moduleId)) { if (isset($_SESSION["modules/" . $_REQUEST->moduleId . "/params"])) { $params = $_SESSION["modules/" . $_REQUEST->moduleId . "/params"]; } } $this->setParameters($params); $id = \Core\Request::getClassUri($this); $id = \Core\CString::sanitize($id); $this->id = $id . "-" . md5(serialize($params)); // Sotck une clé unique d'initialisation en session if (!isset($_SESSION["modules/" . $this->id()])) { $_SESSION["modules/" . $this->id()] = CString::rand(30); } $this->key = $_SESSION["modules/" . $this->id()]; $_SESSION["modules/" . $this->id() . "/params"] = $params; }
/** * * Construtor do Router * * @param Request $request Objeto da Requisição * * @param array|null $routes * * @return void * */ function __construct($routes = NULL) { if (empty(self::$request)) { self::$request = Request::getInstance(); } if (empty(self::$config)) { self::$config = Config::getInstance(); } if (!empty($routes)) { if (is_array($routes)) { foreach ($routes as $i => $route) { self::register($route); } } else { self::register($routes); } } $this->matcher = new Matcher(); self::$instance = $this; }
public function __construct() { global $user; $user = User::getInstance(); if (!$user->uid) { Response::redirect('/Auth/login'); } if (LOCKSCREEN) { // check LOACKSCREEN define if (!empty(@$_COOKIE['token'])) { $token = Util::getToken(); if ($token > 3600 && stristr(\Core\Request::getRequestPath(), 'lockscreen') == false) { Response::redirect('/Auth/lockscreen'); } } else { Response::redirect('/Auth/lockscreen'); } } $user = $user->GetUserByEmail($user->email); }
public function actionCreate() { $this->view->titlePage = "Редактирование поста"; /** * @var Post $post */ $post = new Post(); if (isset($_POST['Post'])) { $post->setAttributes($_POST['Post']); $post->active = isset($_POST['Post']['active']) ? 1 : 0; $post->body = isset($_POST['Post']['body']) ? trim($_POST['Post']['body']) : $post->body; $result = $post->save(); if ($result) { $this->redirect($this->createUrl('/blog/show', ['id' => $result])); exit; } } if (Request::isAjax()) { echo $this->view->render('create', ['post' => $post], false, false); exit; } $this->view->render('create', ['post' => $post]); }
public function onSuccess(AuthEvent $event) { $this->lastLogin->create($event->getAuthType(), $event->getUserId(), Request::getIpAddress(), Request::getUserAgent()); }
/** * Get current server base url * * @access public * @return string */ public function server() { $self = str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])); $url = Request::isHTTPS() ? 'https://' : 'http://'; $url .= $_SERVER['SERVER_NAME']; $url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? '' : ':' . $_SERVER['SERVER_PORT']; $url .= $self !== '/' ? $self . '/' : '/'; return $url; }
public static function set_analytic_cookie(Request &$request, $user) { $cookie = Cipher::encrypt(implode('|', array($user, time(), $request->getUserAgent()))); setcookie('__ac', $cookie, time() + 3600 * 24 * 7, '/', app_domain); return $cookie; }
/** * Get current server base url * * @access public * @return string */ public function server() { if (empty($_SERVER['SERVER_NAME'])) { return 'http://localhost/'; } $url = Request::isHTTPS() ? 'https://' : 'http://'; $url .= $_SERVER['SERVER_NAME']; $url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? '' : ':' . $_SERVER['SERVER_PORT']; $url .= $this->dir() ?: '/'; return $url; }
| <a href="#" id="logout_<?php echo $randId; ?> "><trans>logout</trans></a> </div> <script type="text/javascript"> $(function() { // Edit link $("#logout_<?php echo $randId; ?> ").click(function() { $.ajax({ url: "<?php echo APP_URI . "index.php/" . \Core\Request::getClassUri($self) . "/logout"; ?> /", method : "POST", data : { "moduleId" : "<?php echo $self->id(); ?> ", "<?php echo $self->id(); ?> " : "<?php echo $self->key(); ?> "
/** * Remove the cookie * * @access public */ public function deleteCookie() { setcookie(self::COOKIE_NAME, '', time() - 3600, BASE_URL_DIRECTORY, null, Request::isHTTPS(), true); }
private static function Error($message = NULL) { if (class_exists('\\Controller\\ErrorController')) { $app = new \Controller\ErrorController(Request::getInstance()); return $app->index($message); } else { return 'Error: ' . $message; } }
include_once dirname($modulePath) . "/Event.php"; } } } $include_flux = trim(ob_get_contents()); ob_end_clean(); // Liste des module php preconisé $loadedExtension = \Core\Server::extensions(); foreach (array("mcrypt", "mbstring", "zlib") as $mod) { if (!in_array(strtolower($mod), $loadedExtension)) { \Core\FirePHP::fbLog("warn", "Warning : module " . strtoupper($mod) . " is not installed"); } } // Set php config \Core\Config::ApplyIni(); $_REQUEST = \Core\Request::create($_REQUEST); // Renvoie dans fb les eventuels flux des includes if ($include_flux !== "") { // info, warn, error, dump, trace, table \Core\FirePHP::fbLog("warn", $include_flux); \Core\Event::fire("Page_FluxNotNull", $_REQUEST, $include_flux); } // Default service et request // Par défault la page d'accueil se trouve dans services/_default.php, function Main() $s = "_default"; $r = "main"; // Get security defaultService $confSecurity = \Core\Config::get("security"); if (!empty($confSecurity) && isset($confSecurity["defaultService"]) && !empty($confSecurity["defaultService"])) { $defaultService = $confSecurity["defaultService"]; $defaultService = preg_replace("/:{1,2}/", "/", $defaultService);