7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
12 function openid_content(App $a) {
14 $noid = Config::get('system','no_openid');
16 goaway(System::baseUrl());
18 logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
20 if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
22 $openid = new LightOpenID($a->get_hostname());
24 if($openid->validate()) {
26 $authid = $_REQUEST['openid_identity'];
28 if(! strlen($authid)) {
29 logger(L10n::t('OpenID protocol error. No ID returned.') . EOL);
30 goaway(System::baseUrl());
33 // NOTE: we search both for normalised and non-normalised form of $authid
34 // because the normalization step was removed from setting
35 // mod/settings.php in 8367cad so it might have left mixed
36 // records in the user table
40 WHERE ( `openid` = '%s' OR `openid` = '%s' )
41 AND `blocked` = 0 AND `account_expired` = 0
42 AND `account_removed` = 0 AND `verified` = 1
44 dbesc($authid), dbesc(normalise_openid($authid))
47 if (DBM::is_result($r)) {
49 // successful OpenID login
51 unset($_SESSION['openid']);
53 require_once('include/security.php');
54 authenticate_success($r[0],true,true);
56 // just in case there was no return url set
57 // and we fell through
59 goaway(System::baseUrl());
62 // Successful OpenID login - but we can't match it to an existing account.
65 if ($a->config['register_policy'] == REGISTER_CLOSED) {
66 notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL);
67 goaway(System::baseUrl());
70 unset($_SESSION['register']);
72 $attr = $openid->getAttributes();
73 if (is_array($attr) && count($attr)) {
74 foreach ($attr as $k => $v) {
75 if ($k === 'namePerson/friendly') {
76 $nick = notags(trim($v));
78 if($k === 'namePerson/first') {
79 $first = notags(trim($v));
81 if($k === 'namePerson') {
82 $args .= '&username=' . urlencode(notags(trim($v)));
84 if ($k === 'contact/email') {
85 $args .= '&email=' . urlencode(notags(trim($v)));
87 if ($k === 'media/image/aspect11') {
88 $photosq = bin2hex(trim($v));
90 if ($k === 'media/image/default') {
91 $photo = bin2hex(trim($v));
96 $args .= '&nickname=' . urlencode($nick);
99 $args .= '&nickname=' . urlencode($first);
103 $args .= '&photo=' . urlencode($photosq);
106 $args .= '&photo=' . urlencode($photo);
109 $args .= '&openid_url=' . urlencode(notags(trim($authid)));
111 goaway(System::baseUrl() . '/register?' . $args);
116 notice(L10n::t('Login failed.') . EOL);
117 goaway(System::baseUrl());