3 require_once('library/openid.php');
5 if(! function_exists('openid_content')) {
6 function openid_content(&$a) {
8 $noid = get_config('system','no_openid');
12 logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
14 if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
16 $openid = new LightOpenID;
18 if($openid->validate()) {
20 $authid = normalise_openid($_REQUEST['openid_identity']);
22 if(! strlen($authid)) {
23 logger( t('OpenID protocol error. No ID returned.') . EOL);
27 $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
28 FROM `user` WHERE `openid` = '%s' AND `blocked` = 0
29 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
35 // successful OpenID login
37 unset($_SESSION['openid']);
39 require_once('include/security.php');
40 authenticate_success($r[0],true,true);
42 // just in case there was no return url set
43 // and we fell through
48 // Successful OpenID login - but we can't match it to an existing account.
51 if($a->config['register_policy'] == REGISTER_CLOSED) {
52 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
56 unset($_SESSION['register']);
58 $attr = $openid->getAttributes();
59 if(is_array($attr) && count($attr)) {
60 foreach($attr as $k => $v) {
61 if($k === 'namePerson/friendly')
62 $nick = notags(trim($v));
63 if($k === 'namePerson/first')
64 $first = notags(trim($v));
65 if($k === 'namePerson')
66 $args .= '&username=' . notags(trim($v));
67 if($k === 'contact/email')
68 $args .= '&email=' . notags(trim($v));
69 if($k === 'media/image/aspect11')
70 $photosq = bin2hex(trim($v));
71 if($k === 'media/image/default')
72 $photo = bin2hex(trim($v));
76 $args .= '&nickname=' . $nick;
78 $args .= '&nickname=' . $first;
81 $args .= '&photo=' . $photosq;
83 $args .= '&photo=' . $photo;
85 $args .= '&openid_url=' . notags(trim($authid));
87 goaway($a->get_baseurl() . '/register' . $args);
92 notice( t('Login failed.') . EOL);