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.
This commit is contained in:
parent
3df40b5bb7
commit
8ec1d2cab3
@ -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())
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<tbody>
|
||||
{section name=donor loop=$DONORS}
|
||||
<tr>
|
||||
<td>{$DONORS[donor].username}</td>
|
||||
<td>{if $DONORS[donor].is_anonymous|default:"0" == 1}anonymous{else}{$DONORS[donor].username}{/if}</td>
|
||||
<td class="center">{$DONORS[donor].donate_percent}</td>
|
||||
<td class="right">{$DONORS[donor].donation|number_format:"2"}</td>
|
||||
</tr>
|
||||
|
||||
@ -11,6 +11,10 @@
|
||||
<tr><td>Payment Address: </td><td><input type="text" name="paymentAddress" value="{nocache}{$smarty.request.paymentAddress|default:$GLOBAL.userdata.coin_address|escape}{nocache}" size="40"></td></tr>
|
||||
<tr><td>Donation %: </td><td><input type="text" name="donatePercent" value="{nocache}{$smarty.request.donatePercent|default:$GLOBAL.userdata.donate_percent|escape}{nocache}" size="4"><font size="1"> [donation amount in percent (example: 0.5)]</font></td></tr>
|
||||
<tr><td>Automatic Payout Threshold: </td><td valign="top"><input type="text" name="payoutThreshold" value="{$smarty.request.payoutThreshold|default:$GLOBAL.userdata.ap_threshold|escape}" size="5" maxlength="5"> <font size="1">[{$GLOBAL.config.ap_threshold.min}-{$GLOBAL.config.ap_threshold.max} {$GLOBAL.config.currency}. Set to '0' for no auto payout]</font></td></tr>
|
||||
<tr><td>Anonymous Account: </td><td>
|
||||
<input type="checkbox" name="is_anonymous" value="1" id="is_anonymous" {if $GLOBAL.userdata.is_anonymous}checked{/if} />
|
||||
<label for="is_anonymous"></label>
|
||||
</td></tr>
|
||||
<tr><td>4 digit PIN: </td><td><input type="password" name="authPin" size="4" maxlength="4"><font size="1"> [The 4 digit PIN you chose when registering]</font></td></tr>
|
||||
</tbody></table>
|
||||
<input type="submit" class="submit long" value="Update Settings"></form>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{if $GLOBAL.userdata.username|default}
|
||||
<h2>Welcome, {$smarty.session.USERDATA.username|escape} <font size='1px'><b>Active Account</b>: <b>{$GLOBAL.fees|escape}%</b> Pool Fee</font> <font size='1px'><i>(You are <a href='{$smarty.server.PHP_SELF}?page=account&action=edit'>donating</a> <b></i>{$GLOBAL.userdata.donate_percent|escape}%</b> <i>of your earnings)</i></font></h2>
|
||||
<h2>Welcome, {$smarty.session.USERDATA.username|escape} <font size='1px'><b>{if $GLOBAL.userdata.is_anonymous}Anonymous{else}Active{/if} Account</b>: <b>{$GLOBAL.fees|escape}%</b> Pool Fee</font> <font size='1px'><i>(You are <a href='{$smarty.server.PHP_SELF}?page=account&action=edit'>donating</a> <b></i>{$GLOBAL.userdata.donate_percent|escape}%</b> <i>of your earnings)</i></font></h2>
|
||||
{else}
|
||||
<h2>Welcome guest, <font size="1px"> please <a href="{$smarty.server.PHP_SELF}?page=register">register</a> to user this pool.</font></h2>
|
||||
{/if}
|
||||
|
||||
@ -57,7 +57,7 @@ target and network difficulty and assuming a zero variance scenario.
|
||||
{else if $BLOCKSFOUND[block].confirmations == -1}
|
||||
<font color="red">Orphan</font>
|
||||
{else}{$GLOBAL.confirmations - $BLOCKSFOUND[block].confirmations} left{/if}</td>
|
||||
<td>{$BLOCKSFOUND[block].finder|default:"unknown"|escape}</td>
|
||||
<td>{if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if}</td>
|
||||
<td class="center">{$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"}</td>
|
||||
<td class="right">{$BLOCKSFOUND[block].difficulty|number_format:"2"}</td>
|
||||
<td class="right">{$BLOCKSFOUND[block].amount|number_format:"2"}</td>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
{section block $BLOCKSFOUND}
|
||||
<tr class="{cycle values="odd,even"}">
|
||||
<td class="center"><a href="{$GLOBAL.blockexplorer}{$BLOCKSFOUND[block].height}" target="_blank">{$BLOCKSFOUND[block].height}</a></td>
|
||||
<td>{$BLOCKSFOUND[block].finder|default:"unknown"|escape}</td>
|
||||
<td>{if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if}</td>
|
||||
<td class="center">{$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"}</td>
|
||||
<td class="right">{$BLOCKSFOUND[block].shares|number_format}</td>
|
||||
</tr>
|
||||
|
||||
@ -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}
|
||||
<tr{if $GLOBAL.userdata.username == $CONTRIBHASHES[contrib].account}{assign var=listed value=1} style="background-color:#99EB99;"{else} class="{cycle values="odd,even"}"{/if}>
|
||||
<td>{$rank++}</td>
|
||||
<td>{$CONTRIBHASHES[contrib].account|escape}</td>
|
||||
<td>{if $CONTRIBHASHES[contrib].is_anonymous|default:"0" == 1}anonymous{else}{$CONTRIBHASHES[contrib].account|escape}{/if}</td>
|
||||
<td class="right">{$CONTRIBHASHES[contrib].hashrate|number_format}</td>
|
||||
<td class="right">{$estday|number_format:"3"}</td>
|
||||
{if $GLOBAL.config.price.currency}<td class="right">{($estday * $GLOBAL.price)|default:"n/a"|number_format:"2"}</td>{/if}
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
{section hashrate $CONTRIBSHARES}
|
||||
<tr{if $GLOBAL.userdata.username == $CONTRIBSHARES[hashrate].account}{assign var=listed value=1} style="background-color:#99EB99;"{else} class="{cycle values="odd,even"}"{/if}>
|
||||
<td>{$rank++}</td>
|
||||
<td>{$CONTRIBSHARES[hashrate].account|escape}</td>
|
||||
<td>{if $CONTRIBHASHES[hashrate].is_anonymous|default:"0" == 1}anonymous{else}{$CONTRIBSHARES[hashrate].account|escape}{/if}</td>
|
||||
<td class="right">{$CONTRIBSHARES[hashrate].shares|number_format}</td>
|
||||
</tr>
|
||||
{/section}
|
||||
|
||||
1
sql/003_accounts_anonymous.sql
Normal file
1
sql/003_accounts_anonymous.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `accounts` ADD `is_anonymous` BOOLEAN NOT NULL DEFAULT FALSE AFTER `is_admin` ;
|
||||
Loading…
Reference in New Issue
Block a user