| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Openid login services module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Login a user
|
| 12 |
*
|
| 13 |
* @param $openid
|
| 14 |
* String. The openid.
|
| 15 |
*/
|
| 16 |
function openid_service_login($openids) {
|
| 17 |
global $user;
|
| 18 |
|
| 19 |
if ($user->uid) {
|
| 20 |
// user is already logged in
|
| 21 |
return services_error(t('Already logged in as !user.', array('!user' => $user->name)));
|
| 22 |
}
|
| 23 |
|
| 24 |
if (! is_array($openids)) {
|
| 25 |
$openids = array($openids);
|
| 26 |
}
|
| 27 |
|
| 28 |
foreach ($openids as $openid) {
|
| 29 |
// add 'http://' if openid supplied did not include it
|
| 30 |
if (stristr($openid, '://') === FALSE) {
|
| 31 |
$openid = 'http://'. $openid; //todo: SSL check
|
| 32 |
}
|
| 33 |
if (substr_count($openid, '/') < 3) {
|
| 34 |
$openid .= '/';
|
| 35 |
}
|
| 36 |
|
| 37 |
// Find the matching uid for the openid supplied
|
| 38 |
$sql = "SELECT uid FROM {authmap} WHERE authname LIKE '%s' OR authname LIKE '%s/'";
|
| 39 |
$uid = db_result(db_query($sql, $openid));
|
| 40 |
$account = user_load(array('uid' => $uid, 'status' => 1));
|
| 41 |
if ($account->uid > 0) {
|
| 42 |
$user = $account;
|
| 43 |
$form_values['name'] = $user->name;
|
| 44 |
user_authenticate_finalize($form_values);
|
| 45 |
} else {
|
| 46 |
continue;
|
| 47 |
}
|
| 48 |
|
| 49 |
if ($user->uid > 0) {
|
| 50 |
return session_id();
|
| 51 |
}
|
| 52 |
session_destroy();
|
| 53 |
}
|
| 54 |
return services_error(t('No user with that OpenID.'));
|
| 55 |
}
|