From bded8227fc8f0c8332d56d0305ec8b225092060c Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 2 Sep 2014 15:40:38 +1000 Subject: [PATCH] php - move repDecode to db.php for most calls --- pool/base.php | 7 ++++--- pool/db.php | 23 +++++++++++++++++------ pool/page_blocks.php | 3 +-- pool/page_payments.php | 3 +-- pool/page_reg.php | 13 ++----------- pool/page_stats.php | 3 +-- pool/page_workers.php | 3 +-- 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pool/base.php b/pool/base.php index 8bfa50ab..ba3ed601 100644 --- a/pool/base.php +++ b/pool/base.php @@ -192,10 +192,11 @@ include_once('db.php'); # function validUserPass($user, $pass) { - $rep = checkpass($user, $pass); - $ans = repDecode($rep); + $rep = checkPass($user, $pass); + if ($rep != null) + $ans = repDecode($rep); usleep(100000); // Max 10x per second - if ($ans['STATUS'] == 'ok') + if ($rep != null && $ans['STATUS'] == 'ok') { $key = 'ckp'.rand(1000000,9999999); $_SESSION['ckpkey'] = $key; diff --git a/pool/db.php b/pool/db.php index 09f3897f..39df49d7 100644 --- a/pool/db.php +++ b/pool/db.php @@ -116,7 +116,7 @@ function homeInfo($user) return $ans; } # -function checkpass($user, $pass) +function checkPass($user, $pass) { $passhash = myhash($pass); $flds = array('username' => $user, 'passwordhash' => $passhash); @@ -124,7 +124,18 @@ function checkpass($user, $pass) $rep = sendsockreply('checkpass', $msg); if (!$rep) dbdown(); - return $rep; + return repDecode($rep); +} +# +function userReg($user, $email, $pass) +{ + $passhash = myhash($pass); + $flds = array('username' => $user, 'emailaddress' => $email, 'passwordhash' => $passhash); + $msg = msgEncode('adduser', 'reg', $flds); + $rep = sendsockreply('adduser', $msg); + if (!$rep) + dbdown(); + return repDecode($rep); } # function getAllUsers() @@ -134,7 +145,7 @@ function getAllUsers() $rep = sendsockreply('getAllUsers', $msg); if (!$rep) dbdown(); - return $rep; + return repDecode($rep); } # function getWorkers($user) @@ -146,7 +157,7 @@ function getWorkers($user) $rep = sendsockreply('getWorkers', $msg); if (!$rep) dbdown(); - return $rep; + return repDecode($rep); } # function getPayments($user) @@ -158,7 +169,7 @@ function getPayments($user) $rep = sendsockreply('getPayments', $msg); if (!$rep) dbdown(); - return $rep; + return repDecode($rep); } # function getBlocks($user) @@ -170,7 +181,7 @@ function getBlocks($user) $rep = sendsockreply('getBlocks', $msg); if (!$rep) dbdown(); - return $rep; + return repDecode($rep); } # ?> diff --git a/pool/page_blocks.php b/pool/page_blocks.php index 0168b8d2..75f98349 100644 --- a/pool/page_blocks.php +++ b/pool/page_blocks.php @@ -4,8 +4,7 @@ function doblocks($data, $user) { $pg = '

Blocks

'; - $rep = getBlocks($user); - $ans = repDecode($rep); + $ans = getBlocks($user); $pg .= "\n"; $pg .= ""; diff --git a/pool/page_payments.php b/pool/page_payments.php index 2fa4c847..2fea9175 100644 --- a/pool/page_payments.php +++ b/pool/page_payments.php @@ -4,8 +4,7 @@ function dopayments($data, $user) { $pg = '

Payments

'; - $rep = getPayments($user); - $ans = repDecode($rep); + $ans = getPayments($user); $pg .= "
\n"; $pg .= ""; diff --git a/pool/page_reg.php b/pool/page_reg.php index e523db6f..abd54fbe 100644 --- a/pool/page_reg.php +++ b/pool/page_reg.php @@ -129,20 +129,11 @@ function show_reg($menu, $name, $u) if ($ok === true) { - $passhash = myhash($pass); - $flds = array('username' => $user, - 'emailaddress' => $mail, - 'passwordhash' => $passhash); - $msg = msgEncode('adduser', 'reg', $flds); - $rep = sendsockreply('show_reg', $msg); - if (!$rep) - dbdown(); - - $ans = repDecode($rep); + $ans = userReg($user, $mail, $pass); if ($ans['STATUS'] == 'ok') gopage($data, 'doreg2', $menu, $name, $u, true, true, false); else - $data['error'] = "Invalid details"; + $data['error'] = "Invalid username, password or email address"; } gopage($data, 'doreg', $menu, $name, $u, true, true, false); diff --git a/pool/page_stats.php b/pool/page_stats.php index fad0f4db..098acba5 100644 --- a/pool/page_stats.php +++ b/pool/page_stats.php @@ -12,8 +12,7 @@ function dostats($data, $user) { $pg = '

Pool Stats

'; - $rep = getAllUsers(); - $ans = repDecode($rep); + $ans = getAllUsers(); $pg .= "
\n"; $pg .= ""; diff --git a/pool/page_workers.php b/pool/page_workers.php index 275b6567..310923f2 100644 --- a/pool/page_workers.php +++ b/pool/page_workers.php @@ -4,8 +4,7 @@ function doworker($data, $user) { $pg = '

Workers

'; - $rep = getWorkers($user); - $ans = repDecode($rep); + $ans = getWorkers($user); $pg .= "
\n"; $pg .= "";