From 1267e34b4c5d4e32537277019156366503a754cb Mon Sep 17 00:00:00 2001 From: chriskl Date: Thu, 8 May 2003 15:14:14 +0000 Subject: [PATCH] finish off account management screen. fix bugs in displaying empty groups. bump config version number. --- classes/database/Postgres.php | 28 ++++++++++++--- conf/config.inc.php-dist | 7 ++-- groups.php | 4 +-- lang/english.php | 13 +++++-- lang/recoded/english.php | 13 +++++-- libraries/lib.inc.php | 4 +-- topbar.php | 7 ++-- users.php | 66 ++++++++++++++++++++++++++++++++--- 8 files changed, 115 insertions(+), 27 deletions(-) diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 71a9fac7..e1fdf715 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres.php,v 1.97 2003/05/08 14:15:57 chriskl Exp $ + * $Id: Postgres.php,v 1.98 2003/05/08 15:14:14 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -1452,6 +1452,21 @@ class Postgres extends BaseDB { // User functions + /** + * Changes a user's password + * @param $username The username + * @param $password The new password + * @return 0 success + */ + function changePassword($username, $password) { + $this->fieldClean($username); + $this->clean($password); + + $sql = "ALTER USER \"{$username}\" WITH PASSWORD '{$password}'"; + + return $this->execute($sql); + } + /** * Returns all users in the database cluster * @return All users @@ -1575,11 +1590,14 @@ class Postgres extends BaseDB { $sql = "SELECT grolist FROM pg_group WHERE groname = '{$groname}'"; $grodata = $this->selectSet($sql); - $members = $grodata->f['grolist']; - $members = ereg_replace("\{|\}","",$members); - $this->clean($members); + if ($grodata->f['grolist'] !== null && $grodata->f['grolist'] != '{}') { + $members = $grodata->f['grolist']; + $members = ereg_replace("\{|\}","",$members); + $this->clean($members); - $sql = "SELECT usename FROM pg_user WHERE usesysid IN ({$members}) ORDER BY usename"; + $sql = "SELECT usename FROM pg_user WHERE usesysid IN ({$members}) ORDER BY usename"; + } + else $sql = "SELECT usename FROM pg_user WHERE false"; return $this->selectSet($sql); } diff --git a/conf/config.inc.php-dist b/conf/config.inc.php-dist index c6da4c44..f96ff505 100644 --- a/conf/config.inc.php-dist +++ b/conf/config.inc.php-dist @@ -4,7 +4,7 @@ * Central phpPgAdmin configuration. As a user you may modify the * settings here for your particular configuration. * - * $Id: config.inc.php-dist,v 1.19 2003/05/08 14:15:58 chriskl Exp $ + * $Id: config.inc.php-dist,v 1.20 2003/05/08 15:14:15 chriskl Exp $ */ // An example server. Create as many of these as you wish, @@ -37,6 +37,9 @@ // means. $conf['owned_reports_only'] = false; + // Minimum length users can set their password to. + $conf['min_password_length'] = 1; + // Width of the left frame in pixels (object browser) $conf['left_width'] = 200; @@ -56,6 +59,6 @@ * Don't modify anything below this line * *****************************************/ - $conf['version'] = 6; + $conf['version'] = 7; ?> diff --git a/groups.php b/groups.php index 86cb249c..5962203a 100644 --- a/groups.php +++ b/groups.php @@ -3,7 +3,7 @@ /** * Manage groups in a database cluster * - * $Id: groups.php,v 1.7 2003/04/18 11:08:26 chriskl Exp $ + * $Id: groups.php,v 1.8 2003/05/08 15:14:14 chriskl Exp $ */ // Include application functions @@ -35,7 +35,7 @@ echo "\n"; } - else echo "

{$lang['strinvalidparam']}

\n"; + else echo "

{$lang['strnousers']}

\n"; echo "

{$lang['strshowallgroups']}

\n"; } diff --git a/lang/english.php b/lang/english.php index 1bb11317..85d05243 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.75 2003/05/08 14:15:58 chriskl Exp $ + * $Id: english.php,v 1.76 2003/05/08 15:14:15 chriskl Exp $ */ // Language and character set @@ -66,6 +66,7 @@ $lang['strunique'] = 'Unique'; $lang['strprimary'] = 'Primary'; $lang['strexport'] = 'Export'; + $lang['strimport'] = 'Import'; $lang['strsql'] = 'SQL'; $lang['strgo'] = 'Go'; $lang['stradmin'] = 'Admin'; @@ -80,6 +81,8 @@ $lang['strinstead'] = 'Do Instead'; $lang['strwhen'] = 'When'; $lang['strformat'] = 'Format'; + $lang['strdata'] = 'Data'; + $lang['strconfirm'] = 'Confirm'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -151,7 +154,7 @@ $lang['strcreatedb'] = 'Create DB?'; $lang['strexpires'] = 'Expires'; $lang['strnousers'] = 'No users found.'; - $lang['struserupdated'] = 'User updated.'; + $lang['struserupdated'] = 'User updated.'; $lang['struserupdatedbad'] = 'User update failed.'; $lang['strshowallusers'] = 'Show All Users'; $lang['strcreateuser'] = 'Create User'; @@ -162,7 +165,11 @@ $lang['struserdroppedbad'] = 'Failed to drop user.'; $lang['straccount'] = 'Account'; $lang['strchangepassword'] = 'Change Password'; - + $lang['strpasswordchanged'] = 'Password changed.'; + $lang['strpasswordchangedbad'] = 'Failed to change password.'; + $lang['strpasswordshort'] = 'Password is too short.'; + $lang['strpasswordconfirm'] = 'Password does not match confirmation.'; + // Groups $lang['strgroupadmin'] = 'Group Admin'; $lang['strgroup'] = 'Group'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 6a14774a..fd32b25a 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.27 2003/05/08 14:15:59 chriskl Exp $ + * $Id: english.php,v 1.28 2003/05/08 15:14:15 chriskl Exp $ */ // Language and character set @@ -66,6 +66,7 @@ $lang['strunique'] = 'Unique'; $lang['strprimary'] = 'Primary'; $lang['strexport'] = 'Export'; + $lang['strimport'] = 'Import'; $lang['strsql'] = 'SQL'; $lang['strgo'] = 'Go'; $lang['stradmin'] = 'Admin'; @@ -80,6 +81,8 @@ $lang['strinstead'] = 'Do Instead'; $lang['strwhen'] = 'When'; $lang['strformat'] = 'Format'; + $lang['strdata'] = 'Data'; + $lang['strconfirm'] = 'Confirm'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -151,7 +154,7 @@ $lang['strcreatedb'] = 'Create DB?'; $lang['strexpires'] = 'Expires'; $lang['strnousers'] = 'No users found.'; - $lang['struserupdated'] = 'User updated.'; + $lang['struserupdated'] = 'User updated.'; $lang['struserupdatedbad'] = 'User update failed.'; $lang['strshowallusers'] = 'Show All Users'; $lang['strcreateuser'] = 'Create User'; @@ -162,7 +165,11 @@ $lang['struserdroppedbad'] = 'Failed to drop user.'; $lang['straccount'] = 'Account'; $lang['strchangepassword'] = 'Change Password'; - + $lang['strpasswordchanged'] = 'Password changed.'; + $lang['strpasswordchangedbad'] = 'Failed to change password.'; + $lang['strpasswordshort'] = 'Password is too short.'; + $lang['strpasswordconfirm'] = 'Password does not match confirmation.'; + // Groups $lang['strgroupadmin'] = 'Group Admin'; $lang['strgroup'] = 'Group'; diff --git a/libraries/lib.inc.php b/libraries/lib.inc.php index e4f232be..dd3be6c2 100644 --- a/libraries/lib.inc.php +++ b/libraries/lib.inc.php @@ -3,7 +3,7 @@ /** * Function library read in upon startup * - * $Id: lib.inc.php,v 1.44 2003/05/08 14:15:59 chriskl Exp $ + * $Id: lib.inc.php,v 1.45 2003/05/08 15:14:15 chriskl Exp $ */ // Set error reporting level to max @@ -29,7 +29,7 @@ // Configuration file version. If this is greater than that in config.inc.php, then // the app will refuse to run. This and $conf['version'] should be incremented whenever // backwards incompatible changes are made to config.inc.php-dist. - $conf['base_version'] = 6; + $conf['base_version'] = 7; // List of available language files $appLangFiles = array( diff --git a/topbar.php b/topbar.php index 1b76b0b8..5c4d213b 100755 --- a/topbar.php +++ b/topbar.php @@ -3,7 +3,7 @@ /** * Top menu for phpPgAdmin * - * $Id: topbar.php,v 1.10 2003/05/08 14:15:55 chriskl Exp $ + * $Id: topbar.php,v 1.11 2003/05/08 15:14:14 chriskl Exp $ */ // Include application functions @@ -31,13 +31,10 @@ ?> | | - - | + | | diff --git a/users.php b/users.php index 067b3d84..5c219328 100644 --- a/users.php +++ b/users.php @@ -3,7 +3,7 @@ /** * Manage users in a database cluster * - * $Id: users.php,v 1.9 2003/05/08 14:15:56 chriskl Exp $ + * $Id: users.php,v 1.10 2003/05/08 15:14:14 chriskl Exp $ */ // Include application functions @@ -29,11 +29,13 @@ $userdata = &$data->getUser($_SESSION['webdbUsername']); if ($userdata->recordCount() > 0) { + $userdata->f[$data->uFields['usuper']] = $data->phpBool($userdata->f[$data->uFields['usuper']]); + $userdata->f[$data->uFields['ucreatedb']] = $data->phpBool($userdata->f[$data->uFields['ucreatedb']]); echo "\n"; echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "
{$lang['strusername']}{$lang['strsuper']}{$lang['strcreatedb']}{$lang['strexpires']}
", htmlspecialchars($userdata->f[$data->uFields['uname']]), "", $userdata->f[$data->uFields['usuper']], "", $userdata->f[$data->uFields['ucreatedb']], "", (($userdata->f[$data->uFields['usuper']]) ? $lang['stryes'] : $lang['strno']), "", (($userdata->f[$data->uFields['ucreatedb']]) ? $lang['stryes'] : $lang['strno']), "", htmlspecialchars($userdata->f[$data->uFields['uexpires']]), "
\n"; } @@ -42,6 +44,51 @@ echo "

{$lang['strchangepassword']}

\n"; } + /** + * Show confirmation of change password and actually change password + */ + function doChangePassword($confirm, $msg = '') { + global $data, $misc; + global $PHP_SELF, $lang, $conf; + + if ($confirm) { + echo "

{$lang['strusers']}: ", htmlspecialchars($_SESSION['webdbUsername']), ": {$lang['strchangepassword']}

\n"; + $misc->printMsg($msg); + + if (!isset($_POST['password'])) $_POST['password'] = ''; + if (!isset($_POST['confirm'])) $_POST['confirm'] = ''; + + + echo "
\n"; + echo $lang['strpassword'], "
\n"; + echo "

\n"; + echo $lang['strconfirm'], "
\n"; + echo "

\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + } + else { + // Check that password is minimum length + if (strlen($_POST['password']) < $conf['min_password_length']) + doChangePassword(true, $lang['strpasswordshort']); + // Check that password matches confirmation password + elseif ($_POST['password'] != $_POST['confirm']) + doChangePassword(true, $lang['strpasswordconfirm']); + else { + $status = $data->changePassword($_SESSION['webdbUsername'], + $_POST['password']); + if ($status == 0) + doAccount($lang['strpasswordchanged']); + else + doAccount($lang['strpasswordchangedbad']); + } + } + } + /** * Function to save after editing a user */ @@ -105,11 +152,13 @@ $userdata = &$data->getUser($_REQUEST['username']); if ($userdata->recordCount() > 0) { + $userdata->f[$data->uFields['usuper']] = $data->phpBool($userdata->f[$data->uFields['usuper']]); + $userdata->f[$data->uFields['ucreatedb']] = $data->phpBool($userdata->f[$data->uFields['ucreatedb']]); echo "\n"; echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "
{$lang['strusername']}{$lang['strsuper']}{$lang['strcreatedb']}{$lang['strexpires']}
", htmlspecialchars($userdata->f[$data->uFields['uname']]), "", $userdata->f[$data->uFields['usuper']], "", $userdata->f[$data->uFields['ucreatedb']], "", (($userdata->f[$data->uFields['usuper']]) ? $lang['stryes'] : $lang['strno']), "", (($userdata->f[$data->uFields['ucreatedb']]) ? $lang['stryes'] : $lang['strno']), "", htmlspecialchars($userdata->f[$data->uFields['uexpires']]), "
\n"; } @@ -241,6 +290,13 @@ $misc->printBody(); switch ($action) { + case 'changepassword': + if (isset($_REQUEST['ok'])) doChangePassword(false); + else doAccount(); + break; + case 'confchangepassword': + doChangePassword(true); + break; case 'account': doAccount(); break; -- 2.39.5