public function submitconfirmationcodeAction() { $this->_helper->layout->disableLayout(); if ($this->session->isNewUser !== true && $this->session->userid !== -1) { $this->_helper->viewRenderer->setNoRender(); header("Location: " . "https://" . $_SERVER['HTTP_HOST']); return; } $this->view->error = null; $this->view->session = $this->session; $this->view->expired = false; $code = isset($_POST["confirmationcode"]) === true ? trim($_POST["confirmationcode"]) : null; if ($code === null) { $this->view->error = "No confirmation code given"; return; } //Check if current account is already connected to a profile implicitly or through a different session //In this case the view should inform the user and autorefresh to the portal if (AccountConnect::isConnected($this->session) !== false) { //Update session so user will auto login on page refresh SamlAuth::setupSamlAuth($this->session); $this->view->session = $this->session; return; } //Check if account is not pending, which means the request has timedout. //In this case the view should inform the user and autorefresh to display the confirmation form. if (AccountConnect::isPending($this->session) === false) { $this->view->error = "Your connection request has expired"; $this->view->expired = true; //Update session so user will be redirected to the appropriate form SamlAuth::setupSamlAuth($this->session); return; } $result = AccountConnect::submitPendingConnectionCode($this->session, $code); if ($result !== true) { $this->view->error = "Given code is not correct"; return; } $this->view->session = $this->session; }
public static function submitPendingConnectionCode($session, $code) { if (self::isValid($session) === false) { return false; } $uid = trim($session->authUid); $source = str_replace("-sp", "", trim($session->authSource)); $paccount = self::getPendingConnection($uid, $source); if (!$paccount) { return false; } if (trim($paccount->code) !== trim($code)) { return false; } $paccount->resolved = true; $paccount->resolvedOn = 'NOW()'; $paccount->save(); self::connectAccountToProfile($paccount->researcherid, $paccount->accountID, $paccount->accountType, $paccount->accountName, $session->idptrace); unset($session->isNewUser); unset($session->accountStatus); unset($session->accountPendingId); unset($session->accountPendingProfileId); unset($session->accountPendingProfileName); SamlAuth::setupSamlAuth($session); return true; }
public function indexAction() { trackPage('/'); if (isset($_COOKIE['rememberme']) && $this->session->userid === null) { //save permaLink in order to handle it after login if (array_key_exists('p', $_GET)) { $this->session->permaLink = $_GET['p']; } if (APPLICATION_ENV == "production") { header('Location: https://' . $_SERVER['HTTP_HOST'] . '/users/login'); } else { header('Location: http://' . $_SERVER['HTTP_HOST'] . '/users/logindev2'); } return; } /* * Check if user is signed in from a different service or browser tab. */ if ($this->session->isLocked()) { $this->session->unLock(); } if ($this->session !== null && $this->session->developsession === true) { //do nothing. It's local development instance where no SImpleSaml installed } else { $auth = SamlAuth::isAuthenticated(); if ($auth === false) { //if logged in but not authdicated the clear session if (isset($this->session->userid) && is_numeric($this->session->userid)) { SamlAuth::logout($this->session); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); header('Location: http://' . $_SERVER["HTTP_HOST"]); return; } } else { if (isset($this->session) === false || isset($this->session->userid) === false || is_numeric($this->session->userid) === false) { //if authenticated but not logged in setup user session $this->session = new Zend_Session_Namespace('default'); $attributes = $auth->getAttributes(); $uid = $attributes['idp:uid'][0]; $_SESSION['identity'] = $uid; $_SESSION['logouturl'] = $auth->getLogoutURL(); $this->session->samlattrs = $attributes; $this->session->samlauthsource = isset($attributes["idp:sourceIdentifier"]) ? $attributes["idp:sourceIdentifier"][0] : ""; SamlAuth::setupSamlAuth($this->session); if ($this->session->isNewUser === true) { header('Location: https://' . $_SERVER['HTTP_HOST'] . '/saml/newaccount'); return; } //Check and redirect if user account is blocked if ($this->session->accountStatus === "blocked") { header('Location: https://' . $_SERVER['HTTP_HOST'] . '/saml/blockedaccount'); return; } //Check and redirect if user is deleted if ($this->session->userDeleted === true) { header('Location: https://' . $_SERVER['HTTP_HOST'] . '/saml/deletedprofile'); return; } } } } $this->session->appCriteria = null; $this->session->pplCriteria = null; $this->session->certLogin = false; $this->view->username = $this->session->username; if ($this->session->userid !== null) { $ppl = new Default_Model_Researchers(); $ppl->filter->id->equals($this->session->userid); $user = $ppl->items[0]; $this->view->user = $user; /* Get count of user requests */ $urs = new Default_Model_UserRequests(); $s2 = new Default_Model_PermissionsFilter(); $s2->actor->equals($this->session->userguid); $s3 = new Default_Model_UserRequestStatesFilter(); $s3->name->equals("submitted"); $urs->filter->chain($s2->chain($s3, "AND"), "AND"); $reqsitems = $urs->items; $uritems = array_merge($reqsitems); //Fetch user requests for NILs if (userIsAdminOrManager($this->session->userid) === false && userIsNIL($this->session->userid) === true) { $nilusers = new Default_Model_UserRequests(); $s1 = new Default_Model_UserRequestTypesFilter(); $s1->id->numequals(3); $s2 = new Default_Model_ResearchersFilter(); $s2->countryid->equals($this->session->userCountryID); $s3 = new Default_Model_UserRequestStatesFilter(); $s3->name->equals("submitted"); $s4 = new Default_Model_ActorGroupsFilter(); $s4->id->numequals(-3); $nilusers->filter->chain($s1->chain($s2->chain($s3->chain($s4, "AND"), "AND"), "AND"), "AND"); if (count($nilusers->items) > 0) { $uritems = array_merge($uritems, $nilusers->items); $uritems = array_filter($uritems, 'uniqueDBObjectFilter'); } } $this->view->userRequests = count($uritems); } $p = ''; if ($this->session->permaLink != '') { $p = $this->session->permaLink; $this->session->permaLink = ''; } elseif (array_key_exists('p', $_GET)) { $p = $_GET["p"]; } else { //TODO : needs review $p = $_SERVER["QUERY_STRING"]; $pos = strpos($p, "p="); if ($pos === false) { $p = ''; } else { $p = substr($p, 2, strlen($p) - 2); } } if ($p != "") { if ($p == "reports") { $this->view->permaLink = $p; } elseif ($p == "brokenlinks") { $this->view->permaLink = $p; } elseif (substr($p, 0, 6) == "about:") { $this->view->permaLink = $p; } elseif (substr($p, 0, 5) == "apps:") { $this->view->permaLink = $p; } elseif (substr($p, 0, 7) == "people:") { $this->view->permaLink = $p; } else { $pp = base64_decode($p); $pp = mb_convert_encoding($pp, 'UTF-8'); $this->view->permaLink = $pp; } } }