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) {
|
public function returnJsonEncoded($json) {
|
||||||
$this->autoRender = false;
|
$this->autoRender = false;
|
||||||
$response = $this->response->withType('application/json');
|
$response = $this->response->withType('application/json');
|
||||||
|
|||||||
@ -20,9 +20,16 @@ class JsonRequestClientComponent extends Component
|
|||||||
if(!is_numeric($user_balance) || intval($user_balance) < 0) {
|
if(!is_numeric($user_balance) || intval($user_balance) < 0) {
|
||||||
return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'user_balance invalid'];
|
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'];
|
return ['state' => 'error', 'type' => 'parameter error', 'msg' => 'base64Message contain invalid base64 characters'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$http = new Client();
|
$http = new Client();
|
||||||
|
|
||||||
$transactionbody = json_encode([
|
$transactionbody = json_encode([
|
||||||
|
|||||||
@ -3,7 +3,7 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use App\Controller\AppController;
|
use App\Controller\AppController;
|
||||||
//use Cake\Routing\Router;
|
//use Cake\Routing\Router;
|
||||||
//use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StateUsers Controller
|
* StateUsers Controller
|
||||||
@ -49,8 +49,10 @@ class DashboardController extends AppController
|
|||||||
{
|
{
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
$this->viewBuilder()->setLayout('frontend');
|
$this->viewBuilder()->setLayout('frontend');
|
||||||
|
$adminErrorsTable = TableRegistry::getTableLocator()->get('AdminErrors');
|
||||||
|
$adminErrorCount = $adminErrorsTable->find('all')->count();
|
||||||
|
|
||||||
|
$this->set('adminErrorCount', $adminErrorCount);
|
||||||
$this->set('timeUsed', microtime(true) - $startTime);
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -282,40 +282,32 @@ class TransactionCreationsController extends AppController
|
|||||||
}
|
}
|
||||||
$creationTransactionCount = count($transactions);
|
$creationTransactionCount = count($transactions);
|
||||||
if($creationTransactionCount > 0) {
|
if($creationTransactionCount > 0) {
|
||||||
$http = new Client();
|
$user_balance = 0;
|
||||||
try {
|
if(isset($user['balance'])) {
|
||||||
$loginServer = Configure::read('LoginServer');
|
$user_balance = $user['balance'];
|
||||||
$url = $loginServer['host'] . ':' . $loginServer['port'];
|
}
|
||||||
$session_id = $session->read('session_id');
|
// $session_id, $base64Message, $user_balance = 0
|
||||||
/*
|
$requestResult = $this->JsonRequestClient->sendTransaction(
|
||||||
* $response = $http->post($url . '/checkTransaction', json_encode([
|
$session->read('session_id'),
|
||||||
'session_id' => $session_id,
|
$transactions,
|
||||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
$user_balance
|
||||||
'balance' => $user['balance']
|
);
|
||||||
]), ['type' => 'json']);
|
if($requestResult['state'] != 'success') {
|
||||||
*/
|
$this->addAdminError('TransactionCreations', 'createMulti', $requestResult, $user['id']);
|
||||||
$transactionbody = json_encode([
|
if($requestResult['type'] == 'request error') {
|
||||||
'session_id' => $session_id,
|
$this->Flash->error(__('Error by requesting LoginServer, please try again'));
|
||||||
'transaction_base64' => $transactions,
|
} else {
|
||||||
'balance' => $user['balance']
|
$this->Flash->error(__('Error, please wait for the admin to fix it'));
|
||||||
]);
|
|
||||||
//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());
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$json = $requestResult['data'];
|
||||||
if($json['state'] != 'success') {
|
if($json['state'] != 'success') {
|
||||||
if($json['msg'] == 'session not found') {
|
if($json['msg'] == 'session not found') {
|
||||||
$session->destroy();
|
$session->destroy();
|
||||||
return $this->redirect(Router::url('/', true) . 'account', 303);
|
return $this->redirect(Router::url('/', true) . 'account', 303);
|
||||||
//$this->Flash->error(__('session not found, please login again'));
|
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
$pendingTransactionCount = $session->read('Transactions.pending');
|
$pendingTransactionCount = $session->read('Transactions.pending');
|
||||||
@ -325,25 +317,17 @@ class TransactionCreationsController extends AppController
|
|||||||
$pendingTransactionCount += $creationTransactionCount;
|
$pendingTransactionCount += $creationTransactionCount;
|
||||||
}
|
}
|
||||||
$session->write('Transactions.pending', $pendingTransactionCount);
|
$session->write('Transactions.pending', $pendingTransactionCount);
|
||||||
echo "pending: " . $pendingTransactionCount;
|
//echo "pending: " . $pendingTransactionCount;
|
||||||
if($mode === 'next') {
|
if($mode === 'next') {
|
||||||
return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303);
|
return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303);
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->success(__('Transaction submitted for review.'));
|
$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']
|
['class' => 'grd-nav-bn grd-nav-bn-large']
|
||||||
);?>
|
);?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<?= $this->Html->link(
|
||||||
|
__('Fehler') . ' (' . $adminErrorCount . ')',
|
||||||
|
['controller' => 'AdminErrors'], ['class' => 'grd-nav-bn']);
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
Loading…
x
Reference in New Issue
Block a user