cleaned up getSingle calls, added getCoinAddress method

This commit is contained in:
Sebastian Grewe 2013-05-12 16:56:11 +02:00
parent 47ac213779
commit 3844bbe1ab

View File

@ -27,7 +27,7 @@ class User {
} }
public function getUserName($userID) { public function getUserName($userID) {
return $this->getSingle($userID, 'id', 'username', $this->table); return $this->getSingle($userID, 'username');
} }
public function checkLogin($username, $password) { public function checkLogin($username, $password) {
@ -51,22 +51,23 @@ class User {
return $pin_hash === $row_pin; return $pin_hash === $row_pin;
} }
private function getSingle($userID, $search='id', $field='id', $table='') { private function getSingle($userID, $search='id') {
if ( empty($table) ) { $stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE id = ? LIMIT 1");
$table = $this->table;
}
// Hack for inconsistent field names
$stmt = $this->mysqli->prepare("SELECT $field FROM $table WHERE $search=? LIMIT 1");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param('i', $userID); $stmt->bind_param('i', $userID);
$stmt->execute(); $stmt->execute();
$stmt->bind_result($value); $stmt->bind_result($retval);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
return $value; return $retval;
} }
return false; return false;
} }
public function getCoinAddress($userID) {
return $this->getSingle($userID, 'coin_address');
}
private function updateSingle($userID, $field, $table) { private function updateSingle($userID, $field, $table) {
$stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE userId = ? LIMIT 1"); $stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE userId = ? LIMIT 1");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {