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'))) {
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 `verified` = 1 LIMIT 1",
34 unset($_SESSION['openid']);
36 require_once('include/security.php');
37 authenticate_success($r[0],true,true);
39 // just in case there was no return url set
40 // and we fell through
47 if($a->config['register_policy'] == REGISTER_CLOSED) {
48 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
52 unset($_SESSION['register']);
54 $attr = $openid->getAttributes();
55 if(is_array($attr) && count($attr)) {
56 foreach($attr as $k => $v) {
57 if($k === 'namePerson/friendly')
58 $nick = notags(trim($v));
59 if($k === 'namePerson/first')
60 $first = notags(trim($v));
61 if($k === 'namePerson')
62 $args .= '&username=' . notags(trim($v));
63 if($k === 'contact/email')
64 $args .= '&email=' . notags(trim($v));
65 if($k === 'media/image/aspect11')
66 $photosq = bin2hex(trim($v));
67 if($k === 'media/image/default')
68 $photo = bin2hex(trim($v));
72 $args .= '&nickname=' . $nick;
74 $args .= '&nickname=' . $first;
77 $args .= '&photo=' . $photosq;
79 $args .= '&photo=' . $photo;
81 $args .= '&openid_url=' . notags(trim($authid));
83 goaway($a->get_baseurl() . '/register' . $args);
88 notice( t('Login failed.') . EOL);