Browse Source

added check to validate lastname matches what is stored in relais

9.x-1.0
Paul Pound 8 years ago
parent
commit
ffb1344ad4
  1. 17
      includes/form.inc
  2. 14
      includes/relais.inc

17
includes/form.inc

@ -37,6 +37,16 @@ function upei_roblib_ill_form($form, &$form_state) {
* An array containing the Drupal form state. * An array containing the Drupal form state.
*/ */
function upei_roblib_ill_form_validate($form, &$form_state) { function upei_roblib_ill_form_validate($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/relais');
if ($form_state['step'] == 'upei_roblib_ill_auth_form') {
$aid = upei_roblib_ill_authenticate($form_state['values']['campus_id'], $form_state['values']['Surname']);
if (is_array($aid) && isset($aid['Problem']['Message'])) {
form_set_error('Surname', $aid['Problem']['Message']);
}
else {
$form_state['storage']['aid'] = $aid;
}
}
if ($form_state['step'] == 'upei_roblib_ill_request_form' && empty($form_state['values']['doi']) && empty($form_state['values']['Title']) && if ($form_state['step'] == 'upei_roblib_ill_request_form' && empty($form_state['values']['doi']) && empty($form_state['values']['Title']) &&
empty($form_state['values']['ArticleTitle']) empty($form_state['values']['ArticleTitle'])
) { ) {
@ -54,7 +64,7 @@ function upei_roblib_ill_form_validate($form, &$form_state) {
* An array containing the Drupal form state. * An array containing the Drupal form state.
*/ */
function upei_roblib_ill_form_submit($form, &$form_state) { function upei_roblib_ill_form_submit($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/relais');
$form_state['storage'][$form_state['step']] = $form_state['values']; $form_state['storage'][$form_state['step']] = $form_state['values'];
switch ($form_state['step']) { switch ($form_state['step']) {
case 'upei_roblib_ill_request_form': case 'upei_roblib_ill_request_form':
@ -65,8 +75,7 @@ function upei_roblib_ill_form_submit($form, &$form_state) {
break; break;
case 'upei_roblib_ill_auth_form': case 'upei_roblib_ill_auth_form':
//process the form //process the form
$aid = upei_roblib_ill_authenticate($form_state['values']['campus_id']); $response = upei_roblib_ill_add_request($form_state, $form_state['storage']['aid']);
$response = upei_roblib_ill_add_request($form_state, $aid);
$form_state['redirect'] = array( $form_state['redirect'] = array(
'upei/roblib/ill/finished', 'upei/roblib/ill/finished',
array( array(
@ -93,8 +102,6 @@ call 902-566-0445</div>";
} }
/** /**
* The patron portion of the ILL form. * The patron portion of the ILL form.
* *

14
includes/relais.inc

@ -45,7 +45,7 @@ function upei_roblib_ill_add_request($form_state, $aid) {
if(!isset($aid) || is_array($aid)) { if(!isset($aid) || is_array($aid)) {
upei_roblib_ill_log_request($relais_arr, $aid); upei_roblib_ill_log_request($relais_arr, $aid);
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $aid['Problem']['Message'])), 'error'); drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $aid['Problem']['Message'])), 'error');
return array('ConfirmMessage' => $aid['Problem']['Message'] . ' You may have entered an incorrect Campus ID'); return array('ConfirmMessage' => t('There was an error processing your request, @msg', array('@msg' => $aid['Problem']['Message'])));
} }
$result = drupal_http_request($url . '?aid=' . $aid, $options); $result = drupal_http_request($url . '?aid=' . $aid, $options);
module_load_include('inc', 'upei_roblib_ill', 'includes/db'); module_load_include('inc', 'upei_roblib_ill', 'includes/db');
@ -65,7 +65,7 @@ function upei_roblib_ill_add_request($form_state, $aid) {
* @return string/array * @return string/array
* Returns a Relais authentication id (token) or an array containing the Relais response error which should include the error message if authentication fails * Returns a Relais authentication id (token) or an array containing the Relais response error which should include the error message if authentication fails
*/ */
function upei_roblib_ill_authenticate($barcode) { function upei_roblib_ill_authenticate($barcode, $surname) {
$url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication'); $url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication');
$json_arr = array(); $json_arr = array();
$json_arr['ApiKey'] = variable_get('upei_roblib_ill_relais_key'); $json_arr['ApiKey'] = variable_get('upei_roblib_ill_relais_key');
@ -80,14 +80,20 @@ function upei_roblib_ill_authenticate($barcode) {
'headers' => array('Content-Type' => 'application/json'), 'headers' => array('Content-Type' => 'application/json'),
); );
$result = drupal_http_request($url, $options); $result = drupal_http_request($url, $options);
if($result->code != '200') {
$response_data['Problem']['Message'] = $result->error;
return $response_data;
}
$response_data = json_decode($result->data, TRUE); $response_data = json_decode($result->data, TRUE);
if ($result->code == '200') { if ($result->code == '200') {
if (isset($response_data['Problem'])) { if (isset($response_data['Problem']) || $response_data['LastName'] !== $surname) {
$err_message = isset($response_data['Problem']['Message']) ? $response_data['Problem']['Message'] : '';
$err_message .= t( ' Your Campus ID could be incorrect or your Last Name does not match what is stored in the profile for the user with the specified Campus ID');
$response_data['Problem']['Message'] = $err_message;
return $response_data; return $response_data;
} }
$aid = $response_data['AuthorizationId']; $aid = $response_data['AuthorizationId'];
} }
return isset($aid) ? $aid : $response_data; return isset($aid) ? $aid : $response_data;
} }

Loading…
Cancel
Save