/** * Perform an authentication check on this request */ protected function checkAuthentication($action) { $id = $this->request->getControllerName(); $restricted = $this->controller_map->isRestricted($id, $action); $requires_login = $this->controller_map->requiresLogin($id, $action); // get user from session $user = $this->request->getUser(); // this action requires authentication if ($restricted || $requires_login) { $redirect_to_login = false; // this action requires a logged-in user, but user is not logged-in if ($requires_login && !$user->isAuthenticated()) { $redirect_to_login = true; } elseif ($restricted && !$user->isAuthenticated() && !$user->isInLocalIpRange()) { $redirect_to_login = true; } // redirect to login page if ($redirect_to_login == true) { return $this->redirectToLogin(); } } }
/** * Construct a URL, taking into account routes, based on supplied parameters * * @param array $params the elements of the url * @param bool $full [optional] should be full url * @param bool $force_secure [optional] should be https:// */ public function url_for(array $params, $full = false, $force_secure = false) { $controller = null; $action = null; $route = array(); // controller if (array_key_exists('controller', $params)) { $controller = $params['controller']; // swap internal controller name for alias $controller = $this->controller_map->getUrlAlias($controller); $route[] = $controller; unset($params['controller']); } // action if (array_key_exists('action', $params)) { $action = $params['action']; $route[] = $action; unset($params['action']); } // config defined route information foreach ($this->controller_map->getRouteInfo($controller, $action) as $param_name) { if (array_key_exists($param_name, $params)) { $route[] = $params[$param_name]; unset($params[$param_name]); } } // always include the lang if it was supplied, and not overriden by the code if ($this->getParam('lang') != null && !array_key_exists('lang', $params)) { $params['lang'] = $this->getParam('lang'); } // assemble it as the route $url = implode('/', $route); // take anything remaining as the query string if (count($params) > 0) { $url .= "?"; $x = 0; // counter $hash = ''; // hash url foreach ($params as $name => $value) { if ($value == "") { continue; } if ($name == '#') { $hash .= "#{$value}"; continue; } if ($x > 0) { $url .= '&'; } // value is array if (is_array($value)) { foreach ($value as $v) { $url .= $name . '=' . urlencode($v) . '&'; } } else { $url .= $name . '=' . urlencode($value); } $x++; } // add hash $url .= $hash; } // is it supposed to be a full url? if ($full == true || $this->getSessionData('is_mobile') == '1') { $base = $this->getServerUrl($force_secure) . $this->getBasePath() . '/'; $url = $base .= $url; } return $url; }