From 8ec1d2cab39e7d4f75871a42965c508aef039451 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 12 Jul 2013 10:33:42 +0200 Subject: [PATCH] Adding anonymous account support * Added anonymous flag to accounts table * Added checkbox for anonymous flag in edit account page * Updated user class to support new flag * Updated statistics class to support anonymous and donations * Updated all templates showing usernames to show anonymous instead * Added new SQL `ALTER TABLE` file for upgrading the table Fixes #419 once merged. --- public/include/classes/statistics.class.php | 23 ++++++++++++++----- public/include/classes/transaction.class.php | 1 + public/include/classes/user.class.php | 8 +++---- public/include/pages/account/edit.inc.php | 2 +- .../templates/mmcFE/about/donors/default.tpl | 2 +- .../templates/mmcFE/account/edit/default.tpl | 4 ++++ public/templates/mmcFE/global/userinfo.tpl | 2 +- .../mmcFE/statistics/blocks/default.tpl | 2 +- .../mmcFE/statistics/blocks/small_table.tpl | 2 +- .../statistics/pool/contributors_hashrate.tpl | 2 +- .../statistics/pool/contributors_shares.tpl | 2 +- sql/003_accounts_anonymous.sql | 1 + 12 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 sql/003_accounts_anonymous.sql diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 3e375249..e2d1848a 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -61,7 +61,10 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $limit)) return $data; $stmt = $this->mysqli->prepare(" - SELECT b.*, a.username as finder + SELECT + b.*, + a.username AS finder, + a.is_anonymous AS is_anonymous FROM " . $this->block->getTableName() . " AS b LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id @@ -327,9 +330,13 @@ class Statistics { case 'shares': $stmt = $this->mysqli->prepare(" SELECT - COUNT(id) AS shares, - SUBSTRING_INDEX( username, '.', 1 ) AS account - FROM " . $this->share->getTableName() . " + a.donate_percent AS donate_percent, + a.is_anonymous AS is_anonymous, + COUNT(s.id) AS shares, + SUBSTRING_INDEX( s.username, '.', 1 ) AS account + FROM " . $this->share->getTableName() . " AS s + LEFT JOIN " . $this->user->getTableName() . " AS a + ON SUBSTRING_INDEX( s.username, '.', 1 ) = a.username WHERE our_result = 'Y' GROUP BY account ORDER BY shares DESC @@ -343,14 +350,18 @@ class Statistics { case 'hashes': $stmt = $this->mysqli->prepare(" SELECT - IFNULL(ROUND(COUNT(id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, - SUBSTRING_INDEX( username, '.', 1 ) AS account + a.donate_percent AS donate_percent, + a.is_anonymous AS is_anonymous, + IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, + SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( SELECT id, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' UNION SELECT id, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' ) AS t1 + LEFT JOIN " . $this->user->getTableName() . " AS a + ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username GROUP BY account ORDER BY hashrate DESC LIMIT ?"); if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result()) diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index d01a6d18..30867cc6 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -127,6 +127,7 @@ class Transaction { SELECT SUM(t.amount) AS donation, a.username AS username, + a.is_anonymous AS is_anonymous, a.donate_percent AS donate_percent FROM $this->table AS t LEFT JOIN " . $this->user->getTableName() . " AS a diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php index a363ff58..ac4fabdf 100644 --- a/public/include/classes/user.class.php +++ b/public/include/classes/user.class.php @@ -283,7 +283,7 @@ class User { * @param donat float donation % of income * @return bool **/ - public function updateAccount($userID, $address, $threshold, $donate, $email) { + public function updateAccount($userID, $address, $threshold, $donate, $email, $is_anonymous) { $this->debug->append("STA " . __METHOD__, 4); $bUser = false; @@ -317,8 +317,8 @@ class User { $donate = min(100, max(0, floatval($donate))); // We passed all validation checks so update the account - $stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ? WHERE id = ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param('sddsi', $address, $threshold, $donate, $email, $userID) && $stmt->execute()) + $stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, is_anonymous = ? WHERE id = ?"); + if ($this->checkStmt($stmt) && $stmt->bind_param('sddsii', $address, $threshold, $donate, $email, $is_anonymous, $userID) && $stmt->execute()) return true; // Catchall $this->setErrorMessage('Failed to update your account'); @@ -421,7 +421,7 @@ class User { $this->debug->append("Fetching user information for user id: $userID"); $stmt = $this->mysqli->prepare(" SELECT - id, username, pin, api_key, is_admin, email, + id, username, pin, api_key, is_admin, is_anonymous, email, IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold FROM $this->table WHERE id = ? LIMIT 0,1"); diff --git a/public/include/pages/account/edit.inc.php b/public/include/pages/account/edit.inc.php index 1ced549b..9ab38e49 100644 --- a/public/include/pages/account/edit.inc.php +++ b/public/include/pages/account/edit.inc.php @@ -61,7 +61,7 @@ if ($user->isAuthenticated()) { break; case 'updateAccount': - if ($user->updateAccount($_SESSION['USERDATA']['id'], $_POST['paymentAddress'], $_POST['payoutThreshold'], $_POST['donatePercent'], $_POST['email'])) { + if ($user->updateAccount($_SESSION['USERDATA']['id'], $_POST['paymentAddress'], $_POST['payoutThreshold'], $_POST['donatePercent'], $_POST['email'], $_POST['is_anonymous'])) { $_SESSION['POPUP'][] = array('CONTENT' => 'Account details updated', 'TYPE' => 'success'); } else { $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update your account: ' . $user->getError(), 'TYPE' => 'errormsg'); diff --git a/public/templates/mmcFE/about/donors/default.tpl b/public/templates/mmcFE/about/donors/default.tpl index 2d5efaf3..8d5205ac 100644 --- a/public/templates/mmcFE/about/donors/default.tpl +++ b/public/templates/mmcFE/about/donors/default.tpl @@ -12,7 +12,7 @@ {section name=donor loop=$DONORS} - {$DONORS[donor].username} + {if $DONORS[donor].is_anonymous|default:"0" == 1}anonymous{else}{$DONORS[donor].username}{/if} {$DONORS[donor].donate_percent} {$DONORS[donor].donation|number_format:"2"} diff --git a/public/templates/mmcFE/account/edit/default.tpl b/public/templates/mmcFE/account/edit/default.tpl index fd445286..fcf29c7c 100644 --- a/public/templates/mmcFE/account/edit/default.tpl +++ b/public/templates/mmcFE/account/edit/default.tpl @@ -11,6 +11,10 @@ Payment Address: Donation %: [donation amount in percent (example: 0.5)] Automatic Payout Threshold: [{$GLOBAL.config.ap_threshold.min}-{$GLOBAL.config.ap_threshold.max} {$GLOBAL.config.currency}. Set to '0' for no auto payout] + Anonymous Account: + + + 4 digit PIN: [The 4 digit PIN you chose when registering] diff --git a/public/templates/mmcFE/global/userinfo.tpl b/public/templates/mmcFE/global/userinfo.tpl index d9745394..45e9ad92 100644 --- a/public/templates/mmcFE/global/userinfo.tpl +++ b/public/templates/mmcFE/global/userinfo.tpl @@ -1,5 +1,5 @@ {if $GLOBAL.userdata.username|default} -

Welcome, {$smarty.session.USERDATA.username|escape} Active Account: {$GLOBAL.fees|escape}% Pool Fee (You are donating {$GLOBAL.userdata.donate_percent|escape}% of your earnings)

+

Welcome, {$smarty.session.USERDATA.username|escape} {if $GLOBAL.userdata.is_anonymous}Anonymous{else}Active{/if} Account: {$GLOBAL.fees|escape}% Pool Fee (You are donating {$GLOBAL.userdata.donate_percent|escape}% of your earnings)

{else}

Welcome guest, please register to user this pool.

{/if} diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl index 0856a269..2871cd01 100644 --- a/public/templates/mmcFE/statistics/blocks/default.tpl +++ b/public/templates/mmcFE/statistics/blocks/default.tpl @@ -57,7 +57,7 @@ target and network difficulty and assuming a zero variance scenario. {else if $BLOCKSFOUND[block].confirmations == -1} Orphan {else}{$GLOBAL.confirmations - $BLOCKSFOUND[block].confirmations} left{/if} - {$BLOCKSFOUND[block].finder|default:"unknown"|escape} + {if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if} {$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"} {$BLOCKSFOUND[block].difficulty|number_format:"2"} {$BLOCKSFOUND[block].amount|number_format:"2"} diff --git a/public/templates/mmcFE/statistics/blocks/small_table.tpl b/public/templates/mmcFE/statistics/blocks/small_table.tpl index 2b0f8aac..010b3557 100644 --- a/public/templates/mmcFE/statistics/blocks/small_table.tpl +++ b/public/templates/mmcFE/statistics/blocks/small_table.tpl @@ -14,7 +14,7 @@ {section block $BLOCKSFOUND} {$BLOCKSFOUND[block].height} - {$BLOCKSFOUND[block].finder|default:"unknown"|escape} + {if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if} {$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"} {$BLOCKSFOUND[block].shares|number_format} diff --git a/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl b/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl index b6168c36..a7f3cd9f 100644 --- a/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl +++ b/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl @@ -17,7 +17,7 @@ {math assign="estday" equation="round(reward / ( diff * pow(2,32) / ( hashrate * 1000 ) / 3600 / 24), 3)" diff=$DIFFICULTY reward=$REWARD hashrate=$CONTRIBHASHES[contrib].hashrate} {$rank++} - {$CONTRIBHASHES[contrib].account|escape} + {if $CONTRIBHASHES[contrib].is_anonymous|default:"0" == 1}anonymous{else}{$CONTRIBHASHES[contrib].account|escape}{/if} {$CONTRIBHASHES[contrib].hashrate|number_format} {$estday|number_format:"3"} {if $GLOBAL.config.price.currency}{($estday * $GLOBAL.price)|default:"n/a"|number_format:"2"}{/if} diff --git a/public/templates/mmcFE/statistics/pool/contributors_shares.tpl b/public/templates/mmcFE/statistics/pool/contributors_shares.tpl index 232e76b2..3efb4a8e 100644 --- a/public/templates/mmcFE/statistics/pool/contributors_shares.tpl +++ b/public/templates/mmcFE/statistics/pool/contributors_shares.tpl @@ -14,7 +14,7 @@ {section hashrate $CONTRIBSHARES} {$rank++} - {$CONTRIBSHARES[hashrate].account|escape} + {if $CONTRIBHASHES[hashrate].is_anonymous|default:"0" == 1}anonymous{else}{$CONTRIBSHARES[hashrate].account|escape}{/if} {$CONTRIBSHARES[hashrate].shares|number_format} {/section} diff --git a/sql/003_accounts_anonymous.sql b/sql/003_accounts_anonymous.sql new file mode 100644 index 00000000..167ad5aa --- /dev/null +++ b/sql/003_accounts_anonymous.sql @@ -0,0 +1 @@ +ALTER TABLE `accounts` ADD `is_anonymous` BOOLEAN NOT NULL DEFAULT FALSE AFTER `is_admin` ;