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