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