/** * Returns all users that have not been active for given amount of days. * * @param int $days Preserve users active less than provided amount of days ago * * @return User[] Expired users */ protected function getExpiredUsers($days) { $expireDate = date('Y-m-d', strtotime(sprintf('-%d days', (int) $days))); return $this->table->select(function (Select $select) use($expireDate) { $select->where->notLike('username', 'deleted:%'); $select->where->lessThan('finna_last_login', $expireDate); $select->where->notEqualTo('finna_last_login', '0000-00-00 00:00:00'); }); }
/** * Checks whether the user is logged in. * * @return UserRow|bool Object if user is logged in, false otherwise. */ public function isLoggedIn() { // If user object is not in cache, but user ID is in session, // load the object from the database: if (!$this->currentUser && isset($this->session->userId)) { $results = $this->userTable->select(['id' => $this->session->userId]); $this->currentUser = count($results) < 1 ? false : $results->current(); } return $this->currentUser; }
/** * Run service. * * @param array $arguments Command line arguments. * * @return boolean success */ public function run($arguments) { if (!isset($arguments[0]) || $arguments[0] != 'Y') { echo "Usage:\n php index.php util encrypt_catalog_passwords Y\n\n" . " Encrypt ILS passwords of all users and their library cards.\n"; return false; } if (!isset($this->config->Authentication->encrypt_ils_password) || !$this->config->Authentication->encrypt_ils_password) { echo "Encryption not enabled in config (check Authentication section)\n"; return false; } $callback = function ($select) { $select->where->notLike('username', 'deleted:%'); }; $users = $this->table->select($callback); $count = 0; $usersChanged = 0; $cardsChanged = 0; foreach ($users as $user) { echo "Checking user: "******"\n"; if (null !== $user->cat_password) { $user->saveCredentials($user->cat_username, $user->cat_password); ++$usersChanged; echo " Password encrypted\n"; } if ($user->libraryCardsEnabled()) { foreach ($user->getLibraryCards() as $card) { if (null !== $card->cat_password) { try { $user->saveLibraryCard($card->id, $card->card_name, $card->cat_username, $card->cat_password, $card->home_library); echo " Library card {$card->id} password encrypted\n"; } catch (\VuFind\Exception\LibraryCard $e) { // @codingStandardsIgnoreLine if ($e->getMessage() == 'Username is already in use in another library card') { // Duplicate library card, remove it $user->deleteLibraryCard($card->id); echo " ***** Library card {$card->id}: " . "removed duplicate *****\n"; } } ++$cardsChanged; } } } ++$count; } if ($count === 0) { echo "No users found\n"; } else { echo "{$count} users processed with {$usersChanged} users" . " and {$cardsChanged} library cards encypted\n"; } return true; }
/** * Checks whether the user is logged in. * * @return UserRow|bool Object if user is logged in, false otherwise. */ public function isLoggedIn() { // If user object is not in cache, but user ID is in session, // load the object from the database: if (!$this->currentUser) { if (isset($this->session->userId)) { // normal mode $results = $this->userTable->select(['id' => $this->session->userId]); $this->currentUser = count($results) < 1 ? false : $results->current(); } else { if (isset($this->session->userDetails)) { // privacy mode $results = $this->userTable->createRow(); $results->exchangeArray($this->session->userDetails); $this->currentUser = $results; } else { // unexpected state $this->currentUser = false; } } } return $this->currentUser; }
/** * Constructor * * @param Config $config VuFind configuration * @param string $rowClass Name of class for representing rows * @param Container $session Session container to inject into rows (optional; * used for privacy mode) */ public function __construct(Config $config, $rowClass = 'Finna\\Db\\Row\\User', Container $session = null) { parent::__construct($config, $rowClass, $session); }
/** * Constructor * * @param \Zend\Config\Config $config VuFind configuration */ public function __construct(\Zend\Config\Config $config) { parent::__construct($config); $this->rowClass = 'Finna\\Db\\Row\\User'; }