Skip to content

Commit

Permalink
Merge pull request Aspen-Discovery#1742 from catsoup11789/24.04.00
Browse files Browse the repository at this point in the history
API cleanup
  • Loading branch information
mdnoble73 authored Apr 1, 2024
2 parents 2d984d8 + 081f209 commit 868ab59
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 220 deletions.
60 changes: 60 additions & 0 deletions code/web/services/API/AbstractAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,64 @@ function getLiDAVersion() {
}
return 0;
}

function getLiDASession() {
if (function_exists('getallheaders')) {
foreach (getallheaders() as $name => $value) {
if ($name == 'LiDA-SessionID' || $name == 'lida-sessionid') {
$sessionId = explode(' ', $value);
return $sessionId[0];
}
}
}
return false;
}

function getLiDAUserAgent() {
if (function_exists('getallheaders')) {
foreach (getallheaders() as $name => $value) {
if ($name == 'User-Agent' || $name == 'user-agent') {
if (str_contains($value, 'Aspen LiDA') || str_contains($value, 'aspen lida')) {
return true;
}
}
}
}
return false;
}

/**
* @return array
* @noinspection PhpUnused
*/
function loadUsernameAndPassword() {
$username = $_REQUEST['username'] ?? '';
$password = $_REQUEST['password'] ?? '';

if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [$username, $password];
}

/**
* @return bool|User
*/
function getUserForApiCall() {
$user = false;
[$username, $password] = $this->loadUsernameAndPassword();
$user = UserAccount::validateAccount($username, $password);
if ($user !== false && $user->source == 'admin') {
return false;
}
return $user;
}
}
35 changes: 0 additions & 35 deletions code/web/services/API/EventAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,41 +631,6 @@ function getSavedEvents() {
}
}

/**
* @return array
* @noinspection PhpUnused
*/
private function loadUsernameAndPassword() {
$username = $_REQUEST['username'] ?? '';
$password = $_REQUEST['password'] ?? '';

if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [$username, $password];
}

/**
* @return bool|User
*/
protected function getUserForApiCall() {
$user = false;
[$username, $password] = $this->loadUsernameAndPassword();
$user = UserAccount::validateAccount($username, $password);
if ($user !== false && $user->source == 'admin') {
return false;
}
return $user;
}

function getBreadcrumbs(): array {
return [];
}
Expand Down
26 changes: 0 additions & 26 deletions code/web/services/API/ListAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,32 +308,6 @@ function getUserLists() {
];
}

/**
* @return array
* @noinspection PhpUnused
*/
private function loadUsernameAndPassword(): array {
$username = $_REQUEST['username'] ?? '';
$password = $_REQUEST['password'] ?? '';

// check for post request data
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [
$username,
$password,
];
}

/**
* Get's RSS Feed
* @noinspection PhpUnused
Expand Down
44 changes: 0 additions & 44 deletions code/web/services/API/SearchAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2668,50 +2668,6 @@ function getSavedSearchResults() {
return $response;
}

/**
* @return array
* @noinspection PhpUnused
*/
private function loadUsernameAndPassword(): array {
if (isset($_REQUEST['username'])) {
$username = $_REQUEST['username'];
} else {
$username = '';
}
if (isset($_REQUEST['password'])) {
$password = $_REQUEST['password'];
} else {
$password = '';
}

// check for post request data
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [
$username,
$password,
];
}

protected function getUserForApiCall() {
$user = false;
[$username, $password] = $this->loadUsernameAndPassword();
$user = UserAccount::validateAccount($username, $password);
if ($user !== false && $user->source == 'admin') {
return false;
}
return $user;
}

/** @noinspection PhpUnused */
function getAppSearchResults(): array {
global $configArray;
Expand Down
35 changes: 0 additions & 35 deletions code/web/services/API/SystemAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1189,41 +1189,6 @@ function getLibraryLinks() {
}
}

/**
* @return array
* @noinspection PhpUnused
*/
private function loadUsernameAndPassword() {
$username = $_REQUEST['username'] ?? '';
$password = $_REQUEST['password'] ?? '';

if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [$username, $password];
}

/**
* @return bool|User
*/
protected function getUserForApiCall() {
$user = false;
[$username, $password] = $this->loadUsernameAndPassword();
$user = UserAccount::validateAccount($username, $password);
if ($user !== false && $user->source == 'admin') {
return false;
}
return $user;
}

function getBreadcrumbs(): array {
return [];
}
Expand Down
49 changes: 1 addition & 48 deletions code/web/services/API/UserAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -3963,32 +3963,6 @@ function getPaymentDetails($paymentId = null) {
return $result;
}

/**
* @return array
* @noinspection PhpUnused
*/
private function loadUsernameAndPassword(): array {
$username = $_REQUEST['username'] ?? '';
$password = $_REQUEST['password'] ?? '';

// check for post request data
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [
$username,
$password,
];
}

/** @noinspection PhpUnused */
function getBarcodeForPatron(): array {
$results = [
Expand Down Expand Up @@ -4651,7 +4625,7 @@ function getUserByBarcode(): array {
/**
* @return bool|User
*/
protected function getUserForApiCall() {
function getUserForApiCall() {
if ($this->context == 'internal') {
return UserAccount::getActiveUserObj();
} else {
Expand Down Expand Up @@ -4710,27 +4684,6 @@ function getLiDAVersion() {
return 0;
}

function getLiDASession() {
foreach (getallheaders() as $name => $value) {
if ($name == 'LiDA-SessionID' || $name == 'lida-sessionid') {
$sessionId = explode(' ', $value);
return $sessionId[0];
}
}
return false;
}

function getLiDAUserAgent() {
foreach (getallheaders() as $name => $value) {
if ($name == 'User-Agent' || $name == 'user-agent') {
if(str_contains($value, 'Aspen LiDA') || str_contains($value, 'aspen lida')) {
return true;
}
}
}
return false;
}

function getLinkedAccounts() {
$user = $this->getUserForApiCall();

Expand Down
33 changes: 1 addition & 32 deletions code/web/services/API/WorkAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,38 +291,7 @@ public function getIsbnsForWork($permanentId = null) {
return $record['isbn'];
}
}

private function loadUsernameAndPassword() {
$username = $_REQUEST['username'] ?? '';
$password = $_REQUEST['password'] ?? '';

if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
}

if (is_array($username)) {
$username = reset($username);
}
if (is_array($password)) {
$password = reset($password);
}
return [$username, $password];
}

/**
* @return bool|User
*/
protected function getUserForApiCall() {
$user = false;
[$username, $password] = $this->loadUsernameAndPassword();
$user = UserAccount::validateAccount($username, $password);
if ($user !== false && $user->source == 'admin') {
return false;
}
return $user;
}


function getBreadcrumbs(): array {
return [];
}
Expand Down

0 comments on commit 868ab59

Please sign in to comment.