]> git.mxchange.org Git - friendica.git/blob - mod/openid.php
make 'PHP "register_argc_argv"' easier to translate, may require fix for po2php
[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 = normalise_openid($_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                         $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` 
29                                 FROM `user` WHERE `openid` = '%s' AND `blocked` = 0 
30                                 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
31                                 dbesc($authid)
32                         );
33
34                         if($r && count($r)) {
35
36                                 // successful OpenID login
37
38                                 unset($_SESSION['openid']);
39
40                                 require_once('include/security.php');
41                                 authenticate_success($r[0],true,true);
42
43                                 // just in case there was no return url set 
44                                 // and we fell through
45
46                                 goaway(z_root());
47                         }
48
49                         // Successful OpenID login - but we can't match it to an existing account.
50                         // New registration?
51
52                         if($a->config['register_policy'] == REGISTER_CLOSED) {
53                                 notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL);
54                                 goaway(z_root());
55                         }
56
57                         unset($_SESSION['register']);
58                         $args = '';
59                         $attr = $openid->getAttributes();
60                         if(is_array($attr) && count($attr)) {
61                                 foreach($attr as $k => $v) {
62                                         if($k === 'namePerson/friendly')
63                                                 $nick = notags(trim($v));
64                                         if($k === 'namePerson/first')
65                                                 $first = notags(trim($v));
66                                         if($k === 'namePerson')
67                                                 $args .= '&username=' . notags(trim($v));
68                                         if($k === 'contact/email')
69                                                 $args .= '&email=' . notags(trim($v));
70                                         if($k === 'media/image/aspect11')
71                                                 $photosq = bin2hex(trim($v));
72                                         if($k === 'media/image/default')
73                                                 $photo = bin2hex(trim($v));
74                                 }
75                         }
76                         if($nick)
77                                 $args .= '&nickname=' . $nick;
78                         elseif($first)
79                                 $args .= '&nickname=' . $first;
80
81                         if($photosq)
82                                 $args .= '&photo=' . $photosq;
83                         elseif($photo)
84                                 $args .= '&photo=' . $photo;
85
86                         $args .= '&openid_url=' . notags(trim($authid));
87
88                         goaway($a->get_baseurl() . '/register' . $args);
89
90                         // NOTREACHED
91                 }
92         }
93         notice( t('Login failed.') . EOL);
94         goaway(z_root());
95         // NOTREACHED
96 }