Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / demos / Zend / OpenId / test_auth.php
1 <?php
2 /**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category Zend
16 * @package Zend_OpenId
17 * @subpackage Demos
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 */
21
22 $dir = realpath(dirname(__FILE__)."/../../..");
23 set_include_path("$dir/incubator/library" . PATH_SEPARATOR . "$dir/library" . PATH_SEPARATOR . get_include_path());
24
25 /**
26 * @see Zend_Auth
27 */
28 require_once "Zend/Auth.php";
29
30 /**
31 * @see Zend_Auth_Adapter_OpenId
32 */
33 require_once "Zend/Auth/Adapter/OpenId.php";
34
35 $status = "";
36 $auth = Zend_Auth::getInstance();
37 if ((isset($_POST['openid_action']) &&
38 $_POST['openid_action'] == "login" &&
39 !empty($_POST['openid_identifier'])) ||
40 isset($_GET['openid_mode']) ||
41 isset($_POST['openid_mode'])) {
42 $result = $auth->authenticate(
43 new Zend_Auth_Adapter_OpenId(@$_POST['openid_identifier']));
44 if ($result->isValid()) {
45 Zend_OpenId::redirect(Zend_OpenId::selfURL());
46 } else {
47 $auth->clearIdentity();
48 foreach ($result->getMessages() as $message) {
49 $status .= "$message<br>\n";
50 }
51 }
52 } else if ($auth->hasIdentity()) {
53 if (isset($_POST['openid_action']) &&
54 $_POST['openid_action'] == "logout") {
55 $auth->clearIdentity();
56 } else {
57 $status = "You are logged-in as " . $auth->getIdentity() . "<br>\n";
58 }
59 }
60 ?>
61 <html><body>
62 <?php echo "$status";?>
63 <form method="post"><fieldset>
64 <legend>OpenID Login</legend>
65 <input type="text" name="openid_identifier" value="">
66 <input type="submit" name="openid_action" value="login">
67 <input type="submit" name="openid_action" value="logout">
68 </fieldset></form></body></html>