4 require_once('library/openid.php');
7 function openid_content(&$a) {
9 $noid = get_config('system','no_openid');
13 logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
15 if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
17 $openid = new LightOpenID;
19 if($openid->validate()) {
21 #$authid = normalise_openid($_REQUEST['openid_identity']);
22 $authid = $_REQUEST['openid_identity'];
24 if(! strlen($authid)) {
25 logger( t('OpenID protocol error. No ID returned.') . EOL);
29 $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
30 FROM `user` WHERE `openid` = '%s' AND `blocked` = 0
31 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
37 // successful OpenID login
39 unset($_SESSION['openid']);
41 require_once('include/security.php');
42 authenticate_success($r[0],true,true);
44 // just in case there was no return url set
45 // and we fell through
50 // Successful OpenID login - but we can't match it to an existing account.
53 if($a->config['register_policy'] == REGISTER_CLOSED) {
54 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
58 unset($_SESSION['register']);
60 $attr = $openid->getAttributes();
61 if(is_array($attr) && count($attr)) {
62 foreach($attr as $k => $v) {
63 if($k === 'namePerson/friendly')
64 $nick = notags(trim($v));
65 if($k === 'namePerson/first')
66 $first = notags(trim($v));
67 if($k === 'namePerson')
68 $args .= '&username=' . notags(trim($v));
69 if($k === 'contact/email')
70 $args .= '&email=' . notags(trim($v));
71 if($k === 'media/image/aspect11')
72 $photosq = bin2hex(trim($v));
73 if($k === 'media/image/default')
74 $photo = bin2hex(trim($v));
78 $args .= '&nickname=' . $nick;
80 $args .= '&nickname=' . $first;
83 $args .= '&photo=' . $photosq;
85 $args .= '&photo=' . $photo;
87 $args .= '&openid_url=' . notags(trim($authid));
89 goaway($a->get_baseurl() . '/register' . $args);
94 notice( t('Login failed.') . EOL);