/** * Get all of the lists associated with this user. * * @return \Zend\Db\ResultSet\AbstractResultSet */ public function getLists() { $lists = parent::getLists(); // Sort lists by id $listsSorted = []; foreach ($lists as $l) { $listsSorted[$l['id']] = $l; } ksort($listsSorted); return array_values($listsSorted); }
/** * Returns the stored list of facets for the last search * * @param array $filter Array of field => on-screen description listing * all of the desired facet fields; set to null to get all configured values. * * @return array Facets data arrays */ public function getFacetList($filter = null) { // Make sure we have processed the search before proceeding: if (is_null($this->user)) { $this->performAndProcessSearch(); } // If there is no filter, we'll use all facets as the filter: if (is_null($filter)) { $filter = $this->getParams()->getFacetConfig(); } // Start building the facet list: $retVal = []; // Loop through every requested field: $validFields = array_keys($filter); foreach ($validFields as $field) { if (!isset($this->facets[$field])) { $this->facets[$field] = ['label' => $this->getParams()->getFacetLabel($field), 'list' => []]; switch ($field) { case 'tags': if ($this->list) { $tags = $this->list->getTags(); } else { $tags = $this->user ? $this->user->getTags() : []; } foreach ($tags as $tag) { $this->facets[$field]['list'][] = ['value' => $tag->tag, 'displayText' => $tag->tag, 'count' => $tag->cnt, 'isApplied' => $this->getParams()->hasFilter("{$field}:" . $tag->tag)]; } break; } } if (isset($this->facets[$field])) { $retVal[$field] = $this->facets[$field]; } } return $retVal; }
/** * Delete a group of favorites. * * @param array $ids Array of IDs in source|id format. * @param mixed $listID ID of list to delete from (null for all * lists) * @param User $user Logged in user * * @return void */ public function delete($ids, $listID, $user) { // Sort $ids into useful array: $sorted = []; foreach ($ids as $current) { list($source, $id) = explode('|', $current, 2); if (!isset($sorted[$source])) { $sorted[$source] = []; } $sorted[$source][] = $id; } // Delete favorites one source at a time, using a different object depending // on whether we are working with a list or user favorites. if (empty($listID)) { foreach ($sorted as $source => $ids) { $user->removeResourcesById($ids, $source); } } else { $table = $this->getController()->getTable('UserList'); $list = $table->getExisting($listID); foreach ($sorted as $source => $ids) { $list->removeResourcesById($user, $ids, $source); } } }
/** * Updates the user information in the session. * * @param UserRow $user User object to store in the session * * @return void */ public function updateSession($user) { $this->currentUser = $user; if ($this->inPrivacyMode()) { $this->session->userDetails = $user->toArray(); } else { $this->session->userId = $user->id; } $this->cookieManager->clear('loggedOut'); }
/** * Helper function for recoverAction * * @param \VuFind\Db\Row\User $user User object we're recovering * @param \VuFind\Config $config Configuration object * * @return void (sends email or adds error message) */ protected function sendRecoveryEmail($user, $config) { // If we can't find a user if (null == $user) { $this->flashMessenger()->setNamespace('error')->addMessage('recovery_user_not_found'); } else { // Make sure we've waiting long enough $hashtime = $this->getHashAge($user->verify_hash); $recoveryInterval = isset($config->Authentication->recover_interval) ? $config->Authentication->recover_interval : 60; if (time() - $hashtime < $recoveryInterval) { $this->flashMessenger()->setNamespace('error')->addMessage('recovery_too_soon'); } else { // Attempt to send the email try { // Create a fresh hash $user->updateHash(); $config = $this->getConfig(); $renderer = $this->getViewRenderer(); $method = $this->getAuthManager()->getAuthMethod(); // Custom template for emails (text-only) $message = $renderer->render('Email/recover-password.phtml', ['library' => $config->Site->title, 'url' => $this->getServerUrl('myresearch-verify') . '?hash=' . $user->verify_hash . '&auth_method=' . $method]); $this->getServiceLocator()->get('VuFind\\Mailer')->send($user->email, $config->Site->email, $this->translate('recovery_email_subject'), $message); $this->flashMessenger()->setNamespace('info')->addMessage('recovery_email_sent'); } catch (MailException $e) { $this->flashMessenger()->setNamespace('error')->addMessage($e->getMessage()); } } } }
/** * Process the "edit library card" submission. * * @param \VuFind\Db\Row\User $user Logged in user * * @return object|bool Response object if redirect is * needed, false if form needs to be redisplayed. */ protected function processEditLibraryCard($user) { $cardName = $this->params()->fromPost('card_name', ''); $target = $this->params()->fromPost('target', ''); $username = $this->params()->fromPost('username', ''); $password = $this->params()->fromPost('password', ''); if (!$username || !$password) { $this->flashMessenger()->setNamespace('error')->addMessage('authentication_error_blank'); return false; } if ($target) { $username = "******"; } // Connect to the ILS and check that the credentials are correct: $catalog = $this->getILS(); $patron = $catalog->patronLogin($username, $password); if (!$patron) { $this->flashMessenger()->setNamespace('error')->addMessage('authentication_error_invalid'); return false; } $id = $this->params()->fromRoute('id', $this->params()->fromQuery('id')); try { $user->saveLibraryCard($id == 'NEW' ? null : $id, $cardName, $username, $password); } catch (\VuFind\Exception\LibraryCard $e) { $this->flashMessenger()->setNamespace('error')->addMessage($e->getMessage()); return false; } return $this->redirect()->toRoute('librarycards-home'); }
/** * Process the "change password" submission. * * @param \VuFind\Db\Row\User $user Logged in user * @param \VuFind\Db\Row\UserCard $card Library card * * @return object|bool Response object if redirect is needed, false if form * needs to be redisplayed. */ protected function processPasswordChange($user, $card) { $post = $this->getRequest()->getPost(); $userFromHash = isset($post->hash) ? $this->getTable('User')->getByVerifyHash($post->hash) : false; $oldPassword = $this->params()->fromPost('oldpwd', ''); $password = $this->params()->fromPost('password', ''); $password2 = $this->params()->fromPost('password2', ''); // Validate new password try { $ilsAuth = $this->getServiceLocator()->get('VuFind\\AuthPluginManager')->get('ILS'); $ilsAuth->validatePasswordInUpdate(['password' => $password, 'password2' => $password2]); } catch (AuthException $e) { $this->flashMessenger()->addMessage($e->getMessage(), 'error'); return false; } // Missing or invalid hash if (false == $userFromHash) { $this->flashMessenger()->addMessage('recovery_user_not_found', 'error'); return false; } elseif ($userFromHash->username !== $user->username) { $this->flashMessenger()->addMessage('authentication_error_invalid', 'error'); return false; } // Connect to the ILS and check that the credentials are correct: $catalog = $this->getILS(); $patron = $catalog->patronLogin($card->cat_username, $oldPassword); if (!$patron) { $this->flashMessenger()->addMessage('authentication_error_invalid', 'error'); return false; } $result = $catalog->changePassword(['patron' => $patron, 'oldPassword' => $oldPassword, 'newPassword' => $password]); if (!$result['success'] && $result['status'] == 'authentication_error_invalid' && !empty($oldPassword)) { // Try again with empty old password just in case this was a user that // was logged in with the fallback login field $result = $catalog->changePassword(['patron' => $patron, 'oldPassword' => '', 'newPassword' => $password]); } if (!$result['success']) { $this->flashMessenger()->addMessage($result['status'], 'error'); return false; } $user->saveLibraryCard($card->id, $card->card_name, $card->cat_username, $password); if ($user->cat_username === $card->cat_username) { $user->saveCredentials($card->cat_username, $password); } $user->updateHash(); $this->flashMessenger()->addSuccessMessage('new_password_success'); return $this->redirect()->toRoute('librarycards-home'); }
/** * Deletes user's Library Cards which are not in array $userLibraryIds & creates those cards, which user * doesn't have compared to array $userLibraryIds * * @param User $user * @param array $currentLibCards */ protected function handleLibraryCards(User $user, array $currentLibCards) { $tableManager = $this->getDbTableManager(); $userCardTable = $tableManager->get("UserCard"); $resultSet = $userCardTable->select(['user_id' => $user['id']]); // Delete lost identitites foreach ($resultSet as $result) { $cat_username = $result['cat_username']; // Doesn't exists -> delete it if (!in_array($cat_username, $currentLibCards)) { $result->delete(); } else { $existing[] = $cat_username; } } // Create new identities foreach ($currentLibCards as $cat_username) { if (!in_array($cat_username, $existing)) { $home_library = explode(self::SEPARATOR, $cat_username)[0]; $user->createLibraryCard($cat_username, $home_library); } } }
/** * Process the "change password" submission. * * @param \VuFind\Db\Row\User $user Logged in user * @param \VuFind\Db\Row\UserCard $card Library card * * @return object|bool Response object if redirect is needed, false if form * needs to be redisplayed. */ protected function processPasswordChange($user, $card) { $post = $this->getRequest()->getPost(); $userFromHash = isset($post->hash) ? $this->getTable('User')->getByVerifyHash($post->hash) : false; $oldPassword = $this->params()->fromPost('oldpwd', ''); $password = $this->params()->fromPost('password', ''); $password2 = $this->params()->fromPost('password2', ''); if ($oldPassword === '' || $password === '' || $password2 === '') { $this->flashMessenger()->addMessage('authentication_error_blank', 'error'); return false; } // Missing or invalid hash if (false == $userFromHash) { $this->flashMessenger()->addMessage('recovery_user_not_found', 'error'); return false; } elseif ($userFromHash->username !== $user->username) { $this->flashMessenger()->addMessage('authentication_error_invalid', 'error'); return false; } // Connect to the ILS and check that the credentials are correct: $catalog = $this->getILS(); $patron = $catalog->patronLogin($card->cat_username, $oldPassword); if (!$patron) { $this->flashMessenger()->addMessage('authentication_error_invalid', 'error'); return false; } if ($password !== $password2) { $this->flashMessenger()->addMessage('Passwords do not match', 'error'); return false; } $result = $catalog->changePassword(['patron' => $patron, 'oldPassword' => $oldPassword, 'newPassword' => $password]); if (!$result['success']) { $this->flashMessenger()->addMessage($result['status'], 'error'); return false; } $user->saveLibraryCard($card->id, $card->card_name, $card->cat_username, $password); if ($user->cat_username === $card->cat_username) { $user->saveCredentials($card->cat_username, $password); } $user->updateHash(); $this->flashMessenger()->addMessage('new_password_success', 'info'); return $this->redirect()->toRoute('librarycards-home'); }