6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
11 require_once('library/openid.php');
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;
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 dbesc($authid), dbesc(normalise_openid($authid))
48 if (DBM::is_result($r)) {
50 // successful OpenID login
52 unset($_SESSION['openid']);
54 require_once('include/security.php');
55 authenticate_success($r[0],true,true);
57 // just in case there was no return url set
58 // and we fell through
60 goaway(System::baseUrl());
63 // Successful OpenID login - but we can't match it to an existing account.
66 if ($a->config['register_policy'] == REGISTER_CLOSED) {
67 notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL);
68 goaway(System::baseUrl());
71 unset($_SESSION['register']);
73 $attr = $openid->getAttributes();
74 if (is_array($attr) && count($attr)) {
75 foreach ($attr as $k => $v) {
76 if ($k === 'namePerson/friendly') {
77 $nick = notags(trim($v));
79 if($k === 'namePerson/first') {
80 $first = notags(trim($v));
82 if($k === 'namePerson') {
83 $args .= '&username=' . urlencode(notags(trim($v)));
85 if ($k === 'contact/email') {
86 $args .= '&email=' . urlencode(notags(trim($v)));
88 if ($k === 'media/image/aspect11') {
89 $photosq = bin2hex(trim($v));
91 if ($k === 'media/image/default') {
92 $photo = bin2hex(trim($v));
97 $args .= '&nickname=' . urlencode($nick);
100 $args .= '&nickname=' . urlencode($first);
104 $args .= '&photo=' . urlencode($photosq);
107 $args .= '&photo=' . urlencode($photo);
110 $args .= '&openid_url=' . urlencode(notags(trim($authid)));
112 goaway(System::baseUrl() . '/register?' . $args);
117 notice(L10n::t('Login failed.') . EOL);
118 goaway(System::baseUrl());