diff --git a/src/Controller/ElopageBuysController.php b/src/Controller/ElopageBuysController.php new file mode 100644 index 000000000..725700cd8 --- /dev/null +++ b/src/Controller/ElopageBuysController.php @@ -0,0 +1,119 @@ +paginate = [ + 'contain' => ['ElopageUsers', 'AffiliatePrograms', 'Publishers', 'Orders', 'Products'], + ]; + $elopageBuys = $this->paginate($this->ElopageBuys); + + $this->set(compact('elopageBuys')); + } + + /** + * View method + * + * @param string|null $id Elopage Buy id. + * @return \Cake\Http\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $elopageBuy = $this->ElopageBuys->get($id, [ + 'contain' => ['ElopageUsers', 'AffiliatePrograms', 'Publishers', 'Orders', 'Products'], + ]); + + $this->set('elopageBuy', $elopageBuy); + } + + /** + * Add method + * + * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. + */ + public function add() + { + $elopageBuy = $this->ElopageBuys->newEntity(); + if ($this->request->is('post')) { + $elopageBuy = $this->ElopageBuys->patchEntity($elopageBuy, $this->request->getData()); + if ($this->ElopageBuys->save($elopageBuy)) { + $this->Flash->success(__('The elopage buy has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The elopage buy could not be saved. Please, try again.')); + } + $elopageUsers = $this->ElopageBuys->ElopageUsers->find('list', ['limit' => 200]); + $affiliatePrograms = $this->ElopageBuys->AffiliatePrograms->find('list', ['limit' => 200]); + $publishers = $this->ElopageBuys->Publishers->find('list', ['limit' => 200]); + $orders = $this->ElopageBuys->Orders->find('list', ['limit' => 200]); + $products = $this->ElopageBuys->Products->find('list', ['limit' => 200]); + $this->set(compact('elopageBuy', 'elopageUsers', 'affiliatePrograms', 'publishers', 'orders', 'products')); + } + + /** + * Edit method + * + * @param string|null $id Elopage Buy id. + * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function edit($id = null) + { + $elopageBuy = $this->ElopageBuys->get($id, [ + 'contain' => [], + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $elopageBuy = $this->ElopageBuys->patchEntity($elopageBuy, $this->request->getData()); + if ($this->ElopageBuys->save($elopageBuy)) { + $this->Flash->success(__('The elopage buy has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The elopage buy could not be saved. Please, try again.')); + } + $elopageUsers = $this->ElopageBuys->ElopageUsers->find('list', ['limit' => 200]); + $affiliatePrograms = $this->ElopageBuys->AffiliatePrograms->find('list', ['limit' => 200]); + $publishers = $this->ElopageBuys->Publishers->find('list', ['limit' => 200]); + $orders = $this->ElopageBuys->Orders->find('list', ['limit' => 200]); + $products = $this->ElopageBuys->Products->find('list', ['limit' => 200]); + $this->set(compact('elopageBuy', 'elopageUsers', 'affiliatePrograms', 'publishers', 'orders', 'products')); + } + + /** + * Delete method + * + * @param string|null $id Elopage Buy id. + * @return \Cake\Http\Response|null Redirects to index. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function delete($id = null) + { + $this->request->allowMethod(['post', 'delete']); + $elopageBuy = $this->ElopageBuys->get($id); + if ($this->ElopageBuys->delete($elopageBuy)) { + $this->Flash->success(__('The elopage buy has been deleted.')); + } else { + $this->Flash->error(__('The elopage buy could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } +} diff --git a/src/Controller/TransactionsController.php b/src/Controller/TransactionsController.php index f2c049403..afaf552f3 100644 --- a/src/Controller/TransactionsController.php +++ b/src/Controller/TransactionsController.php @@ -166,17 +166,23 @@ class TransactionsController extends AppController echo "exception: "; var_dump($e); } - $transactionBase64 = base64_encode($transaction->serializeToString()); - //echo "base64:
$transactionBase64
"; - - $result = $this->JsonRpcRequestClient->request('puttransaction', [ - 'group' => 'd502c4254defe1842d71c484dc35f56983ce938e3c22058795c7520b62ab9123', - 'transaction' => $transactionBase64 - ]); - - $timeUsed = microtime(true) - $startTime; - $result['timeUsed'] = $timeUsed; - return $this->returnJson($result); + if(is_array($transaction)) { + $timeUsed = microtime(true) - $startTime; + $transaction['timeUsed'] = $timeUsed; + return $this->returnJson($transaction); + } else { + $transactionBase64 = base64_encode($transaction->serializeToString()); + //echo "base64:
$transactionBase64
"; + + $result = $this->JsonRpcRequestClient->request('puttransaction', [ + 'group' => 'd502c4254defe1842d71c484dc35f56983ce938e3c22058795c7520b62ab9123', + 'transaction' => $transactionBase64 + ]); + + $timeUsed = microtime(true) - $startTime; + $result['timeUsed'] = $timeUsed; + return $this->returnJson($result); + } //return $this->returnJson(['state' => 'success', 'timeUsed' => $timeUsed]); } $timeUsed = microtime(true) - $startTime; diff --git a/src/Model/Entity/ElopageBuy.php b/src/Model/Entity/ElopageBuy.php new file mode 100644 index 000000000..eca2f760b --- /dev/null +++ b/src/Model/Entity/ElopageBuy.php @@ -0,0 +1,57 @@ + true, + 'affiliate_program_id' => true, + 'publisher_id' => true, + 'order_id' => true, + 'product_id' => true, + 'product_price' => true, + 'payer_email' => true, + 'publisher_email' => true, + 'payed' => true, + 'success_date' => true, + 'event' => true, + 'elopage_user' => true, + 'affiliate_program' => true, + 'publisher' => true, + 'order' => true, + 'product' => true, + ]; +} diff --git a/src/Model/Table/ElopageBuysTable.php b/src/Model/Table/ElopageBuysTable.php new file mode 100644 index 000000000..065bb636f --- /dev/null +++ b/src/Model/Table/ElopageBuysTable.php @@ -0,0 +1,140 @@ +setTable('elopage_buys'); + $this->setDisplayField('id'); + $this->setPrimaryKey('id'); + + $this->belongsTo('ElopageUsers', [ + 'foreignKey' => 'elopage_user_id', + 'joinType' => 'INNER', + ]); + $this->belongsTo('AffiliatePrograms', [ + 'foreignKey' => 'affiliate_program_id', + 'joinType' => 'INNER', + ]); + $this->belongsTo('Publishers', [ + 'foreignKey' => 'publisher_id', + 'joinType' => 'INNER', + ]); + $this->belongsTo('Orders', [ + 'foreignKey' => 'order_id', + 'joinType' => 'INNER', + ]); + $this->belongsTo('Products', [ + 'foreignKey' => 'product_id', + 'joinType' => 'INNER', + ]); + } + + /** + * Default validation rules. + * + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator + */ + public function validationDefault(Validator $validator) + { + $validator + ->integer('id') + ->allowEmptyString('id', null, 'create'); + + $validator + ->integer('product_price') + ->requirePresence('product_price', 'create') + ->notEmptyString('product_price'); + + $validator + ->scalar('payer_email') + ->maxLength('payer_email', 255) + ->requirePresence('payer_email', 'create') + ->notEmptyString('payer_email'); + + $validator + ->scalar('publisher_email') + ->maxLength('publisher_email', 255) + ->requirePresence('publisher_email', 'create') + ->notEmptyString('publisher_email'); + + $validator + ->boolean('payed') + ->requirePresence('payed', 'create') + ->notEmptyString('payed'); + + $validator + ->dateTime('success_date') + ->requirePresence('success_date', 'create') + ->notEmptyDateTime('success_date'); + + $validator + ->scalar('event') + ->maxLength('event', 255) + ->requirePresence('event', 'create') + ->notEmptyString('event'); + + return $validator; + } + + /** + * Returns a rules checker object that will be used for validating + * application integrity. + * + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker + */ + public function buildRules(RulesChecker $rules) + { + $rules->add($rules->existsIn(['elopage_user_id'], 'ElopageUsers')); + $rules->add($rules->existsIn(['affiliate_program_id'], 'AffiliatePrograms')); + $rules->add($rules->existsIn(['publisher_id'], 'Publishers')); + $rules->add($rules->existsIn(['order_id'], 'Orders')); + $rules->add($rules->existsIn(['product_id'], 'Products')); + + return $rules; + } + + /** + * Returns the database connection name to use by default. + * + * @return string + */ + public static function defaultConnectionName() + { + return 'loginServer'; + } +} diff --git a/src/Model/Transactions/Transaction.php b/src/Model/Transactions/Transaction.php index 7312712f6..7be390c85 100644 --- a/src/Model/Transactions/Transaction.php +++ b/src/Model/Transactions/Transaction.php @@ -97,6 +97,7 @@ class Transaction extends TransactionBase { //echo 'sig Pair: '; var_dump($sigPair); echo "
"; $pubkey = $sigPair->getPubKey(); $signature = $sigPair->getEd25519(); + echo "verify bodybytes:
" . bin2hex($bodyBytes) . '
'; if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) { $this->addError('Transaction::validate', 'signature for key ' . bin2hex($pubkey) . ' isn\'t valid ' ); return false; @@ -192,7 +193,50 @@ class Transaction extends TransactionBase { if(is_array($body)) { return ['state' => 'error', 'msg' => 'error creating body transaction', 'details' => $body]; } - $protoTransaction->setBodyBytes($body->serializeToString()); + + // validate signatures + $sigPairs = $sigMap->getProto()->getSigPair(); + + if(!$sigPairs || count($sigPairs) < 1) { + return ['state' => 'error', 'msg' => 'error no signatures found']; + } + + //echo "verify bodybytes:
" . bin2hex($bodyBytes) . '
'; + $created = new \Model\Messages\Gradido\TimestampSeconds(); + $created->setSeconds($recevied->getSeconds()); + $body->setCreated($created); + $bodyBytes = $body->serializeToString(); + $createTrys = 0; + $createRight = false; + // check signature(s) and + // try to get created field of TransactionBody right, because it wasn't saved + foreach($sigPairs as $sigPair) { + //echo 'sig Pair: '; var_dump($sigPair); echo "
"; + $pubkey = $sigPair->getPubKey(); + $signature = $sigPair->getEd25519(); + if(!$createRight) { + while($createTrys < 500) { + if(\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) { + $createRight = true; + break; + } else { + $createTrys++; + $created->setSeconds($created->getSeconds() - 1); + //$body->setCreated($created); + $bodyBytes = $body->serializeToString(); + } + } + } + + if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) { + return ['state' => 'error', 'msg' => 'signature for key ' . bin2hex($pubkey) . ' isn\'t valid ']; + } + } + + $protoTransaction->setBodyBytes($bodyBytes); + + + return $protoTransaction; } diff --git a/src/Model/Transactions/TransactionBody.php b/src/Model/Transactions/TransactionBody.php index 1d14a4c26..331e10fce 100644 --- a/src/Model/Transactions/TransactionBody.php +++ b/src/Model/Transactions/TransactionBody.php @@ -155,6 +155,9 @@ class TransactionBody extends TransactionBase { { $protoBody = new \Model\Messages\Gradido\TransactionBody(); $protoBody->setMemo($memo); + + //$created->setSeconds($var); + //$protoBody->setCreated($created); if(count($transaction->transaction_creations) == 1) { //echo "is creation
"; $protoBody->setCreation(TransactionCreation::fromEntity($transaction->transaction_creations[0])->getProto()); diff --git a/src/Template/ElopageBuys/add.ctp b/src/Template/ElopageBuys/add.ctp new file mode 100644 index 000000000..2bea72966 --- /dev/null +++ b/src/Template/ElopageBuys/add.ctp @@ -0,0 +1,33 @@ + + +
+ Form->create($elopageBuy) ?> +
+ + Form->control('elopage_user_id'); + echo $this->Form->control('affiliate_program_id'); + echo $this->Form->control('publisher_id'); + echo $this->Form->control('order_id'); + echo $this->Form->control('product_id'); + echo $this->Form->control('product_price'); + echo $this->Form->control('payer_email'); + echo $this->Form->control('publisher_email'); + echo $this->Form->control('payed'); + echo $this->Form->control('success_date'); + echo $this->Form->control('event'); + ?> +
+ Form->button(__('Submit')) ?> + Form->end() ?> +
diff --git a/src/Template/ElopageBuys/edit.ctp b/src/Template/ElopageBuys/edit.ctp new file mode 100644 index 000000000..0629c8c6e --- /dev/null +++ b/src/Template/ElopageBuys/edit.ctp @@ -0,0 +1,39 @@ + + +
+ Form->create($elopageBuy) ?> +
+ + Form->control('elopage_user_id'); + echo $this->Form->control('affiliate_program_id'); + echo $this->Form->control('publisher_id'); + echo $this->Form->control('order_id'); + echo $this->Form->control('product_id'); + echo $this->Form->control('product_price'); + echo $this->Form->control('payer_email'); + echo $this->Form->control('publisher_email'); + echo $this->Form->control('payed'); + echo $this->Form->control('success_date'); + echo $this->Form->control('event'); + ?> +
+ Form->button(__('Submit')) ?> + Form->end() ?> +
diff --git a/src/Template/ElopageBuys/index.ctp b/src/Template/ElopageBuys/index.ctp new file mode 100644 index 000000000..a76d1fb01 --- /dev/null +++ b/src/Template/ElopageBuys/index.ctp @@ -0,0 +1,67 @@ + + +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Paginator->sort('id') ?>Paginator->sort('elopage_user_id') ?>Paginator->sort('affiliate_program_id') ?>Paginator->sort('publisher_id') ?>Paginator->sort('order_id') ?>Paginator->sort('product_id') ?>Paginator->sort('product_price') ?>Paginator->sort('payer_email') ?>Paginator->sort('publisher_email') ?>Paginator->sort('payed') ?>Paginator->sort('success_date') ?>Paginator->sort('event') ?>
Number->format($elopageBuy->id) ?>Number->format($elopageBuy->elopage_user_id) ?>Number->format($elopageBuy->affiliate_program_id) ?>Number->format($elopageBuy->publisher_id) ?>Number->format($elopageBuy->order_id) ?>Number->format($elopageBuy->product_id) ?>Number->format($elopageBuy->product_price) ?>payer_email) ?>publisher_email) ?>payed) ?>success_date) ?>event) ?> + Html->link(__('View'), ['action' => 'view', $elopageBuy->id]) ?> + Html->link(__('Edit'), ['action' => 'edit', $elopageBuy->id]) ?> + Form->postLink(__('Delete'), ['action' => 'delete', $elopageBuy->id], ['confirm' => __('Are you sure you want to delete # {0}?', $elopageBuy->id)]) ?> +
+
+ +

Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?>

+
+
diff --git a/src/Template/ElopageBuys/view.ctp b/src/Template/ElopageBuys/view.ctp new file mode 100644 index 000000000..a81c68996 --- /dev/null +++ b/src/Template/ElopageBuys/view.ctp @@ -0,0 +1,68 @@ + + +
+

id) ?>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
payer_email) ?>
publisher_email) ?>
event) ?>
Number->format($elopageBuy->id) ?>
Number->format($elopageBuy->elopage_user_id) ?>
Number->format($elopageBuy->affiliate_program_id) ?>
Number->format($elopageBuy->publisher_id) ?>
Number->format($elopageBuy->order_id) ?>
Number->format($elopageBuy->product_id) ?>
Number->format($elopageBuy->product_price) ?>
success_date) ?>
payed ? __('Yes') : __('No'); ?>
+
diff --git a/src/Template/Transactions/send_to_node.ctp b/src/Template/Transactions/send_to_node.ctp index de6e82c76..a79a12248 100644 --- a/src/Template/Transactions/send_to_node.ctp +++ b/src/Template/Transactions/send_to_node.ctp @@ -66,7 +66,7 @@ Letzte eingereichte Transaktion headers: {'X-CSRF-Token': csfr_token}, dataType: 'json', success: function (data) { - if(data.state === 'success') { + if(data.result.state === 'success') { progressState.addClass('grd-success').html('Erfolgreich eingereicht'); setTimeout(function() { putTransaction(index+1);}, 1000); } else { @@ -77,7 +77,8 @@ Letzte eingereichte Transaktion progressState.addClass('grd-error').html('Fehler beim einreichen'); } var timeString = round_to_precision(data.timeUsed * 1000.0, 4) + ' ms'; - progressState.append(' ').append('' + timeString + ''); + var nodeTime = data.result.timeUsed; + progressState.append(' ').append('' + timeString + ' (node: ' + nodeTime + ')'); } }); }