Skip to content

Commit

Permalink
Merge pull request #3 from ebsco/Claus_Updates
Browse files Browse the repository at this point in the history
Minor Bug Fixes / Session Handling Improved
  • Loading branch information
rvandelzen authored Aug 8, 2018
2 parents 253f824 + a045c27 commit b3e5f32
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
8 changes: 6 additions & 2 deletions app/views/results.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<div class="autosuggestedterms">Did you mean:
<?php
foreach($results['autoSuggest'] as $suggestion){
$as = 0;
$query = $_REQUEST;
$query['query'] = (string)$suggestion;
$newQuery = http_build_query($query);
Expand Down Expand Up @@ -461,7 +462,7 @@
}
}
if(!empty($rsData)){
buildResearchStarterPlacard($rsData, $empCount);
buildResearchStarterPlacard($rsData, $empCount, $fieldCode, $encodedHighLigtTerm, $encodedSearchTerm);
}
if(!empty($empData)){
buildExactMatchPlacard($empData, $rsCount);
Expand Down Expand Up @@ -769,7 +770,7 @@

<?php

function buildResearchStarterPlacard($relRec, $count){
function buildResearchStarterPlacard($relRec, $count, $fieldCode, $encodedHighLigtTerm, $encodedSearchTerm){
$rs = $relRec['records'][0];

$rsHtml ='<div class="related-content bluebg" id="related-content">';
Expand Down Expand Up @@ -821,6 +822,9 @@ function buildExactMatchPlacard($relRec, $count){
if($count > 0){
$hideempplacard = 'style="display:none"';
}
else{
$hideempplacard = '';
}
$empHtml = '<div id="emp_placard" class="emp_placard yellowbg" '.$hideempplacard.'>';
$empHtml .= '<div class="emp_label">'.$relRec['Label'].'</div>';
foreach($relRec['records'] as $rec){
Expand Down
56 changes: 36 additions & 20 deletions rest/EBSCOAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function request($action, $params = null, $attempts = 3)
try {

$authenticationToken = $this->getAuthToken();
$sessionToken = $this ->getSessionToken($authenticationToken);
$sessionToken = $this ->getSessionToken($authenticationToken, 'n');


if(empty($authenticationToken)){
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function request($action, $params = null, $attempts = 3)
switch ($code) {
case EBSCOConnector::EDS_AUTH_TOKEN_INVALID:
$authenticationToken = $this->getAuthToken();
$sessionToken = $this ->getSessionToken($authenticationToken);
$sessionToken = $this ->getSessionToken($authenticationToken, 'n');
$headers = array(
'x-authenticationToken: ' . $authenticationToken,
'x-sessionToken: ' . $sessionToken
Expand Down Expand Up @@ -224,24 +224,42 @@ public function apiAuthenticationToken()
*/
public function getSessionToken($authenToken, $guest='n'){
$token = '';
$configFile="Config.xml";

$configFile="Config.xml";

if(isset($_SESSION['sessionToken']) && !empty($_SESSION['sessionToken']) && isset($_SESSION['sessionTimeoutValue']) && ((int)$_SESSION['sessionTimeoutValue'] > (int)time()) && isset($_SESSION['guest']) && ($guest == $_SESSION['guest'])){
// if a sessionToken exists
// AND the sessionTimeout value is greater than current time()
// AND guest status has not change
// return the token that is part of the current SESSION and write forward the sessionTimeoutValue

$_SESSION['sessionTimeoutValue'] = time()+($_SESSION['sessionTimeout']*0.9);
$token = $_SESSION['sessionToken'];
}
else{
// Check user's login status
if(isset($_SESSION['login']) or (validAuthIP($configFile)==true)){
if (($guest=='n') or (validAuthIP($configFile)==true)){
$sessionToken = $this->apiSessionToken($authenToken, 'n');
$_SESSION['sessionToken']=$sessionToken;
}
$token = $_SESSION['sessionToken'];
if(isset($_SESSION['login']) or (validAuthIP($configFile)==true)){
if (($guest=='n') or (validAuthIP($configFile)==true)){
$sessionToken = $this->apiSessionToken($authenToken, 'n');

//ensure your sessionToken, GuestStatus and SessionTimeoutValue is set
$_SESSION['sessionToken']=$sessionToken;
$_SESSION['guest'] = $guest;
$_SESSION['sessionTimeoutValue'] = time()+($_SESSION['sessionTimeout']*0.9);
}
$token = $_SESSION['sessionToken'];
}
else{
$sessionToken = $this->apiSessionToken($authenToken, 'y');
$_SESSION['sessionToken']=$sessionToken;
$token = $_SESSION['sessionToken'];
//ensure your sessionToken, GuestStatus and SessionTimeoutValue is set

$_SESSION['guest'] = $guest;
$_SESSION['sessionTimeoutValue'] = time()+($_SESSION['sessionTimeout']*0.9);
// TODO: check IP validation
}
}
else
{
$sessionToken = $this->apiSessionToken($authenToken, 'y');
$_SESSION['sessionToken']=$sessionToken;

$token = $_SESSION['sessionToken'];
// TODO: check IP validation
}

return $token;
}

Expand Down Expand Up @@ -293,7 +311,6 @@ public function apiEndSessionToken($authenToken, $sessionToken){
* @access public
*/
public function apiSearch($params) {

$results = $this->request('Search', $params);
return $results;
}
Expand Down Expand Up @@ -377,7 +394,6 @@ public function getInfo()
public function apiInfo(){

$response = $this->request('Info');

$Info = array(
'Info' => $response,
'timestamp'=>time()
Expand Down
1 change: 1 addition & 0 deletions rest/EBSCOConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public function requestInfo($params,$headers)
$url = self::$end_point . '/Info';

$response = $this->request($url, $params, $headers);
$_SESSION['sessionTimeout'] = (int)$response->ApplicationSettings->SessionTimeout;
return $response;
}

Expand Down
2 changes: 1 addition & 1 deletion rest/EBSCOResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function buildSearch()
}


if($this->response->SearchResult->RelatedContent){
if($this->response->SearchResult->RelatedContent->RelatedRecords){

$relatedRecsWithAction = $this->response->SearchResult->RelatedContent->RelatedRecords;
foreach($relatedRecsWithAction->RelatedRecord as $relRecs){
Expand Down
1 change: 0 additions & 1 deletion results.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

$results = $_SESSION['results'];
$queryStringUrl = $results['queryString'];

$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
$actions = array();
if(!empty($action)){
Expand Down

0 comments on commit b3e5f32

Please sign in to comment.