mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add getBalance call to api
This commit is contained in:
parent
91f6e04dc5
commit
74c9aeabc3
@ -14,6 +14,7 @@ use Cake\ORM\TableRegistry;
|
||||
use Cake\Http\Client;
|
||||
use Cake\Core\Configure;
|
||||
|
||||
use Cake\I18n\FrozenTime;
|
||||
|
||||
class AppRequestsController extends AppController
|
||||
{
|
||||
@ -23,7 +24,7 @@ class AppRequestsController extends AppController
|
||||
$this->loadComponent('JsonRequestClient');
|
||||
//$this->loadComponent('JsonRpcRequestClient');
|
||||
//$this->Auth->allow(['add', 'edit']);
|
||||
$this->Auth->allow(['index', 'sendCoins', 'createCoins']);
|
||||
$this->Auth->allow(['index', 'sendCoins', 'createCoins', 'getBalance']);
|
||||
}
|
||||
|
||||
|
||||
@ -265,6 +266,32 @@ class AppRequestsController extends AppController
|
||||
|
||||
}
|
||||
|
||||
public function getBalance($session_id = 0)
|
||||
{
|
||||
|
||||
$login_result = $this->requestLogin($session_id, false);
|
||||
if($login_result !== true) {
|
||||
return $this->returnJson($login_result);
|
||||
}
|
||||
$session = $this->getRequest()->getSession();
|
||||
$user = $session->read('StateUser');
|
||||
$state_balances_table = TableRegistry::getTableLocator()->get('StateBalances');
|
||||
$state_balances_table->updateBalances($user['id']);
|
||||
|
||||
$state_balance = $state_balances_table->find()->where(['state_user_id' => $user['id']])->first();
|
||||
|
||||
if(!$state_balance) {
|
||||
return $this->returnJson(['state' => 'success', 'balance' => 0]);
|
||||
}
|
||||
$now = new FrozenTime();
|
||||
return $this->returnJson([
|
||||
'state' => 'success',
|
||||
'balance' => $state_balance->amount,
|
||||
'decay' => $state_balance->partDecay($now),
|
||||
'decay_date' => $now
|
||||
]);
|
||||
}
|
||||
|
||||
private function acquireAccessToken($session_id)
|
||||
{
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user