Beispiel #1
0
 /**
  * Verify that the current catalog account is in the account list
  *
  * @param object $user User
  *
  * @return void
  */
 protected static function verifyAccountInList($user)
 {
     if (!isset($user->cat_username) || !$user->cat_username) {
         return;
     }
     $account = new User_account();
     $account->user_id = $user->id;
     $account->cat_username = $user->cat_username;
     if (!$account->find(true)) {
         list($login_target, $cat_username) = explode('.', $account->cat_username, 2);
         if ($login_target && $cat_username) {
             $account->account_name = translate(array('text' => $login_target, 'prefix' => 'source_'));
         } else {
             $account->account_name = translate('Default');
         }
         $account->cat_password = $user->cat_password;
         $account->home_library = $user->home_library;
         $account->created = date('Y-m-d h:i:s');
         $account->insert();
     } else {
         if ($account->cat_password != $user->cat_password) {
             $account->cat_password = $user->cat_password;
             $account->update();
         }
     }
 }
Beispiel #2
0
 /**
  * Validate and save account information after editing
  *
  * @return boolean Success
  */
 protected function saveAccount()
 {
     global $interface;
     global $user;
     $username = $_POST['username'];
     $password = $_POST['password'];
     $loginTarget = isset($_POST['login_target']) ? $_POST['login_target'] : false;
     if ($loginTarget) {
         $username = "******";
     }
     $catalog = ConnectionManager::connectToCatalog();
     $result = $catalog->patronLogin($username, $password);
     if (!$result || PEAR::isError($result)) {
         $interface->assign('errorMsg', $result ? $result->getMessage() : 'authentication_error_failed');
         $this->editAccount(isset($_REQUEST['id']) ? $_REQUEST['id'] : null);
         return false;
     }
     $exists = false;
     $account = new User_account();
     $account->user_id = $user->id;
     if (isset($_REQUEST['id']) && $_REQUEST['id']) {
         $account->id = $_REQUEST['id'];
         $exists = $account->find(true);
     }
     // Check that the user name is not in use in another account
     if (!$exists || $account->cat_username != $username) {
         $otherAccount = new User_account();
         $otherAccount->user_id = $user->id;
         $otherAccount->cat_username = $username;
         if ($otherAccount->find()) {
             $interface->assign('errorMsg', 'Username already in use in another library card');
             $this->editAccount(isset($_REQUEST['id']) ? $_REQUEST['id'] : null);
             return false;
         }
     }
     if (!$exists) {
         $account->created = date('Y-m-d h:i:s');
     } else {
         if ($user->cat_username == $account->cat_username) {
             // Active account modified, update
             UserAccount::activateCatalogAccount($username, $password, $account->home_library);
         }
     }
     $account->account_name = isset($_REQUEST['account_name']) ? $_REQUEST['account_name'] : '-';
     $account->description = isset($_REQUEST['description']) ? $_REQUEST['description'] : '';
     $account->cat_username = $username;
     $account->cat_password = $password;
     if ($exists) {
         $account->update();
     } else {
         $account->insert();
         // If this is the first one, activate it
         if (count($user->getCatalogAccounts()) == 1) {
             UserAccount::activateCatalogAccount($username, $password, $account->home_library);
         }
     }
     return true;
 }