X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/20ca4e9e509a111f8de0069feeac54e3b31098ee..19f1b5d2a1730f8e37c8fc5585d30b99e70a8575:/www/login.php diff --git a/www/login.php b/www/login.php index e141b65..2762b4b 100644 --- a/www/login.php +++ b/www/login.php @@ -6,10 +6,27 @@ require_once 'www-header.php'; if (isset($_REQUEST['logout'])) { unset($_SESSION); session_destroy(); + //delete last openid cookie. + // if you deliberately log out, you do not want to be logged in + // automatically on the next page reload. + setcookie('lastopenid', '0', time() - 3600); + header('Location: ' . Tools::fullUrl()); exit(); } +$bAutologin = false; +if (isset($_GET['autologin']) && $_GET['autologin'] + && isset($_COOKIE['lastopenid']) +) { + $bAutologin = true; + // autologin=1: start openid autologin + // autologin=2: response from openid server + if ($_GET['autologin'] == 1) { + $_POST['openid_url'] = $_COOKIE['lastopenid']; + } +} + if (!count($_GET) && !count($_POST)) { render( 'login', @@ -36,10 +53,13 @@ if (isset($_POST['openid_url'])) { $realm = Tools::fullUrl(); $returnTo = Tools::fullUrl('login'); +if ($bAutologin) { + $returnTo = Tools::fullUrl('login?autologin=2'); +} try { $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url); -} catch (OpenID_Exception $e) { +} catch (\OpenID_Exception $e) { throw new Exception($e->getMessage()); } @@ -53,8 +73,23 @@ if (isset($_POST['openid_url'])) { $_SESSION['openid_url'] = $openid_url; try { $authRequest = $o->prepare(); - } catch (OpenID_Exception $e) { + if ($bAutologin) { + $authRequest->setMode(\OpenID::MODE_CHECKID_IMMEDIATE); + } + } catch (\OpenID_Exception $e) { + if ($bAutologin) { + $alres = new Login_AutologinResponse('error', $e->getMessage()); + $alres->send(); + exit(0); + } throw new Exception($e->getMessage()); + } catch (\Exception $e) { + if ($bAutologin) { + $alres = new Login_AutologinResponse('error', $e->getMessage()); + $alres->send(); + exit(0); + } + throw $e; } // SREG @@ -100,17 +135,33 @@ $id = $message->get('openid.claimed_id'); $mode = $message->get('openid.mode'); try { - $result = $o->verify(new \Net_URL2($returnTo . '?' . $queryString), $message); + $sep = '?'; + if (strpos($returnTo, '?') !== false) { + $sep = '&'; + } + $result = $o->verify(new \Net_URL2($returnTo . $sep . $queryString), $message); if ($result->success()) { $status = "Status:SUCCESS!"; $status .= " ({$result->getAssertionMethod()})"; } else { + if ($bAutologin) { + $alres = new Login_AutologinResponse( + 'error', 'Error logging in: ' . $result->getAssertionMethod() + ); + $alres->send(); + exit(0); + } throw new Exception('Error logging in'); $status = "Status:FAIL!"; $status .= " ({$result->getAssertionMethod()})"; } -} catch (OpenID_Exception $e) { +} catch (\OpenID_Exception $e) { + if ($bAutologin) { + $alres = new Login_AutologinResponse('error', $e->getMessage()); + $alres->send(); + exit(0); + } throw new Exception('Error logging in'); $status = "Status:EXCEPTION!"; $status .= " ({$e->getMessage()} : {$e->getCode()})"; @@ -156,7 +207,17 @@ $name = isset($openid['openid.ax.value.fullname']) $_SESSION['name'] = isset($name) ? $name : $_SERVER['REMOTE_ADDR']; $_SESSION['identity'] = $openid['openid.identity']; -setcookie('lastopenid', $_SESSION['identity'], time() + 84600 * 60, '/login'); +setcookie('tried-autologin', '0', time() - 3600);//delete +setcookie('lastopenid', $_SESSION['identity'], time() + 84600 * 60); + +if ($bAutologin) { + $alres = new Login_AutologinResponse('ok'); + $alres->name = $_SESSION['name']; + $alres->identity = $_SESSION['identity']; + $alres->send(); + exit(0); +} + $url = ''; if (isset($_SESSION['REQUEST_URI'])) {