]> git.mxchange.org Git - friendica.git/blob - mod/openid.php
EN GB translation update THX AndyH3
[friendica.git] / mod / openid.php
1 <?php
2 /**
3  * @file mod/openid.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Session;
11 use Friendica\Database\DBA;
12 use Friendica\Util\Strings;
13
14 function openid_content(App $a) {
15
16         if (Config::get('system','no_openid')) {
17                 $a->internalRedirect();
18         }
19
20         Logger::log('mod_openid ' . print_r($_REQUEST,true), Logger::DATA);
21
22         if (!empty($_GET['openid_mode']) && !empty($_SESSION['openid'])) {
23
24                 $openid = new LightOpenID($a->getHostName());
25
26                 if ($openid->validate()) {
27                         $authid = $openid->data['openid_identity'];
28
29                         if (empty($authid)) {
30                                 Logger::log(L10n::t('OpenID protocol error. No ID returned.') . EOL);
31                                 $a->internalRedirect();
32                         }
33
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
38                         //
39                         $condition = ['blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true,
40                                 'openid' => [$authid, Strings::normaliseOpenID($authid)]];
41                         $user  = DBA::selectFirst('user', [], $condition);
42                         if (DBA::isResult($user)) {
43
44                                 // successful OpenID login
45
46                                 unset($_SESSION['openid']);
47
48                                 Session::setAuthenticatedForUser($a, $user, true, true);
49
50                                 // just in case there was no return url set
51                                 // and we fell through
52
53                                 $a->internalRedirect();
54                         }
55
56                         // Successful OpenID login - but we can't match it to an existing account.
57                         unset($_SESSION['register']);
58                         Session::set('openid_attributes', $openid->getAttributes());
59                         Session::set('openid_identity', $authid);
60
61                         // Detect the server URL
62                         $open_id_obj = new LightOpenID($a->getHostName());
63                         $open_id_obj->identity = $authid;
64                         Session::set('openid_server', $open_id_obj->discover($open_id_obj->identity));
65
66                         if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) {
67                                 notice(L10n::t('Account not found. Please login to your existing account to add the OpenID to it.'));
68                         } else {
69                                 notice(L10n::t('Account not found. Please register a new account or login to your existing account to add the OpenID to it.'));
70                         }
71
72                         $a->internalRedirect('login');
73                 }
74         }
75         notice(L10n::t('Login failed.') . EOL);
76         $a->internalRedirect();
77         // NOTREACHED
78 }