mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fixing multi creation
This commit is contained in:
parent
d72dc4b223
commit
6aced08f09
@ -231,6 +231,34 @@ class AppController extends Controller
|
||||
}
|
||||
*/
|
||||
|
||||
public function addAdminError($controller, $action, $returnTable, $state_user_id) {
|
||||
if(!is_array($returnTable)) {
|
||||
$this->addAdminError('AppController', 'addAdminError', ['state' => 'error', 'msg' => 'returnTable isn\'t array', 'details' => gettype($returnTable)]);
|
||||
return false;
|
||||
}
|
||||
$adminErrorTable = TableRegistry::getTableLocator()->get('AdminErrors');
|
||||
$adminErrorEntity = $adminErrorTable->newEntity();
|
||||
$adminErrorEntity->state_user_id = $state_user_id;
|
||||
$adminErrorEntity->controller = $controller;
|
||||
$adminErrorEntity->action = $action;
|
||||
$adminErrorEntity->state = $returnTable->state;
|
||||
if(isset($returnTable['msg'])) {
|
||||
$adminErrorEntity->msg = $returnTable['msg'];
|
||||
}
|
||||
if(isset($returnTable['details'])) {
|
||||
$adminErrorEntity->details = $returnTable['details'];
|
||||
}
|
||||
if(!$adminErrorTable->save($adminErrorEntity)) {
|
||||
$this->Flash->error(__('Serious error, couldn\'t save to db, please write the admin: ' . $this->getAdminEmailLink()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAdminEmailLink($text) {
|
||||
$serverAdminEmail = Configure::read('ServerAdminEmail');
|
||||
return '<a href="mailto:' . $serverAdminEmail . '">'. $serverAdminEmail . '</a>';
|
||||
}
|
||||
|
||||
public function returnJsonEncoded($json) {
|
||||
$this->autoRender = false;
|
||||
$response = $this->response->withType('application/json');
|
||||
|
||||
@ -20,9 +20,16 @@ class JsonRequestClientComponent extends Component
|
||||
if(!is_numeric($user_balance) || intval($user_balance) < 0) {
|
||||
return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'user_balance invalid'];
|
||||
}
|
||||
if(!$this->is_base64($base64Message)) {
|
||||
if(is_array($base64Message)) {
|
||||
foreach($base64Message as $singleMessage) {
|
||||
if(!$this->is_base64($singleMessage)) {
|
||||
return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'at least one base64Message contain invalid base64 characters'];
|
||||
}
|
||||
}
|
||||
} else if(!$this->is_base64($base64Message)) {
|
||||
return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'base64Message contain invalid base64 characters'];
|
||||
}
|
||||
|
||||
$http = new Client();
|
||||
|
||||
$transactionbody = json_encode([
|
||||
|
||||
@ -3,7 +3,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
//use Cake\Routing\Router;
|
||||
//use Cake\ORM\TableRegistry;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
/**
|
||||
* StateUsers Controller
|
||||
@ -49,8 +49,10 @@ class DashboardController extends AppController
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$this->viewBuilder()->setLayout('frontend');
|
||||
$adminErrorsTable = TableRegistry::getTableLocator()->get('AdminErrors');
|
||||
$adminErrorCount = $adminErrorsTable->find('all')->count();
|
||||
|
||||
|
||||
$this->set('adminErrorCount', $adminErrorCount);
|
||||
$this->set('timeUsed', microtime(true) - $startTime);
|
||||
}
|
||||
|
||||
|
||||
@ -282,40 +282,32 @@ class TransactionCreationsController extends AppController
|
||||
}
|
||||
$creationTransactionCount = count($transactions);
|
||||
if($creationTransactionCount > 0) {
|
||||
$http = new Client();
|
||||
try {
|
||||
$loginServer = Configure::read('LoginServer');
|
||||
$url = $loginServer['host'] . ':' . $loginServer['port'];
|
||||
$session_id = $session->read('session_id');
|
||||
/*
|
||||
* $response = $http->post($url . '/checkTransaction', json_encode([
|
||||
'session_id' => $session_id,
|
||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||
'balance' => $user['balance']
|
||||
]), ['type' => 'json']);
|
||||
*/
|
||||
$transactionbody = json_encode([
|
||||
'session_id' => $session_id,
|
||||
'transaction_base64' => $transactions,
|
||||
'balance' => $user['balance']
|
||||
]);
|
||||
//die($transactionbody);
|
||||
$response = $http->post($url . '/checkTransaction', $transactionbody, ['type' => 'json']);
|
||||
//var_dump($response->getStringBody());
|
||||
try {
|
||||
//$stringBody = $response->getStringBody();
|
||||
//var_dump($stringBody);
|
||||
$json = $response->getJson();
|
||||
} catch(Exception $ex) {
|
||||
$this->Flash->error(__('result isn\'t json ') . $ex->getMessage());
|
||||
$user_balance = 0;
|
||||
if(isset($user['balance'])) {
|
||||
$user_balance = $user['balance'];
|
||||
}
|
||||
// $session_id, $base64Message, $user_balance = 0
|
||||
$requestResult = $this->JsonRequestClient->sendTransaction(
|
||||
$session->read('session_id'),
|
||||
$transactions,
|
||||
$user_balance
|
||||
);
|
||||
if($requestResult['state'] != 'success') {
|
||||
$this->addAdminError('TransactionCreations', 'createMulti', $requestResult, $user['id']);
|
||||
if($requestResult['type'] == 'request error') {
|
||||
$this->Flash->error(__('Error by requesting LoginServer, please try again'));
|
||||
} else {
|
||||
$this->Flash->error(__('Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$json = $requestResult['data'];
|
||||
if($json['state'] != 'success') {
|
||||
if($json['msg'] == 'session not found') {
|
||||
$session->destroy();
|
||||
return $this->redirect(Router::url('/', true) . 'account', 303);
|
||||
//$this->Flash->error(__('session not found, please login again'));
|
||||
} else {
|
||||
$this->Flash->error(__('login server return error: ' . json_encode($json)));
|
||||
$this->addAdminError('TransactionCreations', 'createMulti', $json, $user['id']);
|
||||
$this->Flash->error(__('Login Server Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$pendingTransactionCount = $session->read('Transactions.pending');
|
||||
@ -325,25 +317,17 @@ class TransactionCreationsController extends AppController
|
||||
$pendingTransactionCount += $creationTransactionCount;
|
||||
}
|
||||
$session->write('Transactions.pending', $pendingTransactionCount);
|
||||
echo "pending: " . $pendingTransactionCount;
|
||||
//echo "pending: " . $pendingTransactionCount;
|
||||
if($mode === 'next') {
|
||||
return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303);
|
||||
} else {
|
||||
$this->Flash->success(__('Transaction submitted for review.'));
|
||||
}
|
||||
}
|
||||
|
||||
} catch(\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
$this->Flash->error(__('error http request: ') . $msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -23,4 +23,8 @@ $this->assign('title', __('Willkommen'));
|
||||
['class' => 'grd-nav-bn grd-nav-bn-large']
|
||||
);?>
|
||||
</fieldset>
|
||||
<?= $this->Html->link(
|
||||
__('Fehler') . ' (' . $adminErrorCount . ')',
|
||||
['controller' => 'AdminErrors'], ['class' => 'grd-nav-bn']);
|
||||
?>
|
||||
</div>
|
||||
Loading…
x
Reference in New Issue
Block a user