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));
31 $args .= '&nickname=' . $nick;
33 $args .= '&nickname=' . $first;
35 $args .= '&openid_url=' . notags(trim($_SESSION['openid']));
36 if($a->config['register_policy'] != REGISTER_CLOSED)
37 goaway($a->get_baseurl() . '/register' . $args);
39 goaway($a->get_baseurl());
45 $r = q("SELECT * FROM `user` WHERE `openid` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
46 dbesc($_SESSION['openid'])
49 notice( t('Login failed.') . EOL );
50 goaway($a->get_baseurl());
52 unset($_SESSION['openid']);
54 $_SESSION['uid'] = $r[0]['uid'];
55 $_SESSION['theme'] = $r[0]['theme'];
56 $_SESSION['authenticated'] = 1;
57 $_SESSION['page_flags'] = $r[0]['page-flags'];
58 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
60 notice( t("Welcome back ") . $r[0]['username'] . EOL);
62 if(strlen($a->user['timezone']))
63 date_default_timezone_set($a->user['timezone']);
65 $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
66 intval($_SESSION['uid']));
69 $a->cid = $r[0]['id'];
70 $_SESSION['cid'] = $a->cid;
73 header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
74 if(($a->module !== 'home') && isset($_SESSION['return_url']))
75 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
77 goaway($a->get_baseurl());
80 notice( t('Login failed.') . EOL);
81 goaway($a->get_baseurl());