add elopage buys skeletton

This commit is contained in:
Dario Rekowski on RockPI 2020-02-13 09:51:23 +00:00
parent 1bcf28246f
commit f2ea3dc5ef
11 changed files with 591 additions and 14 deletions

View File

@ -0,0 +1,119 @@
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* ElopageBuys Controller
*
* @property \App\Model\Table\ElopageBuysTable $ElopageBuys
*
* @method \App\Model\Entity\ElopageBuy[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
*/
class ElopageBuysController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null
*/
public function index()
{
$this->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']);
}
}

View File

@ -166,17 +166,23 @@ class TransactionsController extends AppController
echo "exception: ";
var_dump($e);
}
$transactionBase64 = base64_encode($transaction->serializeToString());
//echo "base64: <br>$transactionBase64<br>";
$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: <br>$transactionBase64<br>";
$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;

View File

@ -0,0 +1,57 @@
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
/**
* ElopageBuy Entity
*
* @property int $id
* @property int $elopage_user_id
* @property int $affiliate_program_id
* @property int $publisher_id
* @property int $order_id
* @property int $product_id
* @property int $product_price
* @property string $payer_email
* @property string $publisher_email
* @property bool $payed
* @property \Cake\I18n\FrozenTime $success_date
* @property string $event
*
* @property \App\Model\Entity\ElopageUser $elopage_user
* @property \App\Model\Entity\AffiliateProgram $affiliate_program
* @property \App\Model\Entity\Publisher $publisher
* @property \App\Model\Entity\Order $order
* @property \App\Model\Entity\Product $product
*/
class ElopageBuy extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array
*/
protected $_accessible = [
'elopage_user_id' => 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,
];
}

View File

@ -0,0 +1,140 @@
<?php
namespace App\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* ElopageBuys Model
*
* @property \App\Model\Table\ElopageUsersTable&\Cake\ORM\Association\BelongsTo $ElopageUsers
* @property \App\Model\Table\AffiliateProgramsTable&\Cake\ORM\Association\BelongsTo $AffiliatePrograms
* @property \App\Model\Table\PublishersTable&\Cake\ORM\Association\BelongsTo $Publishers
* @property \App\Model\Table\OrdersTable&\Cake\ORM\Association\BelongsTo $Orders
* @property \App\Model\Table\ProductsTable&\Cake\ORM\Association\BelongsTo $Products
*
* @method \App\Model\Entity\ElopageBuy get($primaryKey, $options = [])
* @method \App\Model\Entity\ElopageBuy newEntity($data = null, array $options = [])
* @method \App\Model\Entity\ElopageBuy[] newEntities(array $data, array $options = [])
* @method \App\Model\Entity\ElopageBuy|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method \App\Model\Entity\ElopageBuy saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method \App\Model\Entity\ElopageBuy patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \App\Model\Entity\ElopageBuy[] patchEntities($entities, array $data, array $options = [])
* @method \App\Model\Entity\ElopageBuy findOrCreate($search, callable $callback = null, $options = [])
*/
class ElopageBuysTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->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';
}
}

View File

@ -97,6 +97,7 @@ class Transaction extends TransactionBase {
//echo 'sig Pair: '; var_dump($sigPair); echo "<br>";
$pubkey = $sigPair->getPubKey();
$signature = $sigPair->getEd25519();
echo "verify bodybytes: <br>" . bin2hex($bodyBytes) . '<br>';
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: <br>" . bin2hex($bodyBytes) . '<br>';
$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 "<br>";
$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;
}

View File

@ -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<br>";
$protoBody->setCreation(TransactionCreation::fromEntity($transaction->transaction_creations[0])->getProto());

View File

@ -0,0 +1,33 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ElopageBuy $elopageBuy
*/
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('List Elopage Buys'), ['action' => 'index']) ?></li>
</ul>
</nav>
<div class="elopageBuys form large-9 medium-8 columns content">
<?= $this->Form->create($elopageBuy) ?>
<fieldset>
<legend><?= __('Add Elopage Buy') ?></legend>
<?php
echo $this->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');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>

View File

@ -0,0 +1,39 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ElopageBuy $elopageBuy
*/
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $elopageBuy->id],
['confirm' => __('Are you sure you want to delete # {0}?', $elopageBuy->id)]
)
?></li>
<li><?= $this->Html->link(__('List Elopage Buys'), ['action' => 'index']) ?></li>
</ul>
</nav>
<div class="elopageBuys form large-9 medium-8 columns content">
<?= $this->Form->create($elopageBuy) ?>
<fieldset>
<legend><?= __('Edit Elopage Buy') ?></legend>
<?php
echo $this->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');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>

View File

@ -0,0 +1,67 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ElopageBuy[]|\Cake\Collection\CollectionInterface $elopageBuys
*/
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('New Elopage Buy'), ['action' => 'add']) ?></li>
</ul>
</nav>
<div class="elopageBuys index large-9 medium-8 columns content">
<h3><?= __('Elopage Buys') ?></h3>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th scope="col"><?= $this->Paginator->sort('id') ?></th>
<th scope="col"><?= $this->Paginator->sort('elopage_user_id') ?></th>
<th scope="col"><?= $this->Paginator->sort('affiliate_program_id') ?></th>
<th scope="col"><?= $this->Paginator->sort('publisher_id') ?></th>
<th scope="col"><?= $this->Paginator->sort('order_id') ?></th>
<th scope="col"><?= $this->Paginator->sort('product_id') ?></th>
<th scope="col"><?= $this->Paginator->sort('product_price') ?></th>
<th scope="col"><?= $this->Paginator->sort('payer_email') ?></th>
<th scope="col"><?= $this->Paginator->sort('publisher_email') ?></th>
<th scope="col"><?= $this->Paginator->sort('payed') ?></th>
<th scope="col"><?= $this->Paginator->sort('success_date') ?></th>
<th scope="col"><?= $this->Paginator->sort('event') ?></th>
<th scope="col" class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($elopageBuys as $elopageBuy): ?>
<tr>
<td><?= $this->Number->format($elopageBuy->id) ?></td>
<td><?= $this->Number->format($elopageBuy->elopage_user_id) ?></td>
<td><?= $this->Number->format($elopageBuy->affiliate_program_id) ?></td>
<td><?= $this->Number->format($elopageBuy->publisher_id) ?></td>
<td><?= $this->Number->format($elopageBuy->order_id) ?></td>
<td><?= $this->Number->format($elopageBuy->product_id) ?></td>
<td><?= $this->Number->format($elopageBuy->product_price) ?></td>
<td><?= h($elopageBuy->payer_email) ?></td>
<td><?= h($elopageBuy->publisher_email) ?></td>
<td><?= h($elopageBuy->payed) ?></td>
<td><?= h($elopageBuy->success_date) ?></td>
<td><?= h($elopageBuy->event) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $elopageBuy->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $elopageBuy->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $elopageBuy->id], ['confirm' => __('Are you sure you want to delete # {0}?', $elopageBuy->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?></p>
</div>
</div>

View File

@ -0,0 +1,68 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\ElopageBuy $elopageBuy
*/
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('Edit Elopage Buy'), ['action' => 'edit', $elopageBuy->id]) ?> </li>
<li><?= $this->Form->postLink(__('Delete Elopage Buy'), ['action' => 'delete', $elopageBuy->id], ['confirm' => __('Are you sure you want to delete # {0}?', $elopageBuy->id)]) ?> </li>
<li><?= $this->Html->link(__('List Elopage Buys'), ['action' => 'index']) ?> </li>
<li><?= $this->Html->link(__('New Elopage Buy'), ['action' => 'add']) ?> </li>
</ul>
</nav>
<div class="elopageBuys view large-9 medium-8 columns content">
<h3><?= h($elopageBuy->id) ?></h3>
<table class="vertical-table">
<tr>
<th scope="row"><?= __('Payer Email') ?></th>
<td><?= h($elopageBuy->payer_email) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Publisher Email') ?></th>
<td><?= h($elopageBuy->publisher_email) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Event') ?></th>
<td><?= h($elopageBuy->event) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Id') ?></th>
<td><?= $this->Number->format($elopageBuy->id) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Elopage User Id') ?></th>
<td><?= $this->Number->format($elopageBuy->elopage_user_id) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Affiliate Program Id') ?></th>
<td><?= $this->Number->format($elopageBuy->affiliate_program_id) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Publisher Id') ?></th>
<td><?= $this->Number->format($elopageBuy->publisher_id) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Order Id') ?></th>
<td><?= $this->Number->format($elopageBuy->order_id) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Product Id') ?></th>
<td><?= $this->Number->format($elopageBuy->product_id) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Product Price') ?></th>
<td><?= $this->Number->format($elopageBuy->product_price) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Success Date') ?></th>
<td><?= h($elopageBuy->success_date) ?></td>
</tr>
<tr>
<th scope="row"><?= __('Payed') ?></th>
<td><?= $elopageBuy->payed ? __('Yes') : __('No'); ?></td>
</tr>
</table>
</div>

View File

@ -66,7 +66,7 @@ Letzte eingereichte Transaktion <?= gTransactionIds[0] - 1 ?>
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 <?= gTransactionIds[0] - 1 ?>
progressState.addClass('grd-error').html('Fehler beim einreichen');
}
var timeString = round_to_precision(data.timeUsed * 1000.0, 4) + ' ms';
progressState.append('&nbsp;').append('<span class="time-used">' + timeString + '</span>');
var nodeTime = data.result.timeUsed;
progressState.append('&nbsp;').append('<span class="time-used">' + timeString + ' (node: ' + nodeTime + ')</span>');
}
});
}