4 require_once('library/openid.php');
6 function openid_content(App $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 = $_REQUEST['openid_identity'];
22 if(! strlen($authid)) {
23 logger( t('OpenID protocol error. No ID returned.') . EOL);
27 // NOTE: we search both for normalised and non-normalised form of $authid
28 // because the normalization step was removed from setting
29 // mod/settings.php in 8367cad so it might have left mixed
30 // records in the user table
32 $r = q("SELECT *, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` FROM `user`
33 WHERE ( `openid` = '%s' OR `openid` = '%s' )
34 AND `blocked` = 0 AND `account_expired` = 0
35 AND `account_removed` = 0 AND `verified` = 1
37 dbesc($authid), dbesc(normalise_openid($authid))
40 if (dbm::is_result($r)) {
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));
71 if($k === 'namePerson/first') {
72 $first = notags(trim($v));
74 if($k === 'namePerson') {
75 $args .= '&username=' . urlencode(notags(trim($v)));
77 if ($k === 'contact/email') {
78 $args .= '&email=' . urlencode(notags(trim($v)));
80 if ($k === 'media/image/aspect11') {
81 $photosq = bin2hex(trim($v));
83 if ($k === 'media/image/default') {
84 $photo = bin2hex(trim($v));
89 $args .= '&nickname=' . urlencode($nick);
92 $args .= '&nickname=' . urlencode($first);
96 $args .= '&photo=' . urlencode($photosq);
99 $args .= '&photo=' . urlencode($photo);
102 $args .= '&openid_url=' . urlencode(notags(trim($authid)));
104 goaway(App::get_baseurl() . '/register?' . $args);
109 notice( t('Login failed.') . EOL);