adding some more files

This commit is contained in:
Dario Rekowski on RockPI 2020-02-04 17:52:36 +00:00
parent 2862d7824d
commit 2af0efaa9f
15 changed files with 806 additions and 0 deletions

View File

@ -0,0 +1,71 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\Http\Client;
use Cake\Core\Configure;
use Datto\JsonRpc\Client as JsonRpcClient;
//App\Controller\Component\ComponentRegistry
class JsonRpcRequestClientComponent extends Component
{
var $rpcClient = null;
public function __construct($registry, array $config = array()) {
parent::__construct($registry, $config);
$this->rpcClient = new JsonRpcClient();
}
// @param id: if id = 0 call rand for it
public function request($method, $params = [], $id = 0)
{
if(0 == $id) {
$id = random_int(1, 12000);
}
$this->rpcClient->query($id, $method, $params);
$message = $this->rpcClient->encode();
return $this->sendRequest($message);
// message: {"jsonrpc":"2.0","method":"add","params":[1,2],"id":1}
}
public function sendRequest($message) {
$http = new Client();
$response = $http->post($this->getGradidoNodeUrl(), $message, ['type' => 'json']);
$responseStatus = $response->getStatusCode();
if($responseStatus != 200) {
return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response status code isn\'t 200', 'details' => $responseStatus];
}
//$responseType = $response->getType();
//if($responseType != 'application/json') {
// return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response isn\'t json', 'details' => $responseType];
// }
$json = $response->getJson();
if($json == null) {
//$responseType = $response->getType();
return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response isn\'t valid json'];
}
return $json;
//return ['state' => 'success', 'data' => $json];
}
static public function getGradidoNodeUrl()
{
$gradidoNode = Configure::read('GradidoNode');
return $gradidoNode['host'] . ':' . $gradidoNode['port'];
}
}

View File

@ -0,0 +1,8 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

View File

@ -0,0 +1,94 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Model\Navigation;
class NaviEntrySub extends NaviEntryBase {
private $controller = '';
private $action = '';
private $active = '';
private $param = null;
private $iconClass = '';
private $iconColor = '';
private $bgColorClass = '';
private $subtitle = '';
public function __construct($title, $subtitle, $iconClass, $controller, $action, $active = null, $param = null) {
$this->controller = $controller;
$this->action = $action;
$this->param = $param;
$this->iconClass = $iconClass;
if($active != null) {
$this->active = $active;
} else {
$this->active = ($GLOBALS["side"] == $controller &&
$GLOBALS["subside"] == $action &&
$GLOBALS["passed"] == $param);
}
$this->title = $title;
$this->subtitle = $subtitle;
return $this;
}
public function setIconColor($iconColorClass) {
$this->iconColor = $iconColorClass;
return $this;
}
public function setBGColor($bgColorClass) {
$this->bgColorClass = $bgColorClass;
return $this;
}
private function isActive() {
return $this->active;
}
private function link() {
//global $self;
//echo "<i>self: </i>"; var_dump($GLOBALS("self"));
$self = $GLOBALS["self"];
if($this->hasChilds()) {
return $self->Html->link($this->title.'<span class="caret"></span>', ['controller' => $this->controller, "action" => $this->action, $this->param], ['escape' => false]);
} else {
//return $self->Html->link($this->title, ['controller' => $this->controller, "action" => $this->action, $this->param]);
return $self->Html->Link(
''
.'<span class="link-title">' . $this->title . '</span>'
.'<i class="mdi '. $this->iconClass .' link-icon ' . $this->iconColor .'"></i>'
//.'<small class="text-muted">' . $this->subtitle . '</small>'
,
['controller' => $this->controller, 'action' => $this->action, $this->param],
['class' => $this->bgColorClass, 'escape' => false]);
}
}
public function __toString() {
$str = "";
$str .= "<li";
$class = "";
if($this->hasChilds()) { $class .= "dropdown";}
if($this->isActive()) { $class .= " active"; }
if(strlen($class) > 0 ) $str .= " class='$class'";
$str .= ">";
$str .= '<small class="text-muted">'. $this->subtitle .'</small>';
$str .= $this->link();
if($this->hasChilds()) {
$str .= "<ul class='subnav'>";
foreach($this->childs as $child) {
$str .= $child;
}
$str .= "</ul>";
}
$str .= "</li>";
return $str;
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Model\Transactions;
//use Model\Messages\Gradido\Transaction;
//use Model\Messages\Gradido\TransactionBody;
class SignatureMap {
private $mProtoSigMap = null;
public function __construct($protoSigMap)
{
$this->mProtoSigMap = $protoSigMap;
}
public function getProto() {
return $this->mProtoSigMap;
}
static public function fromEntity($transactionSignatures)
{
$protoSigMap = new \Model\Messages\Gradido\SignatureMap();
$sigPairs = $protoSigMap->getSigPair();
//echo "sigPairs: "; var_dump($sigPairs); echo "<br>";
//return null;
foreach($transactionSignatures as $signature) {
$sigPair = new \Model\Messages\Gradido\SignaturePair();
$sigPair->setPubKey(stream_get_contents($signature->pubkey));
$sigPair->setEd25519(stream_get_contents($signature->signature));
$sigPairs[] = $sigPair;
//array_push($sigPairs, $sigPair);
}
return new SignatureMap($protoSigMap);
}
}

View File

@ -0,0 +1,19 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$this->assign('title', __('Gradido Schöpfung'));
?><?= __('Hallo') ?> <?= $user->first_name ?> <?= $user->last_name ?>,
<?= __('Für dich wurden soeben {0} geschöpft.', $this->element('printGradido', ['number' => $gdd_cent, 'raw' => true])) ?>
Gradido Akademie schreibt:
<?= $memo ?>
<?= __('Bitte antworte nicht auf diese E-Mail!'); ?>
<?= __('Mit freundlichen Grüßen'); ?>
Gradido Community Server

View File

@ -0,0 +1,21 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$this->assign('title', __('Gradido Überweisung'));
$receiverNames = $receiverUser->first_name . ' ' . $receiverUser->last_name;
$senderNames = $senderUser->first_name . ' ' . $senderUser->last_name;
?><?= __('Hallo') ?> <?= $receiverNames ?>,
<?= __('Du hast soeben {0} von {1} erhalten.', $this->element('printGradido', ['number' => $gdd_cent, 'raw' => true]), $senderNames) ?>
<?= __('{0} schreibt:', $senderNames) ?>
<?= $memo ?>
<?= __('Du kannst {0} eine Nachricht schreiben, indem du auf diese E-Mail antwortest', $senderNames); ?>
<?= __('Mit freundlichen Grüßen'); ?>
Gradido Community Server

View File

@ -0,0 +1,29 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
?>
<div class="grd_container_small">
<table>
<thead>
<tr>
<th>first name</th><th>last name</th><th>email</th><th>identHash</th><th>Public key hex
</tr>
</thead>
<tbody>
<?php foreach($stateUsers as $user) :?>
<tr>
<td><?= $user->first_name ?></td>
<td><?= $user->last_name ?></td>
<td><?= $user->email ?></td>
<td><?= $user->identHash ?></td>
<td><?= bin2hex(stream_get_contents($user->public_key)) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

View File

@ -0,0 +1,36 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
?>
<?php if(isset($errors) && count($errors) > 0) : ?>
<div class="grd-alert-color">
<ul>
<?php foreach($errors as $error) : ?>
<li>
<?= var_dump($error); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?= $this->Form->create() ?>
<?= $this->Form->control('base64', ['type'=> 'textarea', 'rows' => '5', 'cols' => 40]) ?>
<?= $this->Form->submit(); ?>
<?= $this->Form->end() ?>
<?php if(isset($transaction)) : ?>
<?php
$body = $transaction;//$transaction->getTransactionBody();
?>
<table>
<tr><th>Type</th><td><?= $body->getTransactionTypeName() ?></td></tr>
<tr><th>Memo</th><td<<?= $body->getMemo() ?></td></tr>
</table>
<?= var_dump($transaction); ?>
<?php endif; ?>

View File

@ -0,0 +1,91 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$this->assign('title', __('Transaktionen an Gradido-Node senden'));
?>
<style type="text/css">
.time-used {
color:grey;
font-size:smaller;
}
.progress-state.grd-error {
border:none;
}
</style>
<p>
<?php if($transactionIds[0] == 1) : ?>
Bisher keine Transaktionen eingereicht
<?php else: ?>
Letzte eingereichte Transaktion <?= gTransactionIds[0] - 1 ?>
<?php endif; ?>
</p>
<ul class="grd-no-style" id="put-progress">
<?php foreach($transactionIds as $i => $id) : ?>
<li>
<b><?= $id ?></b>:
<span class="progress-state">
<?php if($i == 0): ?>
<i>Wird verarbeitet</i>
<?php else: ?>
in Warteschlange
<?php endif; ?>
</span>
<?php endforeach; ?>
</li>
</ul>
<?= $this->Html->script(['core']); ?>
<script type="text/javascript">
var gTransactionIds = <?= json_encode($transactionIds); ?>;
var csfr_token = '<?= $csfr_token ?>';
function round_to_precision(x, precision) {
var h = Math.pow(10, precision);
return Math.round(x * h) / h;
}
function putTransaction(index) {
if(gTransactionIds[index] === undefined) {
return;
}
console.log("index: %d", index);
var progressState = $('#put-progress .progress-state').eq(index);
progressState.html('<i>Wird verarbeitet</i>');
$.ajax({
url: 'ajaxPutTransactionToGradidoNode',
type: 'post',
data: {
transaction_id: gTransactionIds[index]
},
headers: {'X-CSRF-Token': csfr_token},
dataType: 'json',
success: function (data) {
if(data.state === 'success') {
progressState.addClass('grd-success').html('Erfolgreich eingereicht');
setTimeout(function() { putTransaction(index+1);}, 1000);
} else {
$('#put-progress .progress-state').map(function(_index, dom) {
if(_index <= index) return;
$(dom).html('Abgebrochen');
});
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>');
}
});
}
$(function() {
//console.log("on DOM ready");
putTransaction(0);
//.grd-success
// $( "ul li:nth-child(2)" )
})
</script>

View File

@ -0,0 +1,56 @@
<?php
namespace App\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* AdminErrorsFixture
*/
class AdminErrorsFixture extends TestFixture
{
/**
* Fields
*
* @var array
*/
// @codingStandardsIgnoreStart
public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'state_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'controller' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'action' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'state' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'msg' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'details' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'utf8mb4_general_ci'
],
];
// @codingStandardsIgnoreEnd
/**
* Init method
*
* @return void
*/
public function init()
{
$this->records = [
[
'id' => 1,
'state_user_id' => 1,
'controller' => 'Lorem ipsum dolor sit amet',
'action' => 'Lorem ipsum dolor sit amet',
'state' => 'Lorem ipsum dolor sit amet',
'msg' => 'Lorem ipsum dolor sit amet',
'details' => 'Lorem ipsum dolor sit amet',
'created' => '2019-12-16 15:08:19'
],
];
parent::init();
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* StateErrorsFixture
*/
class StateErrorsFixture extends TestFixture
{
/**
* Fields
*
* @var array
*/
// @codingStandardsIgnoreStart
public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'state_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'transaction_type_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'message_json' => ['type' => 'text', 'length' => null, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'utf8mb4_general_ci'
],
];
// @codingStandardsIgnoreEnd
/**
* Init method
*
* @return void
*/
public function init()
{
$this->records = [
[
'id' => 1,
'state_user_id' => 1,
'transaction_type_id' => 1,
'created' => '2019-11-07 13:13:12',
'message_json' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.'
],
];
parent::init();
}
}

View File

@ -0,0 +1,76 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\AdminErrorsController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\AdminErrorsController Test Case
*
* @uses \App\Controller\AdminErrorsController
*/
class AdminErrorsControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.AdminErrors',
'app.StateUsers'
];
/**
* Test index method
*
* @return void
*/
public function testIndex()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test view method
*
* @return void
*/
public function testView()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test add method
*
* @return void
*/
public function testAdd()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test edit method
*
* @return void
*/
public function testEdit()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test delete method
*
* @return void
*/
public function testDelete()
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\AppController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\DashboardController Test Case
*
* @uses \App\Controller\DashboardController
*/
class AppControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.StateBalances'
];
public function setUp()
{
parent::setUp();
}
/**
* Test initialize method
*
* @return void
*/
public function testInitialize()
{
$this->session(['StateUser.id' => 1]);
$this->get('/');
$this->assertSession(1200, 'StateUser.balance');
//$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace App\Test\TestCase\Controller\Component;
use App\Controller\Component\JsonRequestClientComponent;
use Cake\Controller\ComponentRegistry;
use Cake\TestSuite\TestCase;
/**
* App\Controller\Component\JsonRequestClientComponent Test Case
*/
class JsonRequestClientComponentTest extends TestCase
{
/**
* Test subject
*
* @var \App\Controller\Component\JsonRequestClientComponent
*/
public $JsonRequestClientComponent;
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$registry = new ComponentRegistry();
$this->JsonRequestClientComponent = new JsonRequestClientComponent($registry);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
unset($this->JsonRequestClientComponent);
parent::tearDown();
}
/**
* Test sendTransaction method
*
* @return void
*/
public function testSendTransaction()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test getLoginServerUrl method
*
* @return void
*/
public function testGetLoginServerUrl()
{
//$this->markTestIncomplete('Not implemented yet.');
$serverUrl = $this->JsonRequestClientComponent->getLoginServerUrl();
$this->assertEquals($serverUrl, 'http://***REMOVED***');
}
/**
* Test is_base64 method
*
* @return void
*/
public function testIsBase64Valid()
{
$result = $this->JsonRequestClientComponent->is_base64('CgpIYWxsbyBXZWx0EgYIr6fe7wVKLwonCiDWDyYU4+zldTQdQMIzGpsL20W+vV44JuNVA5hwczIELRDgg5sBELmhkoIE');
$this->assertEquals($result, true);
}
public function testIsBase64Invalid()
{
$result = $this->JsonRequestClientComponent->is_base64('CgpIYWxsbyBXZWx0EgYIr6fe7wVKLwonCiDWDyYU4-zldTQdQMIzGpsL20W+vV44JuNVA5hwczIELRDgg5sBELmhkoIE');
$this->assertEquals($result, false);
}
}

View File

@ -0,0 +1,77 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\StateErrorsController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\StateErrorsController Test Case
*
* @uses \App\Controller\StateErrorsController
*/
class StateErrorsControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.StateErrors',
'app.StateUsers',
'app.TransactionTypes'
];
/**
* Test index method
*
* @return void
*/
public function testIndex()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test view method
*
* @return void
*/
public function testView()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test add method
*
* @return void
*/
public function testAdd()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test edit method
*
* @return void
*/
public function testEdit()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test delete method
*
* @return void
*/
public function testDelete()
{
$this->markTestIncomplete('Not implemented yet.');
}
}