diff --git a/include/classes/coin_address.class.php b/include/classes/coin_address.class.php index e5f108ac..1e9bbb08 100644 --- a/include/classes/coin_address.class.php +++ b/include/classes/coin_address.class.php @@ -51,7 +51,22 @@ class CoinAddress extends Base { return false; } $stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (account_id, currency, coin_address) VALUES (?, ?, ?)"); - if ( $this->checkStmt($stmt) && $stmt->bind_param('sis', $userID, $currency, $address) && $stmt->execute()) { + if ( $this->checkStmt($stmt) && $stmt->bind_param('iss', $userID, $currency, $address) && $stmt->execute()) { + return true; + } + return $this->sqlError(); + } + + /** + * Remove a coin address record for a user + * @param userID int Account ID + * @param currency string Currency short handle, defaults to config option + * @return bool true or false + **/ + public function remove ($userID, $currency=NULL) { + if ($currency === NULL) $currency = $this->config['currency']; + $stmt = $this->mysqli->prepare("DELETE FROM " . $this->getTableName() . " WHERE account_id = ? AND currency = ?"); + if ( $this->checkStmt($stmt) && $stmt->bind_param('is', $userID, $currency) && $stmt->execute()) { return true; } return $this->sqlError(); diff --git a/include/classes/user.class.php b/include/classes/user.class.php index 5e59b853..ec672517 100644 --- a/include/classes/user.class.php +++ b/include/classes/user.class.php @@ -545,8 +545,15 @@ class User extends Base { if ($this->checkStmt($stmt) && $stmt->bind_param('ddssii', $threshold, $donate, $email, $timezone, $is_anonymous, $userID) && $stmt->execute()) { $this->log->log("info", $this->getUserName($userID)." updated their account details"); // Update coin address too - if ($this->coin_address->update($userID, $address)) - return true; + if ($address) { + if ($this->coin_address->update($userID, $address)) { + return true; + } + } else { + if ($this->coin_address->remove($userID, $address)) { + return true; + } + } } // Catchall $this->setErrorMessage('Failed to update your account');