From: soranzo Date: Sun, 18 Jan 2004 16:03:01 +0000 (+0000) Subject: Rename user feature for PostgreSQL >= 7.4 X-Git-Tag: REL_3-3-1~35 X-Git-Url: http://git.postgresql.org/gitweb/static/connections.php?a=commitdiff_plain;h=9a32fd4ede7e303cf2dc977c84eee78e860b81a2;p=phppgadmin.git Rename user feature for PostgreSQL >= 7.4 --- diff --git a/HISTORY b/HISTORY index 34a4b388..7943b9d7 100644 --- a/HISTORY +++ b/HISTORY @@ -13,6 +13,7 @@ Features * Integration with the PostgreSQL statistics collector. See table and index performance and usage information. * Display user session defaults for PostgreSQL >= 7.3 +* Rename user feature for PostgreSQL >= 7.4 * Create functions returning arrays and table types Bugs diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index d6a6c5b6..c56e42cd 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres74.php,v 1.22 2004/01/07 16:29:40 soranzo Exp $ + * $Id: Postgres74.php,v 1.23 2004/01/18 16:03:10 soranzo Exp $ */ include_once('./classes/database/Postgres73.php'); @@ -370,6 +370,40 @@ class Postgres74 extends Postgres73 { return $this->execute($sql); } + /** + * Adjusts a user's info and renames the user + * @param $username The username of the user to modify + * @param $password A new password for the user + * @param $createdb boolean Whether or not the user can create databases + * @param $createuser boolean Whether or not the user can create other users + * @param $expiry string Format 'YYYY-MM-DD HH:MM:SS'. '' means never expire. + * @param $newname The new name of the user + * @return 0 success + * @return -1 transaction error + * @return -2 set user attributes error + * @return -3 rename error + */ + function setRenameUser($username, $password, $createdb, $createuser, $expiry, $newname) { + $status = $this->beginTransaction(); + if ($status != 0) return -1; + + $status = $this->setUser($username, $password, $createdb, $createuser, $expiry); + if ($status != 0) { + $this->rollbackTransaction(); + return -2; + } + + if ($username != $newname){ + $status = $this->renameUser($username, $newname); + if ($status != 0) { + $this->rollbackTransaction(); + return -3; + } + } + + return $this->endTransaction(); + } + // Capabilities function hasGrantOption() { return true; } function hasDomainConstraints() { return true; } diff --git a/lang/english.php b/lang/english.php index 57cc09dd..242c5a5f 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.129 2004/01/07 16:29:40 soranzo Exp $ + * $Id: english.php,v 1.130 2004/01/18 16:03:11 soranzo Exp $ */ // Language and character set @@ -195,11 +195,7 @@ $lang['strcreatedb'] = 'Create DB?'; $lang['strexpires'] = 'Expires'; $lang['strsessiondefaults'] = 'Session Defaults'; - $lang['strnewname'] = 'New name'; $lang['strnousers'] = 'No users found.'; - $lang['strrename'] = 'Rename'; - $lang['struserrenamed'] = 'User renamed.'; - $lang['struserrenamedbad'] = 'Failed to rename user.'; $lang['struserupdated'] = 'User updated.'; $lang['struserupdatedbad'] = 'User update failed.'; $lang['strshowallusers'] = 'Show all users'; diff --git a/lang/italian.php b/lang/italian.php index 0d299eef..ca1d0042 100644 --- a/lang/italian.php +++ b/lang/italian.php @@ -4,7 +4,7 @@ * Italian language file, based on the english language file for phpPgAdmin. * Nicola Soranzo [nsoranzo@tiscali.it] * - * $Id: italian.php,v 1.25 2004/01/07 16:29:41 soranzo Exp $ + * $Id: italian.php,v 1.26 2004/01/18 16:03:11 soranzo Exp $ */ // Language and character set - Lingua e set di caratteri @@ -193,11 +193,7 @@ $lang['strcreatedb'] = 'Può creare DB?'; $lang['strexpires'] = 'Scadenza'; $lang['strsessiondefaults'] = 'Defaults della sessione'; - $lang['strnewname'] = 'Nuovo nome'; $lang['strnousers'] = 'Nessun utente trovato'; - $lang['strrename'] = 'Rinomina'; - $lang['struserrenamed'] = 'Utente rinominato.'; - $lang['struserrenamedbad'] = 'Rinomina dell\'utente fallita.'; $lang['struserupdated'] = 'Utente aggiornato.'; $lang['struserupdatedbad'] = 'Aggiornamento utente fallito.'; $lang['strshowallusers'] = 'Mostra tutti gli utenti'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index eb8d0f6f..f43f94ae 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.81 2004/01/07 16:29:41 soranzo Exp $ + * $Id: english.php,v 1.82 2004/01/18 16:03:11 soranzo Exp $ */ // Language and character set @@ -195,11 +195,7 @@ $lang['strcreatedb'] = 'Create DB?'; $lang['strexpires'] = 'Expires'; $lang['strsessiondefaults'] = 'Session Defaults'; - $lang['strnewname'] = 'New name'; $lang['strnousers'] = 'No users found.'; - $lang['strrename'] = 'Rename'; - $lang['struserrenamed'] = 'User renamed.'; - $lang['struserrenamedbad'] = 'Failed to rename user.'; $lang['struserupdated'] = 'User updated.'; $lang['struserupdatedbad'] = 'User update failed.'; $lang['strshowallusers'] = 'Show all users'; diff --git a/lang/recoded/italian.php b/lang/recoded/italian.php index 5a801c69..b3bf433d 100644 --- a/lang/recoded/italian.php +++ b/lang/recoded/italian.php @@ -4,7 +4,7 @@ * Italian language file, based on the english language file for phpPgAdmin. * Nicola Soranzo [nsoranzo@tiscali.it] * - * $Id: italian.php,v 1.20 2004/01/07 16:29:41 soranzo Exp $ + * $Id: italian.php,v 1.21 2004/01/18 16:03:11 soranzo Exp $ */ // Language and character set - Lingua e set di caratteri @@ -193,11 +193,7 @@ $lang['strcreatedb'] = 'Può creare DB?'; $lang['strexpires'] = 'Scadenza'; $lang['strsessiondefaults'] = 'Defaults della sessione'; - $lang['strnewname'] = 'Nuovo nome'; $lang['strnousers'] = 'Nessun utente trovato'; - $lang['strrename'] = 'Rinomina'; - $lang['struserrenamed'] = 'Utente rinominato.'; - $lang['struserrenamedbad'] = 'Rinomina dell\'utente fallita.'; $lang['struserupdated'] = 'Utente aggiornato.'; $lang['struserupdatedbad'] = 'Aggiornamento utente fallito.'; $lang['strshowallusers'] = 'Mostra tutti gli utenti'; diff --git a/users.php b/users.php index 62bfea19..df4910c8 100644 --- a/users.php +++ b/users.php @@ -3,7 +3,7 @@ /** * Manage users in a database cluster * - * $Id: users.php,v 1.22 2004/01/03 19:15:44 soranzo Exp $ + * $Id: users.php,v 1.23 2004/01/18 16:03:07 soranzo Exp $ */ // Include application functions @@ -38,7 +38,7 @@ echo "\n\t", $misc->printVal($userdata->f[$data->uFields['uname']]), "\n"; echo "\t", (($userdata->f[$data->uFields['usuper']]) ? $lang['stryes'] : $lang['strno']), "\n"; echo "\t", (($userdata->f[$data->uFields['ucreatedb']]) ? $lang['stryes'] : $lang['strno']), "\n"; - echo "\t", $misc->printVal($userdata->f[$data->uFields['uexpires']]), "\n"; + echo "\t", ($userdata->f[$data->uFields['uexpires']] == 'infinity' ? '' : $misc->printVal($userdata->f[$data->uFields['uexpires']])), "\n"; if ($data->hasUserSessionDefaults()) echo "\t", $misc->printVal($userdata->f[$data->uFields['udefaults']]), "\n"; echo "\n\n"; } @@ -106,20 +106,22 @@ $userdata = &$data->getUser($_REQUEST['username']); if ($userdata->recordCount() > 0) { + $canRename = $data->hasUserRename() && ($_REQUEST['username'] != $_SESSION['webdbUsername']); $userdata->f[$data->uFields['usuper']] = $data->phpBool($userdata->f[$data->uFields['usuper']]); $userdata->f[$data->uFields['ucreatedb']] = $data->phpBool($userdata->f[$data->uFields['ucreatedb']]); if (!isset($_POST['formExpires'])){ + if ($canRename) $_POST['newname'] = $userdata->f[$data->uFields['uname']]; if ($userdata->f[$data->uFields['usuper']]) $_POST['formSuper'] = ''; if ($userdata->f[$data->uFields['ucreatedb']]) $_POST['formCreateDB'] = ''; - $_POST['formExpires'] = $userdata->f[$data->uFields['uexpires']]; + $_POST['formExpires'] = $userdata->f[$data->uFields['uexpires']] == 'infinity' ? '' : $userdata->f[$data->uFields['uexpires']]; $_POST['formPassword'] = ''; } echo "
\n"; echo "\n"; echo "\t\n\t\t\n"; - echo "\t\t\n\t\n"; + echo "\t\t\n\t\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; @@ -148,11 +150,14 @@ function doSaveEdit() { global $data, $lang; - // Check password - if ($_POST['formPassword'] != $_POST['formConfirm']) + // Check name and password + if (isset($_POST['newname']) && $_POST['newname'] == '') + doEdit($lang['struserneedsname']); + else if ($_POST['formPassword'] != $_POST['formConfirm']) doEdit($lang['strpasswordconfirm']); - else { - $status = $data->setUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires']); + else { + if (isset($_POST['newname'])) $status = $data->setRenameUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires'], $_POST['newname']); + else $status = $data->setUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires']); if ($status == 0) doDefault($lang['struserupdated']); else @@ -273,7 +278,7 @@ echo "\n\t\n"; echo "\t\n"; echo "\t\n"; - echo "\t\n"; + echo "\t\n"; if ($data->hasUserSessionDefaults()) echo "\t\n"; echo "\t\n"; @@ -320,7 +325,7 @@ break; case 'confirm_drop': doDrop(true); - break; + break; case 'save_edit': if (isset($_REQUEST['cancel'])) doDefault(); else doSaveEdit();
{$lang['strusername']}", $misc->printVal($userdata->f[$data->uFields['uname']]), "
", ($canRename ? "" : $misc->printVal($userdata->f[$data->uFields['uname']])), "
{$lang['strsuper']}
", $misc->printVal($users->f[$data->uFields['uname']]), "", ($users->f[$data->uFields['usuper']]) ? $lang['stryes'] : $lang['strno'], "", ($users->f[$data->uFields['ucreatedb']]) ? $lang['stryes'] : $lang['strno'], "", $misc->printVal($users->f[$data->uFields['uexpires']]), "", ($users->f[$data->uFields['uexpires']] == 'infinity' ? '' : $misc->printVal($users->f[$data->uFields['uexpires']])), "", $misc->printVal($users->f[$data->uFields['udefaults']]), "f[$data->uFields['uname']]), "\">{$lang['stralter']}