4 require_once('library/openid.php');
7 function openid_content(App $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 = $_REQUEST['openid_identity'];
23 if(! strlen($authid)) {
24 logger( t('OpenID protocol error. No ID returned.') . EOL);
28 // NOTE: we search both for normalised and non-normalised form of $authid
29 // because the normalization step was removed from setting
30 // mod/settings.php in 8367cad so it might have left mixed
31 // records in the user table
33 $r = q("SELECT * FROM `user`
34 WHERE ( `openid` = '%s' OR `openid` = '%s' )
35 AND `blocked` = 0 AND `account_expired` = 0
36 AND `account_removed` = 0 AND `verified` = 1
38 dbesc($authid), dbesc(normalise_openid($authid))
41 if (dbm::is_result($r)) {
43 // successful OpenID login
45 unset($_SESSION['openid']);
47 require_once('include/security.php');
48 authenticate_success($r[0],true,true);
50 // just in case there was no return url set
51 // and we fell through
56 // Successful OpenID login - but we can't match it to an existing account.
59 if ($a->config['register_policy'] == REGISTER_CLOSED) {
60 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
64 unset($_SESSION['register']);
66 $attr = $openid->getAttributes();
67 if (is_array($attr) && count($attr)) {
68 foreach ($attr as $k => $v) {
69 if ($k === 'namePerson/friendly') {
70 $nick = notags(trim($v));
72 if($k === 'namePerson/first') {
73 $first = notags(trim($v));
75 if($k === 'namePerson') {
76 $args .= '&username=' . notags(trim($v));
78 if ($k === 'contact/email') {
79 $args .= '&email=' . notags(trim($v));
81 if ($k === 'media/image/aspect11') {
82 $photosq = bin2hex(trim($v));
84 if ($k === 'media/image/default') {
85 $photo = bin2hex(trim($v));
90 $args .= '&nickname=' . $nick;
93 $args .= '&nickname=' . $first;
97 $args .= '&photo=' . $photosq;
100 $args .= '&photo=' . $photo;
103 $args .= '&openid_url=' . notags(trim($authid));
105 goaway(App::get_baseurl() . '/register' . $args);
110 notice( t('Login failed.') . EOL);