From 2fa8a6a91c52dc97312f54c426f4ad4252c4eb42 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Mon, 24 Aug 2026 21:49:59 -0600 Subject: [PATCH] Fixes to get user creation working with docker setup --- src/php/api/Db.php | 4 ++-- src/php/api/Dictionary.php | 6 +++--- src/php/api/User.php | 10 ++++++---- src/php/router.php | 4 ++-- src/structure.sql | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/php/api/Db.php b/src/php/api/Db.php index b753eaa..625c499 100644 --- a/src/php/api/Db.php +++ b/src/php/api/Db.php @@ -5,7 +5,7 @@ class Db { private $dbh; public $last_error_info; function __construct() { - $this->dbh = new PDO('mysql:host=localhost;dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASSWORD); + $this->dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASSWORD); $this->dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $this->last_error_info = null; } @@ -20,7 +20,7 @@ class Db { $this->last_error_info = $stmt->errorInfo(); return false; } - + public function query ($query, $params = array()) { // Run a query that returns results $stmt = $this->dbh->prepare($query); diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index b9205fb..d6bf0ea 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -61,7 +61,7 @@ VALUES ($new_id, ?, ?, ?, ?, ?, ?)"; public function changeCurrent ($user, $dictionary) { $update_query = 'UPDATE users SET current_dictionary=? WHERE id=?'; $update = $this->db->query($update_query, array($dictionary, $user)); - if (trim($this->db->last_error_info[2]) == '') { + if (trim($this->db->last_error_info[2] ?? '') == '') { return $dictionary; } return false; @@ -312,7 +312,7 @@ created_on=VALUES(created_on)'; etymology=VALUES(etymology), related=VALUES(related), principal_parts=VALUES(principal_parts)'; - + $results1 = $this->db->execute($query1, $params1); // if ($results1) { @@ -353,7 +353,7 @@ principal_parts=VALUES(principal_parts)'; $insert_query = trim($insert_query, ', ') . ' ON DUPLICATE KEY UPDATE deleted_on=VALUES(deleted_on)'; $delete_query = trim($delete_query, ', ') . ')'; - + $insert_results = $this->db->execute($insert_query, $insert_params); if ($insert_results) { $delete_results = $this->db->execute($delete_query, $delete_params); diff --git a/src/php/api/User.php b/src/php/api/User.php index 4c84dbb..c2dc7f4 100644 --- a/src/php/api/User.php +++ b/src/php/api/User.php @@ -4,8 +4,10 @@ require_once(realpath(dirname(__FILE__) . '/./Token.php')); require_once(realpath(dirname(__FILE__) . '/./Dictionary.php')); class User { - private $db; - private $token; + private Db $db; + private Token $token; + private Dictionary $dictionary; + function __construct () { $this->db = new Db(); $this->token = new Token(); @@ -276,7 +278,7 @@ VALUES (?, ?, ?, ?, current_timestamp())'; $date, $email, )); - + if ($reset) { $user_data = $this->getUserDataByEmailForPasswordReset($email); if ($user_data) { @@ -317,7 +319,7 @@ VALUES (?, ?, ?, ?, current_timestamp())'; $unhashed_code, )); $results = $stmt->fetchAll(); - + if ($stmt && $results) { return count($results) === 1; } else { diff --git a/src/php/router.php b/src/php/router.php index 0bb9fdc..5fbac2d 100644 --- a/src/php/router.php +++ b/src/php/router.php @@ -156,9 +156,9 @@ switch ($view) { } })(window.onload); "; - + $html = str_replace('{{upup_insert}}', $upup_insert, $html); - + $imported_from_http = ''; if (isset($_POST['oldDictionaryFromHTTP'])) { $imported_from_http = ''; diff --git a/src/structure.sql b/src/structure.sql index e653398..8351c0e 100644 --- a/src/structure.sql +++ b/src/structure.sql @@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS `dictionaries` ( `case_sensitive` tinyint(1) NOT NULL DEFAULT 0, `sort_by_definition` tinyint(1) NOT NULL DEFAULT 0, `theme` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'default', - `custom_css` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'CSS', + `custom_css` text COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'CSS', `is_public` tinyint(1) NOT NULL DEFAULT 0, `last_updated` int(11) DEFAULT NULL, `created_on` int(11) NOT NULL,