Example #1
0
 /**
  * Return logout text after user has logged out.
  * Shown only after the first page load if loggedOut param is true.
  *
  * @return string Logout message
  */
 public function __invoke()
 {
     if ($this->authManager->userHasLoggedOut() && $this->request->getQuery('logout', false)) {
         if (!isset($this->session->logoutMessageShown) || !$this->session->logoutMessageShown) {
             $this->session->logoutMessageShown = true;
             return 'logout_success_message';
         }
     }
     return false;
 }
Example #2
0
 public function handleSort(Manager $manager, Parameters $request, $defaultSort, $target)
 {
     $user = $manager->isLoggedIn();
     $requestParams = $request->toArray();
     if ($user) {
         //in case user changed the the sort settings on the result list with a specialized UI control
         //we want to serialize the new value in database
         if (array_key_exists('sortControlElement', $requestParams)) {
             if (array_key_exists('sort', $requestParams)) {
                 $sort = $requestParams['sort'];
                 $dbSort = unserialize($user->default_sort);
                 $dbSort[$target] = $requestParams['sort'];
                 $user->default_sort = serialize($dbSort);
                 $user->save();
             } else {
                 $tSort = $request->get('sort');
                 $sort = !empty($tSort) ? $tSort : $defaultSort;
             }
         } else {
             $tSort = $request->get('sort');
             $sort = !empty($tSort) ? $tSort : $defaultSort;
             //overwrite sort if value is set in database
             if ($user->default_sort) {
                 $userDefaultSort = unserialize($user->default_sort);
                 if (isset($userDefaultSort[$target])) {
                     $sort = $userDefaultSort[$target];
                 }
             }
         }
     } else {
         $sort = $request->get('sort');
     }
     // Check for special parameter only relevant in RSS mode:
     if ($request->get('skip_rss_sort', 'unset') != 'unset') {
         $this->skipRssSort = true;
     }
     return $sort;
 }
 /**
  * User's Library cards (home_library values)
  *
  * @return	array
  */
 public function getUsersHomeLibraries()
 {
     if ($this->useLibraryCardsForPriority && ($user = $this->authManager->isLoggedIn())) {
         // is loggedIn
         $libraryCards = $user->getLibraryCards()->toArray();
         $myLibs = array();
         foreach ($libraryCards as $libCard) {
             $homeLib = $libCard['home_library'];
             $myLibs[] = $homeLib;
         }
         return array_unique($myLibs);
     }
     return [];
 }
Example #4
0
 /**
  * Try to log in the user using current query parameters; return User object
  * on success, throws exception on failure.
  *
  * @param \Zend\Http\PhpEnvironment\Request $request Request object containing
  * account credentials.
  *
  * @throws AuthException
  * @return User Object representing logged-in user.
  */
 public function login($request)
 {
     $user = parent::login($request);
     $auth = $this->getAuth();
     if ($auth instanceof ChoiceAuth) {
         $method = $auth->getSelectedAuthOption();
     } else {
         $method = $this->activeAuth;
     }
     $user->finna_auth_method = strtolower($method);
     $user->finna_last_login = date('Y-m-d H:i:s');
     $user->save();
     return $user;
 }
 /**
  * Attempt to log in the user to the ILS, and save credentials if it works.
  *
  * @param string $username Catalog username
  * @param string $password Catalog password
  *
  * Returns associative array of patron data on success, false on failure.
  *
  * @return array|bool
  * @throws ILSException
  */
 public function newCatalogLogin($username, $password)
 {
     $result = $this->catalog->patronLogin($username, $password);
     if ($result) {
         $user = $this->auth->isLoggedIn();
         if ($user) {
             $user->saveCredentials($username, $password);
             $this->auth->updateSession($user);
             // cache for future use
             $this->ilsAccount[$username] = $result;
         }
         return $result;
     }
     return false;
 }
 /**
  * Is a user account capable of saving data currently available?
  *
  * @return bool
  */
 protected function isAccountAvailable()
 {
     // We can't use account features if login is broken or privacy is on:
     return $this->auth->loginEnabled() && !$this->auth->inPrivacyMode();
 }
Example #7
0
 /**
  * Construct the authentication manager.
  *
  * @param ServiceManager $sm Service manager.
  *
  * @return Manager
  */
 public static function getManager(ServiceManager $sm)
 {
     // Set up configuration:
     $config = $sm->get('VuFind\\Config')->get('config');
     try {
         // Check if the catalog wants to hide the login link, and override
         // the configuration if necessary.
         $catalog = $sm->get('VuFind\\ILSConnection');
         if ($catalog->loginIsHidden()) {
             $config = new \Zend\Config\Config($config->toArray(), true);
             $config->Authentication->hideLogin = true;
             $config->setReadOnly();
         }
     } catch (\Exception $e) {
         // Ignore exceptions; if the catalog is broken, throwing an exception
         // here may interfere with UI rendering. If we ignore it now, it will
         // still get handled appropriately later in processing.
         error_log($e->getMessage());
     }
     // Load remaining dependencies:
     $userTable = $sm->get('VuFind\\DbTablePluginManager')->get('user');
     $sessionManager = $sm->get('VuFind\\SessionManager');
     $pm = $sm->get('VuFind\\AuthPluginManager');
     $cookies = $sm->get('VuFind\\CookieManager');
     // Build the object and make sure account credentials haven't expired:
     $manager = new Manager($config, $userTable, $sessionManager, $pm, $cookies);
     $manager->checkForExpiredCredentials();
     return $manager;
 }
Example #8
0
 /**
  * Get user institutions from database
  *
  * @return    String[]
  */
 protected function getFromDatabase()
 {
     $favoriteList = $this->authManager->isLoggedIn()->favorite_institutions;
     return $favoriteList ? explode(',', $favoriteList) : array();
 }
Example #9
0
 /**
  * Determines whether or not the current user session is identifed as a guest
  * session
  *
  * @return string 'y'|'n'
  */
 protected function isGuest()
 {
     // If the user is not logged in, then treat them as a guest. Unless they are
     // using IP Authentication.
     // If IP Authentication is used, then don't treat them as a guest.
     if ($this->ipAuth) {
         return 'n';
     }
     if (isset($this->authManager)) {
         return $this->authManager->isLoggedIn() ? 'n' : 'y';
     }
     return 'y';
 }
Example #10
0
 /**
  * Log out the current user.
  *
  * @param string $url
  *            URL to redirect user to after logging out.
  * @param bool $destroy
  *            Should we destroy the session (true) or just reset it
  *            (false); destroy is for log out, reset is for expiration.
  * @param bool $isGlobalLogout
  *            Is global logout? Or do we want only local logout, so that
  *            we the remove current session & prompt for proper redirection?
  *
  * @return string Redirect URL (usually same as $url, but modified in
  *         some authentication modules).
  */
 public function logout($url, $destroy = true)
 {
     return parent::logout($url, $destroy);
 }
Example #11
0
 /**
  * Constructor
  *
  * @param \Zend\Config\Config $config VuFind configuration
  */
 public function __construct(Config $config, UserTable $userTable, SessionManager $sessionManager, PluginManager $pm, CookieManager $cookieManager)
 {
     parent::__construct($config, $userTable, $sessionManager, $pm, $cookieManager);
 }
Example #12
0
 /**
  * Check whether user is logged in
  *
  * @return Boolean
  */
 protected function isLoggedIn()
 {
     return $this->authManager->isLoggedIn() !== false;
 }