3 $noSecurityCheck = true;
4 require_once 'www-header.php';
6 if (isset($_REQUEST['logout'])) {
9 header('Location: ' . Tools::fullUrl('/'));
13 if (!count($_GET) && !count($_POST)) {
18 // Hackaround Non-Javascript Login Page
19 if (!count($_POST) && isset($_GET['openid_url'])) {
23 if (isset($_POST['openid_url'])) {
24 $openid_url = $_POST['openid_url'];
25 } else if (isset($_SESSION['openid_url'])) {
26 $openid_url = $_SESSION['openid_url'];
31 $realm = Tools::fullUrl('/');
32 $returnTo = Tools::fullUrl('/login');
35 $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url);
36 } catch (OpenID_Exception $e) {
37 throw new Exception($e->getMessage());
40 if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associations'])) {
41 $o->disableAssociations();
42 $_SESSION['disable_associations'] = true;
45 $log = new \OpenID_Observer_Log;
46 \OpenID::attach($log);
48 if (isset($_POST['openid_url'])) {
50 $_SESSION['openid_url'] = $openid_url;
52 $authRequest = $o->prepare();
53 } catch (OpenID_Exception $e) {
54 throw new Exception($e->getMessage());
58 $sreg = new \OpenID_Extension_SREG11(\OpenID_Extension::REQUEST);
59 $sreg->set('required', 'email,fullname');
60 $authRequest->addExtension($sreg);
63 $ax = new \OpenID_Extension_AX(\OpenID_Extension::REQUEST);
64 $ax->set('type.email', 'http://axschema.org/contact/email');
65 $ax->set('type.firstname', 'http://axschema.org/namePerson/first');
66 $ax->set('type.lastname', 'http://axschema.org/namePerson/last');
67 $ax->set('mode', 'fetch_request');
68 $ax->set('required', 'email,firstname,lastname');
69 $authRequest->addExtension($ax);
71 $url = $authRequest->getAuthorizeURL();
73 header("Location: $url");
78 if (isset($_SESSION['openid_url'])) {
79 $usid = $_SESSION['openid_url'];
80 unset($_SESSION['openid_url']);
85 unset($_SESSION['disable_associations']);
88 list(, $queryString) = explode('?', $_SERVER['REQUEST_URI']);
90 // I hate php sometimes
91 $queryString = file_get_contents('php://input');
94 $message = new \OpenID_Message($queryString, \OpenID_Message::FORMAT_HTTP);
95 $id = $message->get('openid.claimed_id');
96 $mode = $message->get('openid.mode');
99 $result = $o->verify(new \Net_URL2($returnTo . '?' . $queryString), $message);
101 if ($result->success()) {
102 $status = "<tr><td>Status:</td><td><font color='green'>SUCCESS!";
103 $status .= " ({$result->getAssertionMethod()})</font></td></tr>";
105 $status = "<tr><td>Status:</td><td><font color='red'>FAIL!";
106 $status .= " ({$result->getAssertionMethod()})</font></td></tr>";
108 } catch (OpenID_Exception $e) {
109 $status = "<tr><td>Status:</td><td><font color='red'>EXCEPTION!";
110 $status .= " ({$e->getMessage()} : {$e->getCode()})</font></td></tr>";
114 $openid = $message->getArrayFormat();
116 $email = isset($openid['openid.ext1.value.email'])
117 ? $openid['openid.ext1.value.email']
119 $email = isset($openid['openid.ext2.value.email']) && !isset($email)
120 ? $openid['openid.ext2.value.email']
122 $email = isset($openid['openid.sreg.email']) && !isset($email)
123 ? $openid['openid.sreg.email']
125 $email = isset($openid['openid.ax.value.email'])
126 && isset($openid['openid.ax.type.email'])
127 && $openid['openid.ax.type.email'] == 'http://axschema.org/contact/email'
129 ? $openid['openid.ax.value.email']
131 $_SESSION['email'] = isset($email)
133 : $GLOBALS['phorkie']['auth']['anonymousEmail'];
135 $name = isset($openid['openid.ext1.value.firstname'])
136 && isset($openid['openid.ext1.value.lastname'])
137 ? $openid['openid.ext1.value.firstname'] . ' '
138 . $openid['openid.ext1.value.lastname']
140 $name = isset($openid['openid.sreg.fullname']) && !isset($name)
141 ? $openid['openid.sreg.fullname']
144 $_SESSION['name'] = isset($name) ? $name : $_SERVER['REMOTE_ADDR'];
145 $_SESSION['identity'] = $openid['openid.identity'];
147 if (isset($_SESSION['REQUEST_URI'])) {
148 $redirect = Tools::fullUrl($_SESSION['REQUEST_URI']);
150 $redirect = Tools::fullUrl('/');
152 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));