cvs: pearweb /public_html account-edit.php

From: Date: Thu, 17 Jun 2004 02:44:40 +0000
Subject: cvs: pearweb /public_html account-edit.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-20785@lists.php.net to get a copy of this message
danielc Wed Jun 16 22:44:40 2004 EDT Modified files: /pearweb/public_html account-edit.php Log: * Add accesskeys. * Use centralized form styles. * Use " instead of ". * Coding standards. * Use _GET and _POST instead of HTTP_*_VARS. * On successful completion of update, redisplay form after printing success message. * On update of password, reset the cookie rather than forcing a relogin.

http://cvs.php.net/diff.php/pearweb/public_html/account-edit.php?r1=1.24&r2=1.25&ty=u Index: pearweb/public_html/account-edit.php diff -u pearweb/public_html/account-edit.php:1.24 pearweb/public_html/account-edit.php:1.25 --- pearweb/public_html/account-edit.php:1.24 Mon Dec 29 05:25:34 2003 +++ pearweb/public_html/account-edit.php Wed Jun 16 22:44:40 2004 @@ -15,23 +15,26 @@ +----------------------------------------------------------------------+ | Authors: | +----------------------------------------------------------------------+ - $Id: account-edit.php,v 1.24 2003/12/29 10:25:34 mj Exp $ + $Id: account-edit.php,v 1.25 2004/06/17 02:44:40 danielc Exp $ */ auth_require(); -require_once "HTML/Form.php"; +require_once 'HTML/Form.php'; -if (isset($HTTP_GET_VARS['handle'])) { - $handle = $HTTP_GET_VARS['handle']; -} elseif (isset($HTTP_POST_VARS['handle'])) { - $handle = $HTTP_POST_VARS['handle']; +if (isset($_GET['handle'])) { + $handle = strtolower($_GET['handle']); +} elseif (isset($_POST['handle'])) { + $handle = strtolower($_POST['handle']); } else { - $handle = ""; + $handle = ''; } ob_start(); -response_header("Edit Account: $handle"); +response_header('Edit Account: ' . $handle); + +print '<h1>Edit Account &quot;' . $handle . "&quot;</h1>\n"; +print "<ul><li><a href=\"#password\">Manage your password</a></li></ul>"; $admin = $auth_user->isAdmin(); $user = $auth_user->is($handle); @@ -42,17 +45,16 @@ exit(); } -if (empty($handle) && !isset($HTTP_POST_VARS['command'])) { +if (empty($handle) && !isset($_POST['command'])) { PEAR::raiseError("No valid handle found!"); } -if (!isset($HTTP_POST_VARS['command'])) { - $HTTP_POST_VARS['command'] = "display"; +if (!isset($_POST['command'])) { + $_POST['command'] = "display"; } -switch ($HTTP_POST_VARS['command']) { - - case "update" : { +switch ($_POST['command']) { + case 'update': if (isset($_POST['showemail'])) { $_POST['showemail'] = 1; } else { @@ -84,183 +86,129 @@ } } - print "The <b>update</b> has been executed <b>successfully</b>."; - print "<br /><br />"; - print "Back to the info page for " . $user->makeLink() . "."; - - $handle = $HTTP_POST_VARS['handle']; - - response_footer(); - return; - } + print '<div class="thanks">'; + print 'Your information was successfully updated.'; + print "</div>\n"; + break; - case "change_password" : { + case 'change_password': $user = &new PEAR_User($dbh, $handle); - $execute = true; - if (empty($_POST['password_old']) || empty($_POST['password1']) || + if (empty($_POST['password_old']) || empty($_POST['password']) || empty($_POST['password2'])) { - PEAR::raiseError("Please fill out all password fields."); - $execute = false; + PEAR::raiseError('Please fill out all password fields.'); + break; } - if ($user->get("password") != md5($_POST['password_old'])) { - PEAR::raiseError("You provided a wrong old password."); - $execute = false; + if ($user->get('password') != md5($_POST['password_old'])) { + PEAR::raiseError('You provided a wrong old password.'); + break; } - if ($_POST['password1'] != $_POST['password2']) { - PEAR::raiseError("The new passwords do not match."); - $execute = false; + if ($_POST['password'] != $_POST['password2']) { + PEAR::raiseError('The new passwords do not match.'); + break; } - if ($execute === true) { - $user->set("password", md5($_POST['password1'])); - if ($user->store()) { - auth_logout(); - localRedirect("/login.php"); + $user->set('password', md5($_POST['password'])); + if ($user->store()) { + if (!empty($_POST['PEAR_PERSIST'])) { + $expire = 2147483647; + } else { + $expire = 0; } + setcookie('PEAR_PW', md5($_POST['password']), $expire, '/'); + + print '<div class="thanks">'; + print 'Your password was successfully updated.'; + print "</div>\n"; } - } + break; +} - default : { - $dbh->setFetchmode(DB_FETCHMODE_ASSOC); - $row = $dbh->getRow("SELECT * FROM users WHERE handle = ?", - array($handle)); - $cvs_acl_arr = $dbh->getCol("SELECT path FROM cvs_acl ". - "WHERE username = ? AND access = 1", 0, - array($handle)); - $cvs_acl = implode("\n", $cvs_acl_arr); - if ($row === null) { - PEAR::raiseError("No account information found!"); - } - - - print "<form action=\"" . $HTTP_SERVER_VARS['PHP_SELF'] . "?handle=" . $handle . "\" method=\"post\">\n"; - print "<input type=\"hidden\" name=\"command\" value=\"update\" />\n"; - print "<input type=\"hidden\" name=\"handle\" value=\"$handle\" />\n"; - - print "<h1>Editing account \"$handle\"</h1>\n"; - - print "<ul><li><a href=\"#password\">Manage your password</a></li></ul>"; - - $bb = new BorderBox("Edit your information"); - - print "<table border=\"0\" cellspacing=\"1\" cellpadding=\"5\" width=\"100%\">\n"; - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Handle:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">$handle</td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Name:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayText("name", $row['name']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Email:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayText("email", $row['email']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">PGP Key ID:<br /><small>(Without leading 0x)</small></th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayText("pgpkeyid", $row['pgpkeyid']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Homepage:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayText("homepage", $row['homepage']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Additional user information:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayTextarea("userinfo", $row['userinfo']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">CVS Access:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayTextarea("cvs_acl", $cvs_acl); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">URL to wishlist:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayText("wishlist", $row['wishlist']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Show Email address:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayCheckbox("showemail", $row['showemail']); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">&nbsp;</th>\n"; - print " <td bgcolor=\"#e8e8e8\"><input type=\"submit\" value=\"Submit\" name=\"submit\" />&nbsp;<input type=\"reset\" name=\"reset\" value=\"Reset\" /></td>\n"; - print " </tr>\n"; - - print "</table>\n"; - - print "</form>\n"; - - $bb->end(); - - print "<br /><br /><a name=\"password\" />"; - - $bb = new BorderBox("Change password"); - - print "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n"; - print "<input type=\"hidden\" name=\"handle\" value=\"" . $handle . "\" />\n"; - print "<input type=\"hidden\" name=\"command\" value=\"change_password\" />\n"; - print "<table border=\"0\" cellspacing=\"1\" cellpadding=\"5\" width=\"100%\">\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">Old Password:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayPassword("password_old", "", 25); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">New Password:</th>\n"; - print " <td bgcolor=\"#e8e8e8\">"; - HTML_Form::displayPassword("password1", "", 25); - print " repeat "; - HTML_Form::displayPassword("password2", "", 25); - print " </td>\n"; - print " </tr>\n"; - - print " <tr>\n"; - print " <th bgcolor=\"#CCCCCC\">&nbsp;</th>\n"; - print " <td bgcolor=\"#e8e8e8\"><input type=\"submit\" value=\"Submit\" name=\"submit\" />"; - print " (You will be redirected to a login form where you have"; - print " to enter your new password.)"; - print " </td>\n"; - print " </tr>\n"; - print "</table>\n"; +$dbh->setFetchmode(DB_FETCHMODE_ASSOC); - $bb->end(); +$row = $dbh->getRow('SELECT * FROM users WHERE handle = ?', array($handle)); - response_footer(); +$cvs_acl_arr = $dbh->getCol('SELECT path FROM cvs_acl' + . ' WHERE username = ? AND access = 1', 0, + array($handle)); +$cvs_acl = implode("\n", $cvs_acl_arr); - } +if ($row === null) { + PEAR::raiseError('No account information found!'); + response_footer(); + exit; } + +$th = 'class="form-label_left"'; +$td = 'class="form-input"'; + +$form = new HTML_Form($_SERVER['PHP_SELF'], 'post'); + +$form->addPlaintext('Handle:', $handle, + $th, $td); +$form->addText('name', '<span class="accesskey">N</span>ame:', + $row['name'], 40, null, '', + $th, $td); +$form->addText('email', 'Email:', + $row['email'], 40, null, '', + $th, $td); +$form->addText('pgpkeyid', 'PGP Key ID:' + . '<p class="cell_note">(Without leading 0x)</p>', + $row['pgpkeyid'], 40, 8, '', + $th, $td); +$form->addText('homepage', 'Homepage:', + $row['homepage'], 40, null, '', + $th, $td); +$form->addTextarea('userinfo', + 'Additional User Information:', + $row['userinfo'], 40, 5, null, '', + $th, $td); +$form->addTextarea('cvs_acl', + 'CVS Access:', + $cvs_acl, 40, 5, null, '', + $th, $td); +$form->addText('wishlist', 'Wishlist URI:', + $row['wishlist'], 40, null, '', + $th, $td); +$form->addCheckbox('showemail', 'Show email address?', + $row['showemail'], '', + $th, $td); +$form->addSubmit('submit', 'Submit', '', + $th, $td); +$form->addHidden('handle', $handle); +$form->addHidden('command', 'update'); +$form->display('class="form-holder" style="margin-bottom: 2em;"' + . ' cellspacing="1"', + 'Edit Your Information', 'class="form-caption"'); + + +print '<a name="password"></a>' . "\n"; + + +$form = new HTML_Form($_SERVER['PHP_SELF'], 'post'); +$form->addPlaintext('<span class="accesskey">O</span>ld Password:', + $form->returnPassword('password_old', '', 40, 0, + 'accesskey="o"'), + $th, $td); +$form->addPassword('password', 'Password:', + '', 10, null, '', + $th, $td); +$form->addCheckbox('PEAR_PERSIST', 'Remember username and password?', + '', '', + $th, $td); +$form->addSubmit('submit', 'Submit', '', + $th, $td); +$form->addHidden('handle', $handle); +$form->addHidden('command', 'change_password'); +$form->display('class="form-holder" cellspacing="1"', + 'Change Password', 'class="form-caption"'); + ob_end_flush(); +response_footer(); + ?>
« previous php.pear.cvs (#20785) next »