]> git.mxchange.org Git - friendica.git/blob - mod/openid.php
Don't show the local community page on single user instances
[friendica.git] / mod / openid.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Core\System;
6 use Friendica\Database\DBM;
7
8 require_once('library/openid.php');
9
10 function openid_content(App $a) {
11
12         $noid = Config::get('system','no_openid');
13         if($noid)
14                 goaway(System::baseUrl());
15
16         logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA);
17
18         if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
19
20                 $openid = new LightOpenID;
21
22                 if($openid->validate()) {
23
24                         $authid = $_REQUEST['openid_identity'];
25
26                         if(! strlen($authid)) {
27                                 logger( t('OpenID protocol error. No ID returned.') . EOL);
28                                 goaway(System::baseUrl());
29                         }
30
31                         // NOTE: we search both for normalised and non-normalised form of $authid
32                         //       because the normalization step was removed from setting
33                         //       mod/settings.php in 8367cad so it might have left mixed
34                         //       records in the user table
35                         //
36                         $r = q("SELECT *
37                                 FROM `user`
38                                 WHERE ( `openid` = '%s' OR `openid` = '%s' )
39                                 AND `blocked` = 0 AND `account_expired` = 0
40                                 AND `account_removed` = 0 AND `verified` = 1
41                                 LIMIT 1",
42                                 dbesc($authid), dbesc(normalise_openid($authid))
43                         );
44
45                         if (DBM::is_result($r)) {
46
47                                 // successful OpenID login
48
49                                 unset($_SESSION['openid']);
50
51                                 require_once('include/security.php');
52                                 authenticate_success($r[0],true,true);
53
54                                 // just in case there was no return url set
55                                 // and we fell through
56
57                                 goaway(System::baseUrl());
58                         }
59
60                         // Successful OpenID login - but we can't match it to an existing account.
61                         // New registration?
62
63                         if ($a->config['register_policy'] == REGISTER_CLOSED) {
64                                 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
65                                 goaway(System::baseUrl());
66                         }
67
68                         unset($_SESSION['register']);
69                         $args = '';
70                         $attr = $openid->getAttributes();
71                         if (is_array($attr) && count($attr)) {
72                                 foreach ($attr as $k => $v) {
73                                         if ($k === 'namePerson/friendly') {
74                                                 $nick = notags(trim($v));
75                                         }
76                                         if($k === 'namePerson/first') {
77                                                 $first = notags(trim($v));
78                                         }
79                                         if($k === 'namePerson') {
80                                                 $args .= '&username=' . urlencode(notags(trim($v)));
81                                         }
82                                         if ($k === 'contact/email') {
83                                                 $args .= '&email=' . urlencode(notags(trim($v)));
84                                         }
85                                         if ($k === 'media/image/aspect11') {
86                                                 $photosq = bin2hex(trim($v));
87                                         }
88                                         if ($k === 'media/image/default') {
89                                                 $photo = bin2hex(trim($v));
90                                         }
91                                 }
92                         }
93                         if ($nick) {
94                                 $args .= '&nickname=' . urlencode($nick);
95                         }
96                         elseif ($first) {
97                                 $args .= '&nickname=' . urlencode($first);
98                         }
99
100                         if ($photosq) {
101                                 $args .= '&photo=' . urlencode($photosq);
102                         }
103                         elseif ($photo) {
104                                 $args .= '&photo=' . urlencode($photo);
105                         }
106
107                         $args .= '&openid_url=' . urlencode(notags(trim($authid)));
108
109                         goaway(System::baseUrl() . '/register?' . $args);
110
111                         // NOTREACHED
112                 }
113         }
114         notice( t('Login failed.') . EOL);
115         goaway(System::baseUrl());
116         // NOTREACHED
117 }