/** * Creat an authentication object * * @param Request $request * @return Scheme */ public function getAuthenticationObject(Request $request) { $registry = Registry::getInstance(); // if the authentication_source is set in the request, then it takes precedence $override = $request->getParam("authentication_source"); if ($override == null) { // otherwise, see if one has been set in session from a previous login $session_auth = $request->getSessionData("auth"); if ($session_auth != "") { $override = $session_auth; } } // make sure it's in our list, or if blank still, we get the default $name = $registry->getAuthenticationSource($override); // sanitize $name = preg_replace('/\\W/', '', $name); // main class $class_name = 'Application\\Model\\Authentication' . '\\' . ucfirst($name); // local custom version $local_class_name = 'Local\\Authentication' . '\\' . ucfirst($name); if (class_exists($local_class_name)) { $class_name = $local_class_name; } // make it $authentication = new $class_name($request); if (!$authentication instanceof Scheme) { throw new \Exception("class '{$class_name}' for the '{$name}' authentication scheme must extend Scheme"); } return $authentication; }
/** * Register the user in session and with the user tables in the database * and then forwards them to the return url * * @param User $user [optional] user object */ public function register(User $user = null) { // if passed in externally if ($user != null) { $this->user = $user; } // data map $datamap_users = new Users(); $datamap_records = new SavedRecords(); // if the user was previously active under a local username // then reassign any saved records to the new username $old_username = $this->request->getSessionData("username"); $old_role = $this->request->getSessionData("role"); if ($old_role == "local") { $datamap_records->reassignRecords($old_username, $this->user->username); } // add or update user in the database // get any values in the db not specified here and populates user $this->user = $datamap_users->touchUser($this->user); // @todo: reconcile this code with User code // should we just save user object in session? // set main properties in session $admins = explode(',', $this->registry->getConfig('ADMIN_USERS')); if (in_array($this->user->username, $admins)) { $this->request->setSessionData("user_admin", true); } $this->request->setSessionData("username", $this->user->username); $this->request->setSessionData("role", $this->role); // store user's additional properties in session, so they can be used by // controller, and included in xml for views. $this->request->setSessionData("user_properties", $this->user->properties()); // groups too empty array not null please. $this->request->setSessionData("user_groups", $this->user->usergroups); // set this object's id in session $this->request->setSessionData("auth", $this->id); // now forward them to the return url return $this->redirectTo($this->return_url); }
/** * Create a User * * @param Request $request [optional] create user from current Request */ public function __construct(Request $request = null) { self::$request = $request; $this->registry = Registry::getInstance(); if ($request != "") { // user attributes $this->username = $request->getSessionData("username"); $this->role = $request->getSessionData("role"); $this->ip_address = $request->getClientIp(); $this->admin = $request->getSessionData('user_admin'); // local ip range from config $this->ip_range = $this->registry->getConfig("LOCAL_IP_RANGE", false, null); // temporarily authenticate users if ($this->username == "") { // on campus if ($this->isInLocalIpRange() == true) { $this->username = self::genRandomUsername(self::LOCAL); $this->role = self::LOCAL; } else { $this->username = self::genRandomUsername(self::GUEST); $this->role = self::GUEST; } $request->setSessionData("username", $this->username); $request->setSessionData("role", $this->role); } } }
/** * Add links to the query object limits * * @param Query $query */ public function addQueryLinks(Query $query) { // we have to pass in the query object here rather than take // the property above because adding the links doesn't seem // to reflect back in the main object, even though they should // be references, maybe because limit objects are in an array? // add current query to query object itself $params = $query->extractSearchParams(); $params['controller'] = $this->request->getParam('controller'); $params['action'] = 'search'; $params['source'] = $this->request->getParam('source'); $params['sort'] = $this->request->getParam('sort'); // url $query->url = $this->request->url_for($params); // query only $query->url_query = Parser::removeLeft($query->url, '?'); // advanced search $params['action'] = 'advanced'; $query->url_advanced = $this->request->url_for($params); // search option links $search = $this->registry->getConfig('search'); if ($search instanceof \SimpleXMLElement) { $controller_map = $this->request->getControllerMap(); // combined results $combined = $controller_map->getUrlAlias('combined'); $combined_id = $combined . '_' . $query->getHash(); if ($this->request->getSessionData($combined_id) != null) { $params = $query->extractSearchParams(); $params['controller'] = $combined; $params['action'] = "results"; $search->combined_url = $this->request->url_for($params); } // individual search options foreach ($search->xpath("//option") as $option) { $id = (string) $option["id"]; if ((string) $option["source"] != '') { $id .= '_' . (string) $option["source"]; } $id .= '_' . $this->query->getHash(); // format the number // is this the current tab? if ($this->request->getControllerName() == (string) $option["id"] && ($this->request->getParam('source') == (string) $option["source"] || (string) $option["source"] == '')) { // mark as current $option->addAttribute('current', "1"); } // create url based on the search terms only! $params = $query->extractSearchParams(); $params['controller'] = $controller_map->getUrlAlias((string) $option["id"]); $params['action'] = "results"; $params['source'] = (string) $option["source"]; $params['sort'] = $this->request->getParam('sort'); // results url $url = $this->request->url_for($params); $option->addAttribute('url', $url); // hits url $params['action'] = 'hits'; $url = $this->request->url_for($params); $option->addAttribute('url_hits', $url); // cached search hit count? foreach ($this->request->getAllSessionData() as $session_id => $session_value) { // does this value in the cache have the save id as our tab? $id = str_replace("_" . $query->getHash(), "", $session_id); if ($id == (string) $option["id"]) { // yup, so add it $option->addAttribute('hits', Parser::number_format($session_value)); } } } // header('Content-type: text/xml'); echo $search->asXML(); exit; $this->registry->setConfig('search', $search); } // links to remove facets foreach ($query->getLimits() as $limit) { $params = $this->currentParams(); $value = $limit->value; if ($limit->display != "") { $value = $limit->display; } // urlencode here necessary to support the urlencode above on 'key' urls $params = Parser::removeFromArray($params, urlencode($limit->param), $value); $limit->remove_url = $this->request->url_for($params); } }