diff options
| author | Christophe Nowicki <cnowicki@easter-eggs.com> | 2004-08-18 15:03:56 +0000 |
|---|---|---|
| committer | Christophe Nowicki <cnowicki@easter-eggs.com> | 2004-08-18 15:03:56 +0000 |
| commit | 131a818d244eea55a4e038c654c72ceee0a17526 (patch) | |
| tree | 3a11a9fa8260bd3a1b0f1d46b15373fe4160f0c2 | |
| parent | 712ff1a9f7f68c8ade853f3ae031666a63120fa8 (diff) | |
| download | lasso-131a818d244eea55a4e038c654c72ceee0a17526.tar.gz lasso-131a818d244eea55a4e038c654c72ceee0a17526.tar.xz lasso-131a818d244eea55a4e038c654c72ceee0a17526.zip | |
Service Provider written in PHP (login is working and logout will work soon ;0)
| -rw-r--r-- | php/Attic/examples/sample-sp/admin_user.php | 162 | ||||
| -rw-r--r-- | php/Attic/examples/sample-sp/assertionConsumer.php | 174 | ||||
| -rw-r--r-- | php/Attic/examples/sample-sp/config.php.inc | 27 | ||||
| -rw-r--r-- | php/Attic/examples/sample-sp/index.php | 119 | ||||
| -rwxr-xr-x | php/Attic/examples/sample-sp/install.php | 130 | ||||
| -rw-r--r-- | php/Attic/examples/sample-sp/login.php | 58 | ||||
| -rw-r--r-- | php/Attic/examples/sample-sp/logout.php | 45 | ||||
| -rw-r--r-- | php/Attic/examples/sample-sp/register.php | 83 |
8 files changed, 798 insertions, 0 deletions
diff --git a/php/Attic/examples/sample-sp/admin_user.php b/php/Attic/examples/sample-sp/admin_user.php new file mode 100644 index 00000000..83e9b7b1 --- /dev/null +++ b/php/Attic/examples/sample-sp/admin_user.php @@ -0,0 +1,162 @@ +<?php +/* + * Service Provider Example -- User Administration + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + include "config.php.inc"; + + require_once 'DB.php'; + + + $db = &DB::connect($dsn); + + if (DB::isError($db)) + die($db->getMessage()); + + if (!empty($_GET['dump'])) { + $query = "SELECT identity_dump FROM users WHERE user_id='" . $_GET['dump'] . "'"; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + $row = $res->fetchRow(); +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> +<body> +<table> +<caption>Identity Dump</caption> +<tr> +<td> +<textarea rows="15" cols="50"> +<?php + echo htmlentities($row[0], ENT_QUOTES); +?> +</textarea> +</td> +</tr> +<tr> +<td align="center"><a href="javascript:window.close(self)">Close</a></td> +</tr> +</table> +</body> +</html> +<?php + exit; + } + + if (!empty($_GET['del'])) { + + $query = "DELETE FROM nameidentifiers WHERE user_id='" . $_GET['del'] . "'" ; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + + $query = "DELETE FROM users WHERE user_id='" . $_GET['del'] . "'" ; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + + } + + + $query = "SELECT * FROM users"; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> +<head> +<title>Lasso Service Provider Example : Users Management</title> +<script type="text/javascript"> + + function openpopup(popurl){ + var winpops=window.open(popurl,"","width=400,height=300") + } + +</script> +</head> +<body> + +<table border="1" align="center"> +<caption>Users</caption> +<?php + $num_col = $res->numCols(); + $tableinfo = $db->tableInfo($res); +?> +<thead> +<tr align="center"><?php + for ($i = 0; $i < $num_col; $i++) { + echo "<td>" . $tableinfo[$i]['name'] ."</td>"; + } +?><td> </td> +</tr> +</thead> +<tbody> +<?php + while ($row =& $res->fetchRow()) { +?> +<tr align="center"> +<?php + for ($i = 0; $i < $num_col; $i++) + { + ?> + <td> + <?php + switch ($tableinfo[$i]['name']) + { + case "identity_dump": + echo "<a href=javascript:openpopup('". $PHP_SELF . '?dump=' . $row[0] . "')>view</a>"; + break; + + default: + echo (empty($row[$i])) ? " " : $row[$i]; + } + ?> + </td> + <?php + } + ?> + <td> + <a href="<?php echo $PHP_SELF . '?del=' . $row[0]; ?>">delete</a> + </td> +</tr> +<?php +} +?> +</tbody> +<tfoot> +<tr> +<td colspan="<?php echo $num_col; ?>"> </td> +<td>Total: <?php echo $res->numRows();?> Users</td> +</tr> +</tfoot> +</table> + +</body> + +</html> +<?php + $db->disconnect(); +?> diff --git a/php/Attic/examples/sample-sp/assertionConsumer.php b/php/Attic/examples/sample-sp/assertionConsumer.php new file mode 100644 index 00000000..a84cb847 --- /dev/null +++ b/php/Attic/examples/sample-sp/assertionConsumer.php @@ -0,0 +1,174 @@ +<?php +/* + * Service Provider Example -- AssertionConsumer + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + include "config.php.inc"; + + require_once 'DB.php'; + + + if (!$_GET['SAMLart']) { + exit(1); + } + + session_start(); + + lasso_init(); + + $server_dump = file_get_contents($server_dump_filename); + + $server = lasso_server_new_from_dump($server_dump); + + $login = lasso_login_new($server); + + lasso_login_init_request($login, $_SERVER['QUERY_STRING'], lassoHttpMethodRedirect); + lasso_login_build_request_msg($login); + + $profile = lasso_cast_to_profile($login); + + + $msg_url = lasso_profile_get_msg_url($profile); + $msg_body = lasso_profile_get_msg_body($profile); + + /*print "msg_url : " . $msg_url . "\n<br>"; + print "msg_body : " . $msg_body . "\n<br>"; */ + + $url = parse_url($msg_url); + + $soap = sprintf( + "POST %s HTTP/1.1\r\nHost: %s:%d\r\nAccept-Encoding: identity\r\nContent-Length: %d\r\nContent-Type: text/xml\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html\r\nConnection: close\r\n\r\n%s\r\n", + $url['path'], $url['host'], $url['port'], strlen($msg_body), $msg_body); + + + # PHP 4.3.0 with OpenSSL support required + $fp = fsockopen("ssl://" . $url['host'], $url['port'], $errno, $errstr, 30) or die($errstr ($errno)); + fwrite($fp, $soap); + $ret = fgets($fp); + + if (!preg_match("/^HTTP\/1\\.. 200/i", $ret)) { + die("Wrong artifact"); + } + + while (!feof($fp)) { + $reponse .= @fread($fp, 8192); + } + + fclose($fp); + + list($header, $body) = preg_split("/\r\n\r\n/", $reponse, 2); + + lasso_login_process_response_msg($login, $body); + $nameidentifier = lasso_profile_get_nameidentifier($profile); + + // print "nameidentifier: " . $nameidentifier . "<br>\n"; + + + # Look for the name_identifier in user db. + $options = array( + 'debug' => 2, + ); + $db = &DB::connect($dsn, $options); + + if (DB::isError($db)) + die($db->getMessage()); + + $query = "SELECT user_id FROM nameidentifiers WHERE name_identifier='$nameidentifier'"; + $res =& $db->query($query); + + if (DB::isError($res)) + die($res->getMessage()); + + if ($res->numRows() > 0) + { + $row =& $res->fetchRow(); + $user_id = $row[0]; + // print "user id : " . $user_id . "<br>\n"; + + # Get Identity Dump from the data base + $query = "SELECT identity_dump FROM users WHERE user_id='$user_id'"; + $res =& $db->query($query); + + if (DB::isError($db)) + die($db->getMessage()); + + $row =& $res->fetchRow(); + $identity_dump = $row[0]; + + lasso_profile_set_identity_from_dump($profile, $identity_dump); + + $res->free(); + + lasso_login_accept_sso($login); + } + else + { + // New User + lasso_login_accept_sso($login); + + $identity = lasso_profile_get_identity($profile); + $identity_dump = lasso_identity_dump($identity); + // print "identity_dump: " . $identity_dump . "<br>\n"; + + $session = lasso_profile_get_session($profile); + $session_dump = lasso_session_dump($session); + // print "session_dump: " . $session_dump . "<br>\n"; + + // Insert into users + $identity_dump_quoted = $db->quoteSmart($identity_dump); + $query = "INSERT INTO users (user_id,identity_dump,created) VALUES(nextval('user_id_seq'), $identity_dump_quoted, NOW())"; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + + + // Get UserID + $query = "SELECT last_value FROM user_id_seq"; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + $row = $res->fetchRow(); + $user_id = $row[0]; + + // Insert into nameidentifiers + $query = "INSERT INTO nameidentifiers VALUES('$nameidentifier', '$user_id')"; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + + + $_SESSION["nameidentifier"] = $nameidentifier; + $_SESSION["session_dump"] = $session_dump; + $_SESSION["user_id"] = $user_id; + + $url = "register.php"; + } + + $db->disconnect(); + + lasso_shutdown(); + + header("Request-URI: $url"); + header("Content-Location: $url"); + header("Location: $url"); + exit(); +?> diff --git a/php/Attic/examples/sample-sp/config.php.inc b/php/Attic/examples/sample-sp/config.php.inc new file mode 100644 index 00000000..baf26b4a --- /dev/null +++ b/php/Attic/examples/sample-sp/config.php.inc @@ -0,0 +1,27 @@ +<?php +/* + * Service Provider Example -- Configuration File + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + $server_dump_filename = "lasso_server_dump.xml"; + + $dsn = "pgsql://sp:sp@localhost/sp"; +?> diff --git a/php/Attic/examples/sample-sp/index.php b/php/Attic/examples/sample-sp/index.php new file mode 100644 index 00000000..73179fb6 --- /dev/null +++ b/php/Attic/examples/sample-sp/index.php @@ -0,0 +1,119 @@ +<?php +/* + * Service Provider Example -- Configuration File + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + if(!extension_loaded('lasso')) { + $ret = @dl('lasso.' . PHP_SHLIB_SUFFIX); + if ($ret == FALSE) + { + + print "<p align='center'><b>The Lasso Extension is not available</b><br>"; + print "Please check your PHP extensions<br>"; + print "You can get more informations about <b>Lasso</b> at <br>"; + print "<a href='http://lasso.entrouvert.org/'>http://lasso.entrouvert.org/</a></p>"; + exit(); + } + } + + session_start(); + + lasso_init(); + +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> +<head> +<title>Lasso Service Provider Example</title> +</head> + +<body> +<br><br> +<table border="1" align="center" frame="above"> +<tr> + <td><b>Serice Provider Administration</b></td> +</tr> +<tr> + <td><a href="admin_user.php">Users Management</a></td> +</tr> +<tr> + <td><a href="admin_fed.php">Federation Administration</a></td> +</tr> +<tr> +<tr> + <td><b>Serice Provider Fonctionnality</b></td> +</tr> +<?php + if (!isset($_SESSION["nameidentifier"])) { + ?> +<tr> + <td><a href="login.php">Login!</a></td> +</tr> +<?php } else { ?> +<tr> + <td><a href="logout.php">Logout!</a></td> +</tr> +<?php } ?> +</table> + +<table border="1" align="center" frame="above"> +<caption><b>Status</b></caption> +<tr> + <?php + if (!isset($_SESSION["nameidentifier"])) + { + echo "<td>User is <b>not</b> logged in!</td>"; + } + else + { + ?> + <td colspan='2' align="center">User <b>is</b> logged in!</td> +</tr> +<tr> + <td><b>Name Identifier:</b></td><td><?php echo $_SESSION["nameidentifier"]; ?></td> +</tr> +<tr> + <td><b>UserID:</b></td><td><?php echo $_SESSION["user_id"]; ?></td> +</tr> +<tr> + <td><b>Last Name:</b></td><td><?php echo $last_name; ?></td> +</tr> +<tr> + <td><b>First Name:</b></td><td><?php echo $first_name; ?></td> + <?php + } + ?> +</tr> +</table> + +<p>Lasso Version : <?php echo lasso_version(); ?></p> + +<br> +<p align="right">Copyright © 2004 Entr'ouvert</p> + +</body> + +</html> +<?php + lasso_shutdown(); + ?> diff --git a/php/Attic/examples/sample-sp/install.php b/php/Attic/examples/sample-sp/install.php new file mode 100755 index 00000000..7304a27b --- /dev/null +++ b/php/Attic/examples/sample-sp/install.php @@ -0,0 +1,130 @@ +<?php +/* + * + * Service Provider Example -- Installation Script + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + include "config.php.inc"; + + require_once 'DB.php'; + + print "Install script for L.A.S.S.O (Liberty Alliance Single Sign On)\n"; + + lasso_init(); + print "$server_dump_filename: "; + + + # Create XML Server Dump + if (file_exists($server_dump_filename)) + { + print "file already exists.\n"; + } + else + { + $server = lasso_server_new( + "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/metadata.xml", + "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/public-key.pem", + "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/private-key-raw.pem", + "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/certificate.pem", + lassoSignatureMethodRsaSha1); + + lasso_server_add_provider($server, + "/home/cnowicki/mcvs/lasso/tests/data/idp1-la/metadata.xml", + "/home/cnowicki/mcvs/lasso/tests/data/idp1-la/public-key.pem", + "/home/cnowicki/mcvs/lasso/tests/data/ca1-la/certificate.pem" + ); + + $dump = lasso_server_dump($server); + $fd = fopen($server_dump_filename, "w"); + fwrite($fd, $dump); + print "wrote.\n"; + fclose($fd); + } + + print "Create User Database.\n"; + print "DSN : $dsn\n"; + + $options = array( + 'debug' => 2, + ); + + $db = &DB::connect($dsn, $options); + if (DB::isError($db)) { + die($db->getMessage()); + } + + + # Drop user_id_seq + print "DROP user_id_seq.\n"; + $query = "DROP SEQUENCE user_id_seq"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + + # Create user_id_seq + print "Create user_id_seq Sequence.\n"; + $query = "CREATE SEQUENCE user_id_seq"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + /* print "DROP users.\n"; + $query = "DROP TABLE users CASCADE"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); */ + + # Create local data base + print "Create users Table.\n"; + $query = "CREATE TABLE users ( + user_id varchar(100) primary key, + identity_dump text, + first_name varchar(50), + last_name varchar(50), + created timestamp)"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + /* print "DROP nameidentifiers.\n"; + $query = "DROP TABLE nameidentifiers"; + + $res =& $db->query($query); */ + + if (DB::isError($res)) + die($res->getMessage()); + + print "Create nameidentifiers Table.\n"; + $query = "CREATE TABLE nameidentifiers ( + name_identifier varchar(100) primary key, + user_id varchar(100), + FOREIGN KEY (user_id) REFERENCES users (user_id))"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + + $db->disconnect(); + + lasso_shutdown(); +?> diff --git a/php/Attic/examples/sample-sp/login.php b/php/Attic/examples/sample-sp/login.php new file mode 100644 index 00000000..4b70c095 --- /dev/null +++ b/php/Attic/examples/sample-sp/login.php @@ -0,0 +1,58 @@ +<?php +/* + * + * Service Provider Example -- Simple Sing On + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + include "config.php.inc"; + + lasso_init(); + + $server_dump = file_get_contents($server_dump_filename); + + $server = lasso_server_new_from_dump($server_dump); + + $login = lasso_login_new($server); + + lasso_login_init_authn_request($login); + + $profile = lasso_cast_to_profile($login); + + $node = lasso_profile_get_request($profile); + + $lib_authn_request = lasso_cast_to_lib_authn_request($node); + + // lasso_lib_authn_request_set_forceauthn($lib_authn_request, TRUE); + lasso_lib_authn_request_set_ispassive($lib_authn_request, FALSE); + lasso_lib_authn_request_set_nameidpolicy($lib_authn_request, lassoLibNameIDPolicyTypeFederated); + lasso_lib_authn_request_set_consent($lib_authn_request, lassoLibConsentObtained); + + lasso_login_build_authn_request_msg($login, "https://idp1/metadata"); + + + $url = lasso_profile_get_msg_url($profile); + + header("Request-URI: $url"); + header("Content-Location: $url"); + header("Location: $url"); + exit(); +?> diff --git a/php/Attic/examples/sample-sp/logout.php b/php/Attic/examples/sample-sp/logout.php new file mode 100644 index 00000000..1d4ab750 --- /dev/null +++ b/php/Attic/examples/sample-sp/logout.php @@ -0,0 +1,45 @@ +<?php +/* + * Service Provider Example -- AssertionConsumer + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + include "config.php.inc"; + + session_start(); + + if (!isset($_SESSION["nameidentifier"])) { + print "User is not logged in"; + exit(0); + } + + lasso_init(); + + $server_dump = file_get_contents($server_dump_filename); + + $server = lasso_server_new_from_dump($server_dump); + + $logout = lasso_logout_new($server, lassoProviderTypeSp); + + // $profile = lasso_cast_to_profile($logout); + + lasso_shutdown(); +?> diff --git a/php/Attic/examples/sample-sp/register.php b/php/Attic/examples/sample-sp/register.php new file mode 100644 index 00000000..76b43380 --- /dev/null +++ b/php/Attic/examples/sample-sp/register.php @@ -0,0 +1,83 @@ +<?php +/* + * Service Provider Example -- Register Form + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: Christophe Nowicki <cnowicki@easter-eggs.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + include "config.php.inc"; + + require_once 'DB.php'; + + session_start(); + + if (!isset($_SESSION["nameidentifier"])) { + print "User is not logged in"; + exit(0); + } + + switch($_POST['action']) { + case "submit": + $db = &DB::connect($dsn); + + if (DB::isError($db)) + die($db->getMessage()); + + $query = "UPDATE users SET first_name='" . $_POST['first_name'] . "',last_name='". $_POST['last_name'] ."' WHERE user_id='".$_SESSION["user_id"]."'"; + $res =& $db->query($query); + if (DB::isError($res)) + print $res->getMessage(). "\n"; + + $url = "index.php"; + header("Request-URI: $url"); + header("Content-Location: $url"); + header("Location: $url"); + break; + default: +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> +<head> +<title>Lasso Service Provider Example : Registration Form</title> +</head> + +<body> +<form name='frm' action="<?php echo $PHP_SELF; ?>" method='post'> +<table align="center"> +<caption>Registration Form</caption> +<tr> + <td>First Name:</td><td><input type='text' name="first_name" maxlength='50'></td> +</tr> +<tr> + <td>Last Name:</td><td><input type='text' name="last_name" maxlength='50'></td> +</tr> +<tr> + <td> </td><td><input type='submit' value="Ok"></td> +</tr> +</table> +<input type='hidden' name='action' value='submit'> +</form> + +</body> +</html> +<?php +} +?> |
