X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/e380a7f6aaefb1bbd16a595b6f855ce036501981..8c762aa599e4022654cf707125d7ac2ed6f194b0:/www/login.php
diff --git a/www/login.php b/www/login.php
index e3d165d..5782521 100644
--- a/www/login.php
+++ b/www/login.php
@@ -1,42 +1,18 @@
- * @copyright 2009 Bill Shupp
- * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
- * @link http://github.com/shupp/openid
- */
namespace phorkie;
-// A tool for testing Relying Party functionality
-set_include_path(
- __DIR__ . '/../../src/'
- . PATH_SEPARATOR . get_include_path()
-);
-
-$pageRequiresLogin = false;
+$noSecurityCheck = true;
require_once 'www-header.php';
-require_once 'openid/config.php';
-
if (isset($_REQUEST['logout'])) {
unset($_SESSION);
session_destroy();
- $redirect = 'http://' . $_SERVER['HTTP_HOST'];
- header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
- exit;
+ header('Location: ' . Tools::fullUrl('/'));
+ exit();
}
if (!count($_GET) && !count($_POST)) {
- render(
- 'login',
- null
- );
- exit;
+ render('login');
+ exit();
}
// Hackaround Non-Javascript Login Page
@@ -52,14 +28,13 @@ if (isset($_POST['openid_url'])) {
$openid_url = null;
}
+$realm = Tools::fullUrl('/');
+$returnTo = Tools::fullUrl('/login');
+
try {
$o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url);
} catch (OpenID_Exception $e) {
- $contents = "
\n";
- $contents .= "
" . $e->getMessage() . "
\n";
- $contents .= "
";
- include_once 'openid/wrapper.php';
- exit;
+ throw new Exception($e->getMessage());
}
if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associations'])) {
@@ -67,20 +42,13 @@ if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associat
$_SESSION['disable_associations'] = true;
}
-$log = new \OpenID_Observer_Log;
-\OpenID::attach($log);
-
if (isset($_POST['openid_url'])) {
$_SESSION['openid_url'] = $openid_url;
try {
$authRequest = $o->prepare();
} catch (OpenID_Exception $e) {
- $contents = "\n";
- $contents .= "
" . $e->getMessage() . "
\n";
- $contents .= "
";
- include_once 'openid/wrapper.php';
- exit;
+ throw new Exception($e->getMessage());
}
// SREG
@@ -88,17 +56,18 @@ if (isset($_POST['openid_url'])) {
$sreg->set('required', 'email,fullname');
$authRequest->addExtension($sreg);
- // AX
+ // AX, http://stackoverflow.com/a/7657061/282601
$ax = new \OpenID_Extension_AX(\OpenID_Extension::REQUEST);
$ax->set('type.email', 'http://axschema.org/contact/email');
$ax->set('type.firstname', 'http://axschema.org/namePerson/first');
$ax->set('type.lastname', 'http://axschema.org/namePerson/last');
+ $ax->set('type.fullname', 'http://axschema.org/namePerson');
$ax->set('mode', 'fetch_request');
- $ax->set('required', 'email,firstname,lastname');
+ $ax->set('required', 'email,firstname,lastname,fullname');
$authRequest->addExtension($ax);
$url = $authRequest->getAuthorizeURL();
-
+
header("Location: $url");
exit;
@@ -137,7 +106,7 @@ try {
} catch (OpenID_Exception $e) {
$status = "Status: | EXCEPTION!";
$status .= " ({$e->getMessage()} : {$e->getCode()}) |
";
- }
+}
$openid = $message->getArrayFormat();
@@ -151,7 +120,10 @@ $email = isset($openid['openid.ext2.value.email']) && !isset($email)
$email = isset($openid['openid.sreg.email']) && !isset($email)
? $openid['openid.sreg.email']
: $email;
-$email = isset($openid['openid.ax.value.email']) && !isset($email)
+$email = isset($openid['openid.ax.value.email'])
+ && isset($openid['openid.ax.type.email'])
+ && $openid['openid.ax.type.email'] == 'http://axschema.org/contact/email'
+ && !isset($email)
? $openid['openid.ax.value.email']
: $email;
$_SESSION['email'] = isset($email)
@@ -166,11 +138,21 @@ $name = isset($openid['openid.ext1.value.firstname'])
$name = isset($openid['openid.sreg.fullname']) && !isset($name)
? $openid['openid.sreg.fullname']
: $name;
+$name = isset($openid['openid.ax.value.fullname'])
+ && isset($openid['openid.ax.type.fullname'])
+ && $openid['openid.ax.type.fullname'] == 'http://axschema.org/namePerson'
+ && !isset($name)
+ ? $openid['openid.ax.value.fullname']
+ : $name;
$_SESSION['name'] = isset($name) ? $name : $_SERVER['REMOTE_ADDR'];
$_SESSION['identity'] = $openid['openid.identity'];
-$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SESSION['REQUEST_URI'];
+if (isset($_SESSION['REQUEST_URI'])) {
+ $redirect = Tools::fullUrl($_SESSION['REQUEST_URI']);
+} else {
+ $redirect = Tools::fullUrl('/');
+}
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
exit;
?>