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']);
23 if(! strlen($authid)) {
24 logger( t('OpenID protocol error. No ID returned.') . EOL);
28 $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
29 FROM `user` WHERE `openid` = '%s' AND `blocked` = 0
30 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
36 // successful OpenID login
38 unset($_SESSION['openid']);
40 require_once('include/security.php');
41 authenticate_success($r[0],true,true);
43 // just in case there was no return url set
44 // and we fell through
49 // Successful OpenID login - but we can't match it to an existing account.
52 if($a->config['register_policy'] == REGISTER_CLOSED) {
53 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
57 unset($_SESSION['register']);
59 $attr = $openid->getAttributes();
60 if(is_array($attr) && count($attr)) {
61 foreach($attr as $k => $v) {
62 if($k === 'namePerson/friendly')
63 $nick = notags(trim($v));
64 if($k === 'namePerson/first')
65 $first = notags(trim($v));
66 if($k === 'namePerson')
67 $args .= '&username=' . notags(trim($v));
68 if($k === 'contact/email')
69 $args .= '&email=' . notags(trim($v));
70 if($k === 'media/image/aspect11')
71 $photosq = bin2hex(trim($v));
72 if($k === 'media/image/default')
73 $photo = bin2hex(trim($v));
77 $args .= '&nickname=' . $nick;
79 $args .= '&nickname=' . $first;
82 $args .= '&photo=' . $photosq;
84 $args .= '&photo=' . $photo;
86 $args .= '&openid_url=' . notags(trim($authid));
88 goaway($a->get_baseurl() . '/register' . $args);
93 notice( t('Login failed.') . EOL);