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 // NOTE: we search both for normalised and non-normalised form of $authid
30 // because the normalization step was removed from setting
31 // mod/settings.php in 8367cad so it might have left mixed
32 // records in the user table
34 $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
35 FROM `user` WHERE ( openid = '%s' OR openid = '%s' ) AND blocked = 0
36 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
37 dbesc($authid), dbesc(normalise_openid($authid))
42 // successful OpenID login
44 unset($_SESSION['openid']);
46 require_once('include/security.php');
47 authenticate_success($r[0],true,true);
49 // just in case there was no return url set
50 // and we fell through
55 // Successful OpenID login - but we can't match it to an existing account.
58 if($a->config['register_policy'] == REGISTER_CLOSED) {
59 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
63 unset($_SESSION['register']);
65 $attr = $openid->getAttributes();
66 if(is_array($attr) && count($attr)) {
67 foreach($attr as $k => $v) {
68 if($k === 'namePerson/friendly')
69 $nick = notags(trim($v));
70 if($k === 'namePerson/first')
71 $first = notags(trim($v));
72 if($k === 'namePerson')
73 $args .= '&username=' . notags(trim($v));
74 if($k === 'contact/email')
75 $args .= '&email=' . notags(trim($v));
76 if($k === 'media/image/aspect11')
77 $photosq = bin2hex(trim($v));
78 if($k === 'media/image/default')
79 $photo = bin2hex(trim($v));
83 $args .= '&nickname=' . $nick;
85 $args .= '&nickname=' . $first;
88 $args .= '&photo=' . $photosq;
90 $args .= '&photo=' . $photo;
92 $args .= '&openid_url=' . notags(trim($authid));
94 goaway($a->get_baseurl() . '/register' . $args);
99 notice( t('Login failed.') . EOL);