7 use Friendica\Core\Authentication;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
13 function openid_content(App $a) {
15 $noid = Config::get('system','no_openid');
17 goaway(System::baseUrl());
19 logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
21 if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
23 $openid = new LightOpenID($a->getHostName());
25 if($openid->validate()) {
27 $authid = $_REQUEST['openid_identity'];
29 if(! strlen($authid)) {
30 logger(L10n::t('OpenID protocol error. No ID returned.') . EOL);
31 goaway(System::baseUrl());
34 // NOTE: we search both for normalised and non-normalised form of $authid
35 // because the normalization step was removed from setting
36 // mod/settings.php in 8367cad so it might have left mixed
37 // records in the user table
41 WHERE ( `openid` = '%s' OR `openid` = '%s' )
42 AND `blocked` = 0 AND `account_expired` = 0
43 AND `account_removed` = 0 AND `verified` = 1
45 DBA::escape($authid), DBA::escape(normalise_openid($authid))
48 if (DBA::isResult($r)) {
50 // successful OpenID login
52 unset($_SESSION['openid']);
54 Authentication::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 (intval(Config::get('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());