]> git.mxchange.org Git - friendica.git/blob - mod/openid.php
report failure to generate keys
[friendica.git] / mod / openid.php
1 <?php
2
3
4 require_once('library/openid.php');
5
6
7 function openid_content(&$a) {
8
9         if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
10                 $openid = new LightOpenID;
11
12                 if($openid->validate()) {
13
14                         if(x($_SESSION,'register')) {
15                                 unset($_SESSION['register']);
16                                 $args = '';
17                                 $attr = $openid->getAttributes();
18                                 if(is_array($attr) && count($attr)) {
19                                         foreach($attr as $k => $v) {
20                                                 if($k === 'namePerson/friendly')
21                                                         $nick = notags(trim($v));
22                                                 if($k === 'namePerson/first')
23                                                         $first = notags(trim($v));
24                                                 if($k === 'namePerson')
25                                                         $args .= '&username=' . notags(trim($v));
26                                                 if($k === 'contact/email')
27                                                         $args .= '&email=' . notags(trim($v));
28                                                 if($k === 'media/image/aspect11')
29                                                         $photosq = bin2hex(trim($v));
30                                                 if($k === 'media/image/default')
31                                                         $photo = bin2hex(trim($v));
32                                         }
33                                 }
34                                 if($nick)
35                                         $args .= '&nickname=' . $nick;
36                                 elseif($first)
37                                         $args .= '&nickname=' . $first;
38
39                                 if($photosq)
40                                         $args .= '&photo=' . $photosq;
41                                 elseif($photo)
42                                         $args .= '&photo=' . $photo;
43
44                                 $args .= '&openid_url=' . notags(trim($_SESSION['openid']));
45                                 if($a->config['register_policy'] != REGISTER_CLOSED)
46                                         goaway($a->get_baseurl() . '/register' . $args);
47                                 else
48                                         goaway($a->get_baseurl());
49
50                                 // NOTREACHED
51                         } 
52
53
54                         $r = q("SELECT * FROM `user` WHERE `openid` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
55                                 dbesc($_SESSION['openid'])
56                         );
57                         if(! count($r)) {
58                                 notice( t('Login failed.') . EOL );
59                                 goaway($a->get_baseurl());
60                         }
61                         unset($_SESSION['openid']);
62
63                         $_SESSION['uid'] = $r[0]['uid'];
64                         $_SESSION['theme'] = $r[0]['theme'];
65                         $_SESSION['authenticated'] = 1;
66                         $_SESSION['page_flags'] = $r[0]['page-flags'];
67                         $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
68
69                         notice( t("Welcome back ") . $r[0]['username'] . EOL);
70                         $a->user = $r[0];
71                         if(strlen($a->user['timezone']))
72                                 date_default_timezone_set($a->user['timezone']);
73
74                         $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
75                                 intval($_SESSION['uid']));
76                         if(count($r)) {
77                                 $a->contact = $r[0];
78                                 $a->cid = $r[0]['id'];
79                                 $_SESSION['cid'] = $a->cid;
80                         }
81
82                         header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
83                         if(($a->module !== 'home') && isset($_SESSION['return_url']))
84                                 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
85                         else
86                                 goaway($a->get_baseurl());
87                 }
88         }
89         notice( t('Login failed.') . EOL);
90         goaway($a->get_baseurl());
91         // NOTREACHED
92 }