X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/eaf0573ebdcca11a984f4f98577ca77a6c63654e..9fcf10c0d05122e610a8944fc3dd77e0605ebb7f:/www/login.php diff --git a/www/login.php b/www/login.php index bba7c99..e141b65 100644 --- a/www/login.php +++ b/www/login.php @@ -6,12 +6,18 @@ require_once 'www-header.php'; if (isset($_REQUEST['logout'])) { unset($_SESSION); session_destroy(); - header('Location: ' . Tools::fullUrl('/')); + header('Location: ' . Tools::fullUrl()); exit(); } if (!count($_GET) && !count($_POST)) { - render('login'); + render( + 'login', + array( + 'openid' => isset($_COOKIE['lastopenid']) + ? $_COOKIE['lastopenid'] : 'http://' + ) + ); exit(); } @@ -28,8 +34,8 @@ if (isset($_POST['openid_url'])) { $openid_url = null; } -$realm = Tools::fullUrl('/'); -$returnTo = Tools::fullUrl('/login'); +$realm = Tools::fullUrl(); +$returnTo = Tools::fullUrl('login'); try { $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url); @@ -42,9 +48,6 @@ 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; @@ -59,13 +62,14 @@ 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(); @@ -102,10 +106,12 @@ try { $status = "Status:SUCCESS!"; $status .= " ({$result->getAssertionMethod()})"; } else { + throw new Exception('Error logging in'); $status = "Status:FAIL!"; $status .= " ({$result->getAssertionMethod()})"; } } catch (OpenID_Exception $e) { + throw new Exception('Error logging in'); $status = "Status:EXCEPTION!"; $status .= " ({$e->getMessage()} : {$e->getCode()})"; } @@ -140,15 +146,23 @@ $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']; +setcookie('lastopenid', $_SESSION['identity'], time() + 84600 * 60, '/login'); + +$url = ''; if (isset($_SESSION['REQUEST_URI'])) { - $redirect = Tools::fullUrl($_SESSION['REQUEST_URI']); -} else { - $redirect = Tools::fullUrl('/'); + $url = substr($_SESSION['REQUEST_URI'], 1); } +$redirect = Tools::fullUrl($url); header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); exit; ?>