Skip to content

Commit

Permalink
Fixed login issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Apr 29, 2011
1 parent ea26c8c commit 6a9dc69
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 2 additions & 6 deletions alma.module
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function alma_client() {
}
catch (Exception $e) {
watchdog('alma', 'Constructor error: “@message”', array('@message' => $e->getMessage(), WATCHDOG_ERROR));
$client = NULL;
throw $e;
}

}
Expand All @@ -93,20 +93,16 @@ function alma_client() {
* NULL on error, or the result of the method call.
*/
function alma_client_invoke($method) {

$args = func_get_args();
array_shift($args); // Lose the method.
$client = alma_client();
if (!$client) {
return NULL;
}

try {
$result = call_user_func_array(array($client, $method), $args);
}
catch (Exception $e) {
watchdog('alma', '@method error: “@message”', array('@method' => $method, '@message' => $e->getMessage()), WATCHDOG_ERROR);
return NULL;
throw $e;
}

return $result;
Expand Down
26 changes: 19 additions & 7 deletions alma.user.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
*
* Implements hook_user_authenticate().
*
* @param <type> $name
* @param <type> $pass
Expand All @@ -15,31 +15,43 @@ function alma_user_authenticate($uid, $pass) {
$res = alma_client_invoke('get_patron_info', $uid, $pass, TRUE);
$return['success'] = TRUE;
}
catch (Exception $e) {
catch (Exception $e) {
return $return;
}

// Check block status
// @TODO Check block status.

// Set creds
// Set creds.
$return['creds'] = array (
'name' => $uid,
'pass' => $pass,
);

// Set user information
// Set user information.
$return['user'] = array(
'data' => array(
'display_name' => $res['user_name'],
),
);

// Set e-mail address.
if (isset($res['mails'][0]) && valid_email_address($res['mails'][0]['mail'])) {
$return['user']['mail'] = $res['mails'][0]['mail'];
}

// Set preferred branch.
if (isset($res['preferences']['patron_branch'])) {
$return['user']['data']['preferred_branch'] = $res['preferences']['patron_branch'];
}

if (isset($res['mails'][0]) && valid_email_address($res['mails'][0]['mail'])) {
$return['user']['mail'] = $res['mails'][0]['mail'];
// Set patron address.
if (isset($res['addresses'][0])) {
$return['user']['data']['address'] = array(
'street' => $res['addresses'][0]['street'],
'postal_code' => $res['addresses'][0]['postal_code'],
'city' => $res['addresses'][0]['city'],
'country' => $res['addresses'][0]['country'],
);
}

return $return;
Expand Down

0 comments on commit 6a9dc69

Please sign in to comment.