diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index b69d1370315cd438fb327a40e30470787c603887..177049a83f07bf9ccf17cb18435558bb5be08e58 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -163,6 +163,9 @@ class Bootstrap // registered as a shutdown function when using an object as a session // handler: http://us.php.net/manual/en/function.session-set-save-handler.php register_shutdown_function(array($sessionManager, 'writeClose')); + + // Make sure account credentials haven't expired: + $serviceManager->get('AuthManager')->checkForExpiredCredentials(); } /** @@ -204,29 +207,6 @@ class Bootstrap date_default_timezone_set($this->config->Site->timezone); } - /** - * Make account manager available to service manager and views. - * - * @return void - */ - protected function initAccount() - { - // Retrieve from service manager: - $serviceManager = $this->event->getApplication()->getServiceManager(); - $authManager = $serviceManager->get('AuthManager'); - - // Make sure credentials haven't expired: - $authManager->checkForExpiredCredentials(); - - // Register in view: - $callback = function($event) use ($authManager) { - $serviceManager = $event->getApplication()->getServiceManager(); - $viewModel = $serviceManager->get('viewmanager')->getViewModel(); - $viewModel->setVariable('account', $authManager); - }; - $this->events->attach('dispatch', $callback); - } - /** * Set view variables representing the current context. * diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index dd14cd2a795b35c2f989408ef1cbcf6401a55eb7..d2a75c23f296f5a1ad949702ec5abfeb52b6815e 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -1129,7 +1129,6 @@ class AjaxController extends AbstractBase $this->params()->fromQuery('id'), $this->params()->fromQuery('source', 'VuFind') ); - $this->layout()->account = $this->getAuthManager(); $html = $this->getViewRenderer() ->render('record/comments-list.phtml', array('driver' => $driver)); return $this->output($html, self::STATUS_OK); diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Auth.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Auth.php index c7d87063d591b54cf435f1273ac2c76de1803c75..b074db25520e88e62245d26d501b538d15f0c813 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/Auth.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Auth.php @@ -26,7 +26,7 @@ * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ namespace VuFind\Theme\Root\Helper; -use Zend\View\Exception\RuntimeException, Zend\View\Helper\AbstractHelper; +use Zend\View\Exception\RuntimeException; /** * Authentication view helper @@ -37,7 +37,7 @@ use Zend\View\Exception\RuntimeException, Zend\View\Helper\AbstractHelper; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class Auth extends AbstractHelper +class Auth extends AbstractServiceLocator { /** * Render a template within an auth module folder. @@ -56,8 +56,7 @@ class Auth extends AbstractHelper // Get the current auth module's class name, then start a loop // in case we need to use a parent class' name to find the appropriate // template. - $layout = $this->getView()->plugin('layout'); - $className = $layout()->account->getAuthClass(); + $className = $this->getManager()->getAuthClass(); $topClassName = $className; // for error message while (true) { // Guess the template name for the current class: @@ -83,6 +82,27 @@ class Auth extends AbstractHelper } } + /** + * Get manager + * + * @return \VuFind\Auth\Manager + */ + public function getManager() + { + return $this->getServiceLocator()->get('AuthManager'); + } + + /** + * Checks whether the user is logged in. + * + * @return \VuFind\Db\Row\User|bool Object if user is logged in, false + * otherwise. + */ + public function isLoggedIn() + { + return $this->getManager()->isLoggedIn(); + } + /** * Render the create account form fields. * diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml index a6daf89629872e81d2459c0660e276fe084ae64c..8eeec476b1f05b34e938e4820c54fc19ab2f5311 100644 --- a/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml +++ b/themes/blueprint/templates/RecordDriver/SolrDefault/tab-holdings.phtml @@ -1,7 +1,8 @@ <? // Set up convenience variables: - $user = $this->layout()->account->isLoggedIn(); - $holdings = $this->driver->getRealTimeHoldings($this->layout()->account); + $account = $this->auth()->getManager(); + $user = $account->isLoggedIn(); + $holdings = $this->driver->getRealTimeHoldings($account); $openUrl = $this->driver->openURLActive('holdings') ? $this->driver->getOpenURL() : false; $offlineMode = $this->ils()->getOfflineMode(); // Account for replace_other_urls setting @@ -20,7 +21,7 @@ </div> <? endif; ?> <? if ((\VuFind\ILS\Connection::getHoldsMode() == 'driver' && !empty($holdings)) || \VuFind\ILS\Connection::getTitleHoldsMode() == 'driver'): ?> - <? if ($this->layout()->account->loginEnabled() && $offlineMode != 'ils-offline'): ?> + <? if ($account->loginEnabled() && $offlineMode != 'ils-offline'): ?> <? if (!$user): ?> <div class="info"> <a href="<?=$this->currentPath()?>?login=true&catalogLogin=true"><?=$this->transEsc("Login")?></a> <?=$this->transEsc("hold_login")?> @@ -32,7 +33,7 @@ <? endif; ?> <? endif; ?> <? endif; ?> -<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold', array($this->layout()->account)); if (!empty($holdingTitleHold)): ?> +<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold', array($account)); if (!empty($holdingTitleHold)): ?> <a class="holdPlace" href="<?=$this->recordLink()->getHoldUrl($holdingTitleHold)?>"><?=$this->transEsc('title_hold_place')?></a> <? endif; ?> <? if (!empty($urls) || $openUrl): ?> diff --git a/themes/blueprint/templates/header.phtml b/themes/blueprint/templates/header.phtml index 3a734a1dba66f495b62d7c10ad2b00e76c519eae..27c2e6c3a0e3347cc9a874c0c8555b3c1c066aa3 100644 --- a/themes/blueprint/templates/header.phtml +++ b/themes/blueprint/templates/header.phtml @@ -1,4 +1,4 @@ -<? $account = $this->layout()->account; ?> +<? $account = $this->auth()->getManager(); ?> <a id="logo" href="<?=$this->url('home')?>"></a> <div id="headerRight"> <? $cart = $this->cart(); if ($cart->isActive()): ?> diff --git a/themes/blueprint/templates/myresearch/bulk-action-buttons.phtml b/themes/blueprint/templates/myresearch/bulk-action-buttons.phtml index 39228c24ec42c582ea028aa9b1708ffc6a43b045..c7bd1690bf5ff919a0bdd5dffc2aa22fdcea47c0 100644 --- a/themes/blueprint/templates/myresearch/bulk-action-buttons.phtml +++ b/themes/blueprint/templates/myresearch/bulk-action-buttons.phtml @@ -1,4 +1,4 @@ -<? $user = $this->layout()->account->isLoggedIn(); ?> +<? $user = $this->auth()->isLoggedIn(); ?> <div class="bulkActionButtons"> <input type="checkbox" class="selectAllCheckboxes floatleft" name="selectAll" id="<?=$this->idPrefix?>addFormCheckboxSelectAll"/> <label class="floatleft" for="addFormCheckboxSelectAll"><?=$this->transEsc('select_page')?></label> <span class="floatleft">|</span> diff --git a/themes/blueprint/templates/myresearch/login.phtml b/themes/blueprint/templates/myresearch/login.phtml index 90bf7b92d1b0b99479df221af760c8e73ccb7268..3b5ef81ec930a74eda82076f474917ee7db52714 100644 --- a/themes/blueprint/templates/myresearch/login.phtml +++ b/themes/blueprint/templates/myresearch/login.phtml @@ -13,7 +13,7 @@ } // Convenience variables: - $account = $this->layout()->account; + $account = $this->auth()->getManager(); $hideLogin = !(is_object($account) && $account->loginEnabled()); $offlineMode = $this->ils()->getOfflineMode(); ?> diff --git a/themes/blueprint/templates/myresearch/mylist.phtml b/themes/blueprint/templates/myresearch/mylist.phtml index 3f37bee9fb7c6ebc4edb71e79a8ff05e7306c2ad..594ca91ca6f24b8434940072471687e29ce5fdd6 100644 --- a/themes/blueprint/templates/myresearch/mylist.phtml +++ b/themes/blueprint/templates/myresearch/mylist.phtml @@ -15,7 +15,7 @@ $this->headScript()->appendFile("bulk_actions.js"); // Convenience variable: - $account = $this->layout()->account; + $account = $this->auth()->getManager(); ?> <?=$this->flashmessages()?> diff --git a/themes/blueprint/templates/record/comments-list.phtml b/themes/blueprint/templates/record/comments-list.phtml index e724959c685ecc3f8e004138858427eeb7cddb11..0a2af48c9bf850fcf35fb66b9e3d371bf1bcabcb 100644 --- a/themes/blueprint/templates/record/comments-list.phtml +++ b/themes/blueprint/templates/record/comments-list.phtml @@ -7,7 +7,7 @@ <div class="posted"> <?=$this->transEsc('Posted by')?> <strong><?=$this->escapeHtml(trim($comment->firstname . ' ' . $comment->lastname))?></strong> <?=$this->transEsc('posted_on')?> <?=$this->escapeHtml($comment->created)?> - <? if (($user = $this->layout()->account->isLoggedIn()) && $comment->user_id == $user->id): ?> + <? if (($user = $this->auth()->isLoggedIn()) && $comment->user_id == $user->id): ?> <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'DeleteComment')?>?delete=<?=urlencode($comment->id)?>" id="recordComment<?=$this->escapeHtml($comment->id)?>" class="delete tool deleteRecordComment source<?=$this->escapeHtml($this->driver->getResourceSource())?>"><?=$this->transEsc('Delete')?></a> <? endif; ?> </div> diff --git a/themes/blueprint/templates/search/history.phtml b/themes/blueprint/templates/search/history.phtml index 8312be110e779a3359d673647b90390098e8c9a7..c36446774a59c61505d1e80e9849e5f2bb56e3f0 100644 --- a/themes/blueprint/templates/search/history.phtml +++ b/themes/blueprint/templates/search/history.phtml @@ -27,7 +27,7 @@ <?=$this->context($this)->renderInContext( "myresearch/menu.phtml", // Only activate search history in account menu if user is logged in. - $this->layout()->account->isLoggedIn() ? array('active' => 'history') : array() + $this->auth()->isLoggedIn() ? array('active' => 'history') : array() ); ?> </div> diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml index a2283e1bdf57bf929df3bccf0f4929a06b7517c7..c80ed848e83bb4d0e283aac45caedcb92b19f764 100644 --- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml +++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-holdings.phtml @@ -1,7 +1,8 @@ <? // Set up convenience variables: - $user = $this->layout()->account->isLoggedIn(); - $holdings = $this->driver->getRealTimeHoldings($this->layout()->account); + $account = $this->auth()->getManager(); + $user = $account->isLoggedIn(); + $holdings = $this->driver->getRealTimeHoldings($account); $offlineMode = $this->ils()->getOfflineMode(); // Set page title. @@ -17,7 +18,7 @@ </div> <? endif; ?> <? if ((\VuFind\ILS\Connection::getHoldsMode() == 'driver' && !empty($holdings)) || \VuFind\ILS\Connection::getTitleHoldsMode() == 'driver'): ?> - <? if ($this->layout()->account->loginEnabled() && $offlineMode != 'ils-offline'): ?> + <? if ($account->loginEnabled() && $offlineMode != 'ils-offline'): ?> <? if (!$user): ?> <div class="info"> <a href="<?=$this->currentPath()?>?login=true&catalogLogin=true"><?=$this->transEsc("Login")?></a> <?=$this->transEsc("hold_login")?> @@ -29,7 +30,7 @@ <? endif; ?> <? endif; ?> <? endif; ?> -<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold', array($this->layout()->account)); if (!empty($holdingTitleHold)): ?> +<? $holdingTitleHold = $this->driver->tryMethod('getRealTimeTitleHold', array($account)); if (!empty($holdingTitleHold)): ?> <a rel="external" class="holdPlace" href="<?=$this->recordLink()->getHoldUrl($holdingTitleHold, false)?>"><?=$this->transEsc('title_hold_place')?></a> <? endif; ?> <? foreach ($holdings as $location => $holding): ?> diff --git a/themes/jquerymobile/templates/default-footer-navbar.phtml b/themes/jquerymobile/templates/default-footer-navbar.phtml index 7637a414779da5053f5bcae5fa01f68d70b0e6f4..9229aee1e312e2ee7e4478a834d8c15953d9d7c8 100644 --- a/themes/jquerymobile/templates/default-footer-navbar.phtml +++ b/themes/jquerymobile/templates/default-footer-navbar.phtml @@ -1,4 +1,4 @@ -<? $account = $this->layout()->account; ?> +<? $account = $this->auth()->getManager(); ?> <div data-role="navbar"> <ul> <li><a data-rel="dialog" href="#Language-dialog" data-transition="pop"><?=$this->transEsc('Language')?></a></li> diff --git a/themes/jquerymobile/templates/myresearch/footer-navbar.phtml b/themes/jquerymobile/templates/myresearch/footer-navbar.phtml index 2343dc6de810f68e9b1a305a1fc43dcf1aa2e1cb..a4f498d1886a44777ec25496e575cde0fa2a61a2 100644 --- a/themes/jquerymobile/templates/myresearch/footer-navbar.phtml +++ b/themes/jquerymobile/templates/myresearch/footer-navbar.phtml @@ -1,4 +1,4 @@ -<? if ($this->layout()->account->isLoggedIn()): ?> +<? if ($this->auth()->isLoggedIn()): ?> <div data-role="navbar"> <ul> <li><a rel="external" <?=$this->layout()->templateName=="mylist" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-favorites')?>"><?=$this->transEsc('Favorites')?></a></li> diff --git a/themes/jquerymobile/templates/myresearch/header-navbar.phtml b/themes/jquerymobile/templates/myresearch/header-navbar.phtml index 97f4fc98036776fefbd8babb15efec7f1abc91a9..5ae80636b5ce2e618f6d0355356088631d0e9141 100644 --- a/themes/jquerymobile/templates/myresearch/header-navbar.phtml +++ b/themes/jquerymobile/templates/myresearch/header-navbar.phtml @@ -1,4 +1,4 @@ -<? if ($this->layout()->account->isLoggedIn()): ?> +<? if ($this->auth()->isLoggedIn()): ?> <div data-role="navbar"> <ul> <li><a rel="external" <?=$this->layout()->templateName=="checkedout" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-checkedout')?>"><?=$this->transEsc('Checked Out')?></a></li> diff --git a/themes/jquerymobile/templates/myresearch/login.phtml b/themes/jquerymobile/templates/myresearch/login.phtml index 09e14869dd34cc740bbdd5be156c6fe57526fdbb..9bfee6ec31001dfd8bde7eb8dd8149c67c0bbc11 100644 --- a/themes/jquerymobile/templates/myresearch/login.phtml +++ b/themes/jquerymobile/templates/myresearch/login.phtml @@ -3,7 +3,7 @@ $this->headTitle($this->translate('Login')); // Convenience variables: - $account = $this->layout()->account; + $account = $this->auth()->getManager(); $hideLogin = !(is_object($account) && $account->loginEnabled()); $offlineMode = $this->ils()->getOfflineMode(); ?> diff --git a/themes/jquerymobile/templates/myresearch/mylist.phtml b/themes/jquerymobile/templates/myresearch/mylist.phtml index a3aeaaeffaba9cae84f850d5a5dc0b0c724c2943..60bd3abe4dbf670b32ab6c2f2d269bb8eb4bbbb8 100644 --- a/themes/jquerymobile/templates/myresearch/mylist.phtml +++ b/themes/jquerymobile/templates/myresearch/mylist.phtml @@ -2,11 +2,14 @@ // Grab list object from search results (if applicable): $list = $this->results->getListObject(); + // Grab current user (if any): + $user = $this->auth()->isLoggedIn(); + // Set up page title: $this->headTitle(isset($list) ? $list->title : $this->translate('Favorites')); // Set up extra button for header: - $extraButton = isset($list) + $extraButton = (isset($list) && $list->editAllowed($user)) ? '<a rel="external" href="' . $this->url('editList', array('id' => $list->id)) . '" data-icon="gear" class="ui-btn-left">' @@ -40,7 +43,7 @@ <ul class="results mylist" data-role="listview" data-split-icon="minus" data-split-theme="d" data-inset="false"> <? $i = 0; foreach ($this->results->getResults() as $current): ?> <li> - <?=$this->record($current)->getListEntry($list, $this->layout()->account->isLoggedIn())?> + <?=$this->record($current)->getListEntry($list, $user)?> </li> <? endforeach; ?> </ul> diff --git a/themes/jquerymobile/templates/record/comments-list.phtml b/themes/jquerymobile/templates/record/comments-list.phtml index f13dab69f70321b0ccb2c972df7b6e96b7af68a4..dd26920de57c595a9b70b6990f6c48b6f05cd4f0 100644 --- a/themes/jquerymobile/templates/record/comments-list.phtml +++ b/themes/jquerymobile/templates/record/comments-list.phtml @@ -8,7 +8,7 @@ <p class="posted-by"><?=$this->transEsc('Posted by')?> <strong><?=$this->escapeHtml(trim($comment->firstname . ' ' . $comment->lastname))?></strong></p> <span class="ui-li-aside"><?=$this->escapeHtml(array_shift(explode(' ', $comment->created)))?></span> </a> - <? if (($user = $this->layout()->account->isLoggedIn()) && $comment->user_id == $user->id): ?> + <? if (($user = $this->auth()->isLoggedIn()) && $comment->user_id == $user->id): ?> <a rel="external" href="<?=$this->recordLink()->getActionUrl($this->driver, 'DeleteComment')?>?delete=<?=urlencode($comment->id)?>" data-comment-id="<?=$this->escapeHtml($comment->id)?>" class="deleteRecordComment"> <?=$this->transEsc('Delete')?> </a> diff --git a/themes/root/templates/Email/record-sms.phtml b/themes/root/templates/Email/record-sms.phtml index d0cd4c734a6061b033235392325b6fceaf5a13ee..5deb7dbf740d5979e0bd3e5827c6d3f63d33718a 100644 --- a/themes/root/templates/Email/record-sms.phtml +++ b/themes/root/templates/Email/record-sms.phtml @@ -7,7 +7,7 @@ // since text messages can be short, and we want the most important stuff // at the top! if ($this->driver->supportsAjaxStatus()) { - $holdings = $this->driver->getRealTimeHoldings($this->layout()->account); + $holdings = $this->driver->getRealTimeHoldings($this->auth()->getManager()); $locations = array_keys($holdings); if (isset($locations[0])) { if (isset($holdings[$locations[0]]['items'][0]['callnumber'])) {