diff options
author | tailor <cygnus@janrain.com> | 2006-01-25 00:05:55 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2006-01-25 00:05:55 +0000 |
commit | 42c8b4b2cf9aa20d30a1056ee5715c19b5bdb728 (patch) | |
tree | 6d52fdce338234e0845b9bc978dfa9000e1c315c /examples | |
parent | ee14093e0da75a17a88a3f61b1ab9372822f8f5b (diff) | |
download | php-openid-42c8b4b2cf9aa20d30a1056ee5715c19b5bdb728.zip php-openid-42c8b4b2cf9aa20d30a1056ee5715c19b5bdb728.tar.gz php-openid-42c8b4b2cf9aa20d30a1056ee5715c19b5bdb728.tar.bz2 |
[project @ Further cleaned up example code.]
Diffstat (limited to 'examples')
-rw-r--r-- | examples/consumer/finish_auth.php | 28 | ||||
-rw-r--r-- | examples/consumer/index.php (renamed from examples/consumer/index.html) | 8 | ||||
-rw-r--r-- | examples/consumer/try_auth.php | 17 |
3 files changed, 30 insertions, 23 deletions
diff --git a/examples/consumer/finish_auth.php b/examples/consumer/finish_auth.php index d03a87f..83a2939 100644 --- a/examples/consumer/finish_auth.php +++ b/examples/consumer/finish_auth.php @@ -3,7 +3,8 @@ require_once "common.php"; session_start(); -// Retrieve the token from the session. +// Retrieve the token from the session so we can verify the server's +// response. $token = $_SESSION['openid_token']; // Complete the authentication process using the server's response. @@ -14,20 +15,19 @@ $openid = null; // React to the server's response. $info is the OpenID that was // tried. if ($status != Auth_OpenID_SUCCESS) { - print sprintf("Verification of %s failed.", $info); - exit(0); -} - -// The OpenID authentication either succeeded or was cancelled by the -// user. -if ($info) { - // This means the authentication succeeded. - $openid = $info; - print sprintf("You have successfully verified %s as your identity.", - $openid); + $msg = sprintf("Verification of %s failed.", $info); } else { - // Cancelled. - print 'Verification cancelled.'; + if ($info) { + // This means the authentication succeeded. + $openid = $info; + $success = sprintf("You have successfully verified %s as your identity.", + $openid); + } else { + // This means the authentication was ancelled. + $msg = 'Verification cancelled.'; + } } +include 'index.php'; + ?>
\ No newline at end of file diff --git a/examples/consumer/index.html b/examples/consumer/index.php index 9b5c44c..4096ded 100644 --- a/examples/consumer/index.html +++ b/examples/consumer/index.php @@ -19,6 +19,10 @@ border: 1px solid #e7dc2b; background: #fff888; } + .success { + border: 1px solid #669966; + background: #88ff88; + } .error { border: 1px solid #ff0000; background: #ffaaaa; @@ -39,6 +43,10 @@ is your identity URL. </p> + <?php if (isset($msg)) { print "<div class=\"alert\">$msg</div>"; } ?> + <?php if (isset($error)) { print "<div class=\"error\">$error</div>"; } ?> + <?php if (isset($success)) { print "<div class=\"success\">$success</div>"; } ?> + <div id="verify-form"> <form method="get" action="try_auth.php"> Identity URL: diff --git a/examples/consumer/try_auth.php b/examples/consumer/try_auth.php index 9aec86e..6aa6fd1 100644 --- a/examples/consumer/try_auth.php +++ b/examples/consumer/try_auth.php @@ -5,9 +5,9 @@ session_start(); // Render a default page if we got a submission without an openid // value. -if (!array_key_exists('openid_url', $_GET) || - !$_GET['openid_url']) { - print "Expected an OpenID URL."; +if (empty($_GET['openid_url'])) { + $error = "Expected an OpenID URL."; + include 'index.php'; exit(0); } @@ -21,18 +21,17 @@ $trust_root = sprintf("http://%s%s", dirname($_SERVER['PHP_SELF'])); // Begin the OpenID authentication process. -list($status, $info) = $consumer->beginAuth($openid); +list($status, $info) = @$consumer->beginAuth($openid); // Handle failure status return values. if ($status != Auth_OpenID_SUCCESS) { - print "Authentication error."; + $error = "Authentication error."; + include 'index.php'; exit(0); } -// If we got a successful return, continue the auth by redirecting the -// user agent to the OpenID server. Be sure to give the server a URL -// that will cause this script's "process" function to process the -// server's response. +// Redirect the user to the OpenID server for authentication. Store +// the token for this authentication so we can verify the response. $_SESSION['openid_token'] = $info->token; $redirect_url = @$consumer->constructRedirect($info, $process_url, $trust_root); |