updated account template and user class to work with simplified accounts table

This commit is contained in:
Sebastian Grewe 2013-05-11 20:16:32 +02:00
parent 47b3816d27
commit 9dcdc91a7f
3 changed files with 19 additions and 28 deletions

View File

@ -122,26 +122,17 @@ class User {
public function updateAccount($userID, $address, $threshold, $donate) {
$bUser = false;
$bAccount = false;
$threshold = min(250, max(0, floatval($threshold)));
if ($threshold < 1) $threshold = 0.0;
$donate = min(100, max(0, floatval($donate)));
$stmt = $this->mysqli->prepare("UPDATE $this->tableAccountBalance SET sendAddress = ?, threshold = ? WHERE userId = ?");
$stmt->bind_param('ssi', $address, $threshold, $userID);
$stmt->execute();
if ( $stmt->errno == 0 ) {
$bAccount = true;
}
$stmt->close();
$stmt = $this->mysqli->prepare("UPDATE $this->table SET donate_percent = ? WHERE id = ?");
$stmt->bind_param('di', $donate, $userID);
$stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ? WHERE id = ?");
$stmt->bind_param('sddi', $address, $threshold, $donate, $userID);
$stmt->execute();
if ( $stmt->errno == 0 ) {
$bUser = true;
$stmt->close();
return true;
}
$stmt->close();
if ($bAccount && $bUser) return true;
return false;
}
// set/get methods
@ -152,7 +143,7 @@ class User {
return $this->getSingle($userID, 'userId', 'balance', $this->tableAccountBalance);
}
public function getLtcAddress($userID) {
return $this->getSingle($userID, 'userId', 'sendAddress', $this->tableAccountBalance);
return $this->getSingle($userID, 'id', 'coin_address', $this->table);
}
public function getUserName($userID) {
return $this->getSingle($userID, 'id', 'username', $this->table);
@ -201,18 +192,19 @@ class User {
$this->debug->append("Fetching user information for user id: $userID");
$stmt = $this->mysqli->prepare("
SELECT
u.id, u.username, u.pin, u.pass, u.admin, u.share_count, u.stale_share_count, u.shares_this_round, u.hashrate, u.api_key,
IFNULL(u.donate_percent, '0') as donate_percent, IFNULL(u.round_estimate, '0') as round_estimate, a.sendAddress, a.threshold,
a.balance
FROM $this->table as u LEFT JOIN $this->tableAccountBalance as a
ON u.id = a.userId
WHERE u.id=? LIMIT 0,1");
id, username, pin, pass, admin,
IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold
FROM $this->table
WHERE id = ? LIMIT 0,1");
if ($this->checkStmt($stmt)) {
$stmt->bind_param('i', $userID);
$stmt->execute();
if (!$stmt->execute()) {
$this->debug->append('Failed to execute statement');
return false;
}
$result = $stmt->get_result();
$stmt->close();
return $result->fetch_array();
return $result->fetch_assoc();
}
$this->debug->append("Failed to fetch user information for $userID");
return false;

View File

@ -56,7 +56,7 @@ if ( ! $user->checkPin($_SESSION['USERDATA']['id'], $_POST['authPin']) && $_POST
if ($user->updatePassword($_SESSION['USERDATA']['id'], $_POST['currentPassword'], $_POST['newPassword'], $_POST['newPassword2'])) {
$_SESSION['POPUP'][] = array('CONTENT' => 'Password updated', 'TYPE' => 'success');
} else {
$_SESSION['POPUP'][] = array('CONTENT' => $user->error, 'TYPE' => 'errormsg');
$_SESSION['POPUP'][] = array('CONTENT' => $user->getError(), 'TYPE' => 'errormsg');
}
break;
}

View File

@ -6,10 +6,9 @@
<table>
<tbody><tr><td>Username: </td><td>{$GLOBAL.userdata.username}</td></tr>
<tr><td>User Id: </td><td>{$GLOBAL.userdata.id}</td></tr>
<tr><td><a href="api?api_key={$GLOBAL.userdata.api_key|escape}" style="color: blue" target="_blank">API</a> Key: </td><td><h6><font size="1">{$GLOBAL.userdata.api_key|escape}</font></h6></td></tr>
<tr><td>Payment Address: </td><td><input type="text" name="paymentAddress" value="{$GLOBAL.userdata.sendAddress|escape}" size="40"></td></tr>
<tr><td>Donation %: </td><td><input type="text" name="donatePercent" value="{$GLOBAL.userdata.donate_percent|escape}" 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="{$GLOBAL.userdata.threshold|escape}" size="5" maxlength="5"> <font size="1">[1-250 LTC. Set to '0' for no auto payout]</font></td></tr>
<tr><td>Payment Address: </td><td><input type="text" name="paymentAddress" value="{$smarty.request.paymentAddress|default:$GLOBAL.userdata.coin_address|escape}" size="40"></td></tr>
<tr><td>Donation %: </td><td><input type="text" name="donatePercent" value="{$smarty.request.donatePercent|default:$GLOBAL.userdata.donate_percent|escape}" 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">[1-250 LTC. Set to '0' for no auto payout]</font></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>
@ -23,7 +22,7 @@
<input type="hidden" name="do" value="cashOut">
<table>
<tbody><tr><td>Account Balance: &nbsp;&nbsp;&nbsp;</td><td>{$GLOBAL.userdata.balance|escape} LTC</td></tr>
<tr><td>Payout to: </td><td><h6>{$GLOBAL.userdata.sendAddress|escape}</h6></td></tr>
<tr><td>Payout to: </td><td><h6>{$GLOBAL.userdata.coin_address|escape}</h6></td></tr>
<tr><td>4 digit PIN: </td><td><input type="password" name="authPin" size="4" maxlength="4"></td></tr>
</tbody></table>
<input type="submit" class="submit mid" value="Cash Out"></form>