From 0347b734d4cfb5e67cb2a6078ccfae482b9daf7f Mon Sep 17 00:00:00 2001 From: John Houser <90853393+john-c-houser@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:57:49 -0800 Subject: [PATCH 1/3] Change resetPatronPassword to use PATRON role --- src/Libilsws.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libilsws.php b/src/Libilsws.php index 642d855..d4cd40d 100644 --- a/src/Libilsws.php +++ b/src/Libilsws.php @@ -1326,7 +1326,7 @@ public function reset_patron_password ($token = null, $patron_id = null, $url = $json = json_encode($data); - return $this->send_query("$this->base_url/user/patron/resetMyPassword", $token, $json, 'POST'); + return $this->send_query("$this->base_url/user/patron/resetMyPassword", $token, $json, 'POST', 'PATRON'); } /** From fcd565a488c31787ce9ea259026632f8f6dad247 Mon Sep 17 00:00:00 2001 From: John Houser <90853393+john-c-houser@users.noreply.github.com> Date: Tue, 20 Feb 2024 10:51:55 -0800 Subject: [PATCH 2/3] Allow the password reset function to use a different client ID from the default --- README.md | 2 +- src/Libilsws.php | 17 ++++++++++++----- test/register_staff.php | 2 +- test/reset_patron_password.php | 5 ++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ba1ee37..a08ab5b 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ or evaluating data from the Symphony system. - get_patron_indexes($token) - prepare_search($terms) - register_patron($patron, $token, $addr_num, $role, $template, $subject) -- reset_patron_password($token, $patron_id, $url, $email) +- reset_patron_password($token, $patron_id, $url, $email, $role, $client_id) - search_authenticate($token, $index, $search, $password) - search_bib($token, $index, $value, $params) - update_patron($patron, $token, $patron_key, $addr_num) diff --git a/src/Libilsws.php b/src/Libilsws.php index d4cd40d..7fccc88 100644 --- a/src/Libilsws.php +++ b/src/Libilsws.php @@ -299,7 +299,7 @@ public function send_get ($url = null, $token = null, $params = null) * @return object $response Associative array containing the response from ILSWS */ - public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'STAFF', $header = '') + public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'STAFF', $client_id = '', $header = '') { $this->validate('url', $url, 'u'); $this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#'); @@ -307,6 +307,12 @@ public function send_query ($url = null, $token = null, $query_json = null, $que $this->validate('header', $header, 's:40'); $this->validate('role', $role, 'v:STAFF|PATRON'); + if ( $client_id ) { + $this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#'); + } else { + $client_id = $this->config['ilsws']['client_id']; + } + if ( $query_json ) { $this->validate('query_json', $query_json, 'j'); } @@ -322,7 +328,7 @@ public function send_query ($url = null, $token = null, $query_json = null, $que "SD-Response-Tracker: $req_num", "SD-Preferred-Role: $role", 'SD-Prompt-Return: USER_PRIVILEGE_OVRCD/' . $this->config['ilsws']['user_privilege_override'], - 'x-sirs-clientID: ' . $this->config['ilsws']['client_id'], + 'x-sirs-clientID: ' . $client_id, "x-sirs-sessionToken: $token", ]; @@ -1285,13 +1291,14 @@ public function delete_patron ($token = null, $patron_key = null) * @return object Associative array containing response from ILSWS */ - public function change_patron_password ($token = null, $json = null) + public function change_patron_password ($token = null, $json = null, $client_id = null) { $this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#'); $this->validate('json', $json, 'j'); + $this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#'); - return $this->send_query("$this->base_url/user/patron/changeMyPassword", $token, $json, 'POST'); + return $this->send_query("$this->base_url/user/patron/changeMyPassword", $token, $json, 'POST', 'PATRON'); } /** @@ -1326,7 +1333,7 @@ public function reset_patron_password ($token = null, $patron_id = null, $url = $json = json_encode($data); - return $this->send_query("$this->base_url/user/patron/resetMyPassword", $token, $json, 'POST', 'PATRON'); + return $this->send_query("$this->base_url/user/patron/resetMyPassword", $token, $json, 'POST', 'STAFF'); } /** diff --git a/test/register_staff.php b/test/register_staff.php index 6356b68..006c89c 100644 --- a/test/register_staff.php +++ b/test/register_staff.php @@ -17,7 +17,7 @@ 'city_state' => 'Portland, OR', 'county' => '0_MULT', 'profile' => '0_MULT', - 'patron_id' => '99999999999997', + 'patron_id' => '99999999999996', 'email' => 'johnchouser@gmail.com', 'firstName' => 'Bogus', 'friends_notices' => 'YES', diff --git a/test/reset_patron_password.php b/test/reset_patron_password.php index b23e351..722aa9d 100644 --- a/test/reset_patron_password.php +++ b/test/reset_patron_password.php @@ -18,7 +18,10 @@ // Connect and get token $token = $ilsws->connect(); -$response = $ilsws->reset_patron_password($token, $barcode, $url, $email); +$role = 'PATRON'; // Used in the SD-Preferred-Role HTTP header +$client_id = 'QUIPU'; // Used in the x-sirs-clientID HTTP header + +$response = $ilsws->reset_patron_password($token, $barcode, $url, $email, $role, $client_id); $json = json_encode($response, JSON_PRETTY_PRINT); print "$json\n\n"; From d83d0f1319d39a86fa8266e8c8e5e25f45fb0417 Mon Sep 17 00:00:00 2001 From: John Houser <90853393+john-c-houser@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:35:21 -0800 Subject: [PATCH 3/3] Allow the password reset function to use a different client ID from the default --- README.md | 7 +++++-- src/Libilsws.php | 30 +++++++++++++++++++++--------- test/register_patron.php | 6 ++++-- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a08ab5b..264ad95 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ or evaluating data from the Symphony system. - get_patron_checkouts($token, $patron_key, $include_fields) - get_patron_indexes($token) - prepare_search($terms) -- register_patron($patron, $token, $addr_num, $role, $template, $subject) +- register_patron($patron, $token, $addr_num, $role, $client_id, $template, $subject) - reset_patron_password($token, $patron_id, $url, $email, $role, $client_id) - search_authenticate($token, $index, $search, $password) - search_bib($token, $index, $value, $params) @@ -165,7 +165,10 @@ $patron = [ ]; $addr_num = 1; -$response = $ilsws->register_patron($patron, $token, $addr_num, $template); +$role = 'STAFF'; +$client_id = 'StaffClient'; + +$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $client_id, $template); ``` ### Update Patron Record diff --git a/src/Libilsws.php b/src/Libilsws.php index 7fccc88..46ba3f5 100644 --- a/src/Libilsws.php +++ b/src/Libilsws.php @@ -299,13 +299,13 @@ public function send_get ($url = null, $token = null, $params = null) * @return object $response Associative array containing the response from ILSWS */ - public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'STAFF', $client_id = '', $header = '') + public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'PATRON', $client_id = '', $header = '') { $this->validate('url', $url, 'u'); $this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#'); $this->validate('query_type', $query_type, 'v:POST|PUT|DELETE'); $this->validate('header', $header, 's:40'); - $this->validate('role', $role, 'v:STAFF|PATRON'); + $this->validate('role', $role, 'v:STAFF|PATRON|GUEST'); if ( $client_id ) { $this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#'); @@ -328,7 +328,7 @@ public function send_query ($url = null, $token = null, $query_json = null, $que "SD-Response-Tracker: $req_num", "SD-Preferred-Role: $role", 'SD-Prompt-Return: USER_PRIVILEGE_OVRCD/' . $this->config['ilsws']['user_privilege_override'], - 'x-sirs-clientID: ' . $client_id, + "x-sirs-clientID: $client_id", "x-sirs-sessionToken: $token", ]; @@ -1291,14 +1291,20 @@ public function delete_patron ($token = null, $patron_key = null) * @return object Associative array containing response from ILSWS */ - public function change_patron_password ($token = null, $json = null, $client_id = null) + public function change_patron_password ($token = null, $json = null, $role = 'PATRON', $client_id = '') { $this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#'); $this->validate('json', $json, 'j'); - $this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#'); + $this->validate('role', $role, 'v:PATRON|STAFF|GUEST'); - return $this->send_query("$this->base_url/user/patron/changeMyPassword", $token, $json, 'POST', 'PATRON'); + if ( $client_id ) { + $this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#'); + } else { + $client_id = $this->config['ilsws']['client_id']; + } + + return $this->send_query("$this->base_url/user/patron/changeMyPassword", $token, $json, $role, $client_id); } /** @@ -2266,12 +2272,18 @@ private function create_register_json ($patron, $token = null, $addr_num = 1) * @return object $response Associative array containing response from ILSWS */ - public function register_patron ($patron, $token = null, $addr_num = null, $role = null, $template = '', $subject = '') + public function register_patron ($patron, $token = null, $addr_num = null, $role = 'PATRON', $client_id = '', $template = '', $subject = '') { $this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#'); $this->validate('addr_num', $addr_num, 'r:#^[123]{1}$#'); $this->validate('template', $template, 'r:#^([a-zA-Z0-9]{1,40})(\.)(html|text)(\.)(twig)$#'); - $this->validate('role', $role, 'v:STAFF|PATRON'); + $this->validate('role', $role, 'v:STAFF|PATRON|GUEST'); + + if ( $client_id ) { + $this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#'); + } else { + $client_id = $this->config['ilsws']['client_id']; + } $response = []; @@ -2322,7 +2334,7 @@ public function register_patron ($patron, $token = null, $addr_num = null, $role } // Send initial registration (and generate email) - $response = $this->send_query("$this->base_url/user/patron", $token, $json, 'POST', $role); + $response = $this->send_query("$this->base_url/user/patron", $token, $json, 'POST', $role, $client_id); if ( !empty($response['key']) ) { $patron_key = $response['key']; diff --git a/test/register_patron.php b/test/register_patron.php index 9539bc1..edc1996 100644 --- a/test/register_patron.php +++ b/test/register_patron.php @@ -44,8 +44,10 @@ $addr_num = 1; $template = 'registration_email.html.twig'; -$role = 'STAFF'; -$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $template, 'Waffles are good'); +$role = 'STAFF'; // Used in the SD-Preferred-Role HTTP header +$client_id = 'QUIPU'; // Used in the x-sirs-clientID HTTP header + +$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $client_id, $template, 'Waffles are good'); print json_encode($response, JSON_PRETTY_PRINT) . "\n"; // EOF