diff --git a/src/www/ui/user-add.php b/src/www/ui/user-add.php index 98bc962f..d99d92f2 100644 --- a/src/www/ui/user-add.php +++ b/src/www/ui/user-add.php @@ -1,213 +1,205 @@ Name = "user_add"; $this->Title = TITLE_user_add; $this->MenuList = "Admin::Users::Add"; $this->DBaccess = PLUGIN_DB_ADMIN; parent::__construct(); + $this->dbManager = $GLOBALS['container']->get('db.manager'); } /** * \brief Add a user. * * \return NULL on success, string on failure. */ function Add() { global $PG_CONN; if (!$PG_CONN) { DBconnect(); if (!$PG_CONN) { $text = _("NO DB connection!"); echo "
$text\n"; } } /* Get the parameters */ $User = str_replace("'", "''", GetParm('username', PARM_TEXT)); $User = trim($User); $Pass = GetParm('pass1', PARM_TEXT); $Pass2 = GetParm('pass2', PARM_TEXT); $Seed = rand() . rand(); $Hash = sha1($Seed . $Pass); $Desc = str_replace("'", "''", GetParm('description', PARM_TEXT)); $Perm = GetParm('permission', PARM_INTEGER); $Folder = GetParm('folder', PARM_INTEGER); $Email_notify = GetParm('enote', PARM_TEXT); $Email = str_replace("'", "''", GetParm('email', PARM_TEXT)); $agentList = userAgents(); $default_bucketpool_fk = GetParm('default_bucketpool_fk', PARM_INTEGER); - $new_upload_group_fk = GetParm('new_upload_group_fk', PARM_INTEGER); - $new_upload_perm = GetParm('new_upload_perm', PARM_INTEGER); - $uiChoice = GetParm('whichui', PARM_TEXT); /* Make sure username looks valid */ if (empty($User)) { $text = _("Username must be specified. Not added."); return ($text); } /* limit the user name size to 64 characters when creating an account */ if (strlen($User) > 64) { $text = _("Username exceed 64 characters. Not added."); return ($text); } /* Make sure password matches */ if ($Pass != $Pass2) { $text = _("Passwords did not match. Not added."); return ($text); } /* Make sure email looks valid */ $Check = preg_replace("/[^a-zA-Z0-9@_.+-]/", "", $Email); if ($Check != $Email) { $text = _("Invalid email address. Not added."); return ($text); } /* See if the user already exists (better not!) */ - $sql = "SELECT * FROM users WHERE user_name = '$User' LIMIT 1;"; - $result = pg_query($PG_CONN, $sql); - DBCheckResult($result, $sql, __FILE__, __LINE__); - $row = pg_fetch_assoc($result); - pg_free_result($result); + $row = $this->dbManager->getSingleRow("SELECT * FROM users WHERE user_name = $1 LIMIT 1;", + array($User), $stmt = __METHOD__ . ".getUserIfExisting"); if (!empty($row['user_name'])) { $text = _("User already exists. Not added."); return ($text); } /* check email notification, if empty (box not checked), or if no email * specified for the user set to 'n'. */ if(empty($Email_notify)) { $Email_notify = ''; } elseif(empty($Email)) { $Email_notify = ''; } - /* Add the user */ - if($uiChoice != 'simple') - { - $uiChoice = 'original'; - } - - if (empty($new_upload_group_fk)) $new_upload_group_fk = 'NULL'; - if (empty($new_upload_perm)) $new_upload_perm = 'NULL'; - $ErrMsg = add_user($User,$Desc,$Seed,$Hash,$Perm,$Email, $Email_notify,$agentList,$Folder, $default_bucketpool_fk); return ($ErrMsg); } // Add() public function Output() { /* If this is a POST, then process the request. */ $User = GetParm('username', PARM_TEXT); if (!empty($User)) { $rc = $this->Add(); if (empty($rc)) { $text = _("User"); $text1 = _("added"); $this->vars['message'] = "$text $User $text1."; } else { $this->vars['message'] = $rc; } } $V = "