4 require_once('library/openid.php');
7 function openid_content(&$a) {
9 if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) {
10 $openid = new LightOpenID;
12 if($openid->validate()) {
14 if(x($_SESSION,'register')) {
15 unset($_SESSION['register']);
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));
35 $args .= '&nickname=' . $nick;
37 $args .= '&nickname=' . $first;
40 $args .= '&photo=' . $photosq;
42 $args .= '&photo=' . $photo;
44 $args .= '&openid_url=' . notags(trim($_SESSION['openid']));
45 if($a->config['register_policy'] != REGISTER_CLOSED)
46 goaway($a->get_baseurl() . '/register' . $args);
48 goaway($a->get_baseurl());
54 $r = q("SELECT * FROM `user` WHERE `openid` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
55 dbesc($_SESSION['openid'])
58 notice( t('Login failed.') . EOL );
59 goaway($a->get_baseurl());
61 unset($_SESSION['openid']);
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'];
69 notice( t("Welcome back ") . $r[0]['username'] . EOL);
71 if(strlen($a->user['timezone']))
72 date_default_timezone_set($a->user['timezone']);
74 $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
75 intval($_SESSION['uid']));
78 $a->cid = $r[0]['id'];
79 $_SESSION['cid'] = $a->cid;
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']);
86 goaway($a->get_baseurl());
89 notice( t('Login failed.') . EOL);
90 goaway($a->get_baseurl());