Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / demos / Zend / OpenId / test_consumer.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/library" . PATH_SEPARATOR . get_include_path());
24
25 /**
26 * @see Zend_OpenId_Consumer
27 */
28 require_once "Zend/OpenId/Consumer.php";
29
30 /**
31 * @see Zend_OpenId_Extension_Sreg
32 */
33 require_once "Zend/OpenId/Extension/Sreg.php";
34
35 $id = "";
36 $status = "";
37 $data = array();
38 if (isset($_POST['openid_action']) &&
39 $_POST['openid_action'] == "login" &&
40 !empty($_POST['openid_identifier'])) {
41
42 $consumer = new Zend_OpenId_Consumer();
43 $props = array();
44 foreach (Zend_OpenId_Extension_Sreg::getSregProperties() as $prop) {
45 if (isset($_POST[$prop])) {
46 if ($_POST[$prop] === "required") {
47 $props[$prop] = true;
48 } else if ($_POST[$prop] === "optional") {
49 $props[$prop] = false;
50 }
51 }
52 }
53 $sreg = new Zend_OpenId_Extension_Sreg($props, null, 1.1);
54 $id = $_POST['openid_identifier'];
55 if (!$consumer->login($id, null, null, $sreg)) {
56 $status = "OpenID login failed (".$consumer->getError().")";
57 }
58 } else if (isset($_GET['openid_mode'])) {
59 if ($_GET['openid_mode'] == "id_res") {
60 $sreg = new Zend_OpenId_Extension_Sreg();
61 $consumer = new Zend_OpenId_Consumer();
62 if ($consumer->verify($_GET, $id, $sreg)) {
63 $status = "VALID $id";
64 $data = $sreg->getProperties();
65 } else {
66 $status = "INVALID $id (".$consumer->getError().")";
67 }
68 } else if ($_GET['openid_mode'] == "cancel") {
69 $status = "CANCELED";
70 }
71 }
72 $sreg_html = "";
73 $sreg = new Zend_OpenId_Extension_Sreg();
74 foreach (Zend_OpenId_Extension_Sreg::getSregProperties() as $prop) {
75 $val = isset($data[$prop]) ? $data[$prop] : "";
76 $sreg_html .= <<<EOF
77 <tr><td>$prop</td>
78 <td>
79 <input type="radio" name="$prop" value="required">
80 </td><td>
81 <input type="radio" name="$prop" value="optional">
82 </td><td>
83 <input type="radio" name="$prop" value="none" checked="1">
84 </td><td>
85 $val
86 </td></tr>
87 EOF;
88 }
89 ?>
90 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
91 <html>
92 <head>
93 <title>Zend OpenID Consumer Example</title>
94 <style>
95 input.openid_login {
96 background: url(login-bg.gif) no-repeat;
97 background-color: #fff;
98 background-position: 0 50%;
99 color: #000;
100 padding-left: 18px;
101 width: 220px;
102 margin-right: 10px;
103 }
104 </style>
105 </head>
106 <body>
107 <?php echo "$status<br>\n";?>
108 <div>
109 <form action="<?php echo Zend_OpenId::selfUrl(); ?>"
110 method="post" onsubmit="this.login.disabled=true;">
111 <fieldset id="openid">
112 <legend>OpenID Login</legend>
113 <input type="hidden" name="openid_action" value="login">
114 <div>
115 <input type="text" name="openid_identifier" class="openid_login" value="<?php echo $id;?>">
116 <input type="submit" name="login" value="login">
117 <table border="0" cellpadding="2" cellspacing="2">
118 <tr><td>&nbsp;</td><td>requird</td><td>optional</td><td>none</td><td>&nbsp</td></tr>
119 <?php echo "$sreg_html<br>\n";?>
120 </table>
121 <br>
122 <a href="<?php echo dirname(Zend_OpenId::selfUrl()); ?>/test_server.php?openid.action=register">register</a>
123 </div>
124 </fieldset>
125 </form>
126 </div>
127 </body>
128 </html>