From 69e08b46941eaaeb91e1bb8c3f02df47ef20a745 Mon Sep 17 00:00:00 2001 From: Joe Presbrey Date: Tue, 11 Apr 2006 19:13:02 +0000 Subject: [PATCH] bug fix: signup/db-create for class lockers git-svn-id: svn://presbrey.mit.edu/sql/mitsql@98 a142d4bd-2cfb-0310-9673-cb33a7e74f58 --- batch/create_db.php | 4 ++-- lib/proc.lib.php | 4 +++- lib/security.lib.php | 35 +++++++++++++++++++---------------- login.php | 2 +- test.php | 4 +++- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/batch/create_db.php b/batch/create_db.php index f29b3d7..0f994d9 100755 --- a/batch/create_db.php +++ b/batch/create_db.php @@ -19,7 +19,7 @@ if (substr($i_d,0,strlen($myUsername)+1) == $myUsername.DELIMETER) { } list($msg1, $err1) = proc::newdb($User, $i_d); -if (!empty($err1)) die('-3'); -if (empty($err1)) die('0'); +if (!empty($err1)) die('-3,'.implode(' ',$err1)); +if (empty($err1)) die('0,'.$i_d); ?> diff --git a/lib/proc.lib.php b/lib/proc.lib.php index 27f9d87..f9ebc8d 100644 --- a/lib/proc.lib.php +++ b/lib/proc.lib.php @@ -5,7 +5,8 @@ require_once('mitsql.lib.php'); define('MAXDBS', 20); class proc { - static function newdb(&$User, $i_newdb) { + static function newdb(&$User, &$i_newdb) { + // return through $i_newdb the full name of the created db $msg1 = $err1 = array(); $uname = $User->getUsername(); $uname = str_replace('.','',$uname); @@ -25,6 +26,7 @@ class proc { } else { $msg1[] = 'Database `'.$dbname.'` created.'; } + $i_newdb = $dbname; return array($msg1, $err1); } static function drop(&$User, $i_drop) { diff --git a/lib/security.lib.php b/lib/security.lib.php index 32532bc..2084e53 100644 --- a/lib/security.lib.php +++ b/lib/security.lib.php @@ -337,6 +337,7 @@ function addDB($dbname,$userid) { global $_NEW_DB, $_NEW_DBQUOTA, $_NEW_DBOWNER; DBCreate(sprintf('CREATE DATABASE `%s`', mysql_escape_string($dbname))); + if (mysql_error()) return false; $newdb['Name'] = $dbname; $arr = array_merge($newdb, $_NEW_DB); @@ -358,23 +359,25 @@ function addDB($dbname,$userid) { buildSQLSet($arr), $DBId); DBUpdate($sql); - return $DBId; - } else { - $arr = $_NEW_DBQUOTA; - $arr['DatabaseId'] = $DBId; - $sql = sprintf("INSERT IGNORE INTO DBQuota %s", - buildSQLInsert($arr)); - DBInsert($sql); - - $arr = $_NEW_DBOWNER; - $arr['DatabaseId'] = $DBId; - $arr['UserId'] = $userid; - $sql = sprintf("INSERT IGNORE INTO DBOwner %s", - buildSQLInsert($arr)); - DBInsert($sql); - - return $DBId; } + + DBDelete(sprintf("DELETE FROM DBOwner WHERE DatabaseId = '%s'", mysql_escape_string($DBId))); + DBDelete(sprintf("DELETE FROM DBQuota WHERE DatabaseId = '%s'", mysql_escape_string($DBId))); + + $arr = $_NEW_DBQUOTA; + $arr['DatabaseId'] = $DBId; + $sql = sprintf("INSERT IGNORE INTO DBQuota %s", + buildSQLInsert($arr)); + DBInsert($sql); + + $arr = $_NEW_DBOWNER; + $arr['DatabaseId'] = $DBId; + $arr['UserId'] = $userid; + $sql = sprintf("INSERT IGNORE INTO DBOwner %s", + buildSQLInsert($arr)); + DBInsert($sql); + + return $DBId; } function delDB($dbname) { diff --git a/login.php b/login.php index bacfdb4..57d8e88 100644 --- a/login.php +++ b/login.php @@ -22,7 +22,7 @@ if (isPost() && empty($err)) { } elseif (!$Login->exists()) { $err[] = 'Nonexistant account or invalid password.'; } elseif (!$Login->canLogin()) { - $err[] = 'That account is no longer valid. Please contact the staff.'; + $err[] = 'That account is no longer valid. Please contact the staff (sql@mit.edu).'; } if (empty($err)) { diff --git a/test.php b/test.php index 9423e16..1aab1e4 100755 --- a/test.php +++ b/test.php @@ -20,15 +20,17 @@ function getManagedDBs($owner=null) { return $owners; } -/* +/* //GET MANAGED DBs $g = getManagedDBs(); print_r($g); */ +/* //TEST A LOGIN $l = new Login('6.001'); echo !$l->isEnabled(); echo $l->isValid(); print_r($GLOBALS); +*/ //phpinfo(); -- 2.45.1