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