summaryrefslogtreecommitdiffstats
path: root/examples/server/lib/actions.php
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-02-08 23:37:46 +0000
committerJosh Hoyt <josh@janrain.com>2006-02-08 23:37:46 +0000
commit1709607f2f560a2218f57bb565b5d43899ab238d (patch)
treef69e5ad12b37fef13f76e5351bff8fde37bf0af6 /examples/server/lib/actions.php
parent72891e2151d48641dba3c7e54b92f770c940439a (diff)
downloadphp-openid-1709607f2f560a2218f57bb565b5d43899ab238d.zip
php-openid-1709607f2f560a2218f57bb565b5d43899ab238d.tar.gz
php-openid-1709607f2f560a2218f57bb565b5d43899ab238d.tar.bz2
[project @ re-organize the server example and make it prettier]
Diffstat (limited to 'examples/server/lib/actions.php')
-rw-r--r--examples/server/lib/actions.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/examples/server/lib/actions.php b/examples/server/lib/actions.php
new file mode 100644
index 0000000..0f73b8b
--- /dev/null
+++ b/examples/server/lib/actions.php
@@ -0,0 +1,122 @@
+<?php
+
+require_once "lib/common.php";
+require_once "lib/session.php";
+require_once "lib/render.php";
+
+require_once "lib/render/login.php";
+require_once "lib/render/sites.php";
+
+/**
+ * Handle a standard OpenID server request
+ */
+function action_default()
+{
+ $server = getServer();
+ return handleResponse($server->getOpenIDResponse());
+}
+
+/**
+ * Log out the currently logged in user
+ */
+function action_logout()
+{
+ setLoggedInUser(null);
+ setRequestInfo(null);
+ return authCancel(null);
+}
+
+/**
+ * Check the input values for a login request
+ */
+function login_checkInput($input)
+{
+ $openid_url = false;
+ $errors = array();
+
+ if (!isset($input['openid_url'])) {
+ $errors[] = 'Enter an OpenID URL to continue';
+ }
+ if (!isset($input['password'])) {
+ $errors[] = 'Enter a password to continue';
+ }
+ if (count($errors) == 0) {
+ $openid_url = $input['openid_url'];
+ $openid_url = Auth_OpenID_normalizeUrl($openid_url);
+ $password = $input['password'];
+ if (!checkLogin($openid_url, $password)) {
+ $errors[] = 'The entered password does not match the ' .
+ 'entered identity URL.';
+ }
+ }
+ return array($errors, $openid_url);
+}
+
+/**
+ * Log in a user and potentially continue the requested identity approval
+ */
+function action_login()
+{
+ $method = $_SERVER['REQUEST_METHOD'];
+ switch ($method) {
+ case 'GET':
+ return login_render();
+ case 'POST':
+ $info = getRequestInfo();
+ $fields = $_POST;
+ if (isset($fields['cancel'])) {
+ return authCancel($info);
+ }
+
+ list ($errors, $openid_url) = login_checkInput($fields);
+ if (count($errors) || !$openid_url) {
+ $needed = $info ? $info->getIdentityURL() : false;
+ return login_render($errors, @$fields['openid_url'], $needed);
+ } else {
+ setLoggedInUser($openid_url);
+ return doAuth($info);
+ }
+ default:
+ return login_render(array('Unsupported HTTP method: $method'));
+ }
+}
+
+/**
+ * Ask the user whether he wants to trust this site
+ */
+function action_trust()
+{
+ $info = getRequestInfo();
+ $trusted = isset($_POST['trust']);
+ if ($info && isset($_POST['remember'])) {
+ $sites = getSessionSites();
+ $sites[$info->getTrustRoot()] = $trusted;
+ setSessionSites($sites);
+ }
+ return doAuth($info, $trusted, true);
+}
+
+function htmlRepr(&$x)
+{
+ return '<pre>' . htmlspecialchars(var_export($_POST, true)) . '</pre>';
+}
+
+function action_sites()
+{
+ $sites = getSessionSites();
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ if (isset($_POST['clear'])) {
+ $sites = null;
+ } else {
+ foreach ($_POST as $k => $v) {
+ if (preg_match('/^site[0-9]+$/', $k) && isset($sites[$v])) {
+ unset($sites[$v]);
+ }
+ }
+ }
+ setSessionSites($sites);
+ }
+ return sites_render($sites);
+}
+
+?> \ No newline at end of file