update creation transaction and layout

This commit is contained in:
Dario Rekowski on RockPI 2019-10-30 17:08:33 +00:00
parent f131a4111b
commit c31e33c34a
21 changed files with 184 additions and 139 deletions

33
composer.lock generated
View File

@ -613,16 +613,16 @@
},
{
"name": "psr/log",
"version": "1.1.0",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
"reference": "bf73deb2b3b896a9d9c75f3f0d88185d2faa27e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"url": "https://api.github.com/repos/php-fig/log/zipball/bf73deb2b3b896a9d9c75f3f0d88185d2faa27e2",
"reference": "bf73deb2b3b896a9d9c75f3f0d88185d2faa27e2",
"shasum": ""
},
"require": {
@ -631,7 +631,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
},
"autoload": {
@ -656,7 +656,7 @@
"psr",
"psr-3"
],
"time": "2018-11-20T15:27:04+00:00"
"time": "2019-10-25T08:06:51+00:00"
},
{
"name": "psr/simple-cache",
@ -2468,16 +2468,16 @@
},
{
"name": "nikic/php-parser",
"version": "v4.2.4",
"version": "v4.2.5",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "97e59c7a16464196a8b9c77c47df68e4a39a45c4"
"reference": "b76bbc3c51f22c570648de48e8c2d941ed5e2cf2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/97e59c7a16464196a8b9c77c47df68e4a39a45c4",
"reference": "97e59c7a16464196a8b9c77c47df68e4a39a45c4",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/b76bbc3c51f22c570648de48e8c2d941ed5e2cf2",
"reference": "b76bbc3c51f22c570648de48e8c2d941ed5e2cf2",
"shasum": ""
},
"require": {
@ -2485,6 +2485,7 @@
"php": ">=7.0"
},
"require-dev": {
"ircmaxell/php-yacc": "0.0.4",
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0"
},
"bin": [
@ -2515,7 +2516,7 @@
"parser",
"php"
],
"time": "2019-09-01T07:51:21+00:00"
"time": "2019-10-25T18:33:07+00:00"
},
{
"name": "phar-io/manifest",
@ -3953,16 +3954,16 @@
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.5.1",
"version": "3.5.2",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "82cd0f854ceca17731d6d019c7098e3755c45060"
"reference": "65b12cdeaaa6cd276d4c3033a95b9b88b12701e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/82cd0f854ceca17731d6d019c7098e3755c45060",
"reference": "82cd0f854ceca17731d6d019c7098e3755c45060",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/65b12cdeaaa6cd276d4c3033a95b9b88b12701e7",
"reference": "65b12cdeaaa6cd276d4c3033a95b9b88b12701e7",
"shasum": ""
},
"require": {
@ -4000,7 +4001,7 @@
"phpcs",
"standards"
],
"time": "2019-10-16T21:14:26+00:00"
"time": "2019-10-28T04:36:32+00:00"
},
{
"name": "symfony/finder",

View File

@ -45,43 +45,51 @@ class DashboardController extends AppController
// login server cannot detect host ip
//echo "client ip: $ip<br>";
//echo $session_id;
if($session_id != 0 && $session->read('session_id') != $session_id) {
$http = new Client();
try {
$loginServer = Configure::read('LoginServer');
$url = $loginServer['host'] . ':' . $loginServer['port'];
//$url = 'http://***REMOVED***';
$response = $http->get($url . '/login', ['session_id' => $session_id]);
$json = $response->getJson();
if(isset($json) && count($json) > 0) {
if($json['state'] === 'success' && intval($json['user']['email_checked']) === 1) {
//echo "email checked: " . $json['user']['email_checked'] . "; <br>";
$session->destroy();
foreach($json['user'] as $key => $value) {
if($key === 'state') { continue; }
$session->write('StateUser.' . $key, $value );
}
$session->write('session_id', $session_id);
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
if($json['user']['public_hex'] != '') {
$public_key_bin = hex2bin($json['user']['public_hex']);
$stateUserQuery = $stateUserTable->find('all')->where(['public_key' => $public_key_bin]);
if($stateUserQuery->count() == 1) {
$stateUser = $stateUserQuery->first();
$session->write('StateUser.id', $stateUser['id']);
//echo $stateUser['id'];
} else {
$newStateUser = $stateUserTable->newEntity();
$newStateUser->public_key = $public_key_bin;
$newStateUser->first_name = $json['user']['first_name'];
$newStateUser->last_name = $json['user']['last_name'];
$stateUserTable->save($newStateUser);
$session->write('StateUser.id', $newStateUser->id);
//echo $newStateUser->id;
//echo $session_id; echo "<br>";
//echo $session->read('session_id');
if($session_id != 0) {
$userStored = $session->read('StateUser');
$transactionPendings = $session->read('Transactions.pending');
if($session->read('session_id') != $session_id ||
( $userStored && !isset($userStored['id'])) ||
intval($transactionPendings) > 0) {
$http = new Client();
try {
$loginServer = Configure::read('LoginServer');
$url = $loginServer['host'] . ':' . $loginServer['port'];
//$url = 'http://***REMOVED***';
$response = $http->get($url . '/login', ['session_id' => $session_id]);
$json = $response->getJson();
if(isset($json) && count($json) > 0) {
if($json['state'] === 'success' && intval($json['user']['email_checked']) === 1) {
//echo "email checked: " . $json['user']['email_checked'] . "; <br>";
$session->destroy();
foreach($json['user'] as $key => $value) {
if($key === 'state') { continue; }
$session->write('StateUser.' . $key, $value );
}
$transactionPendings = $json['Transaction.pending'];
$session->write('Transaction.pending', $transactionPendings);
$session->write('session_id', $session_id);
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
if($json['user']['public_hex'] != '') {
$public_key_bin = hex2bin($json['user']['public_hex']);
$stateUserQuery = $stateUserTable->find('all')->where(['public_key' => $public_key_bin]);
if($stateUserQuery->count() == 1) {
$stateUser = $stateUserQuery->first();
$session->write('StateUser.id', $stateUser['id']);
//echo $stateUser['id'];
} else {
$newStateUser = $stateUserTable->newEntity();
$newStateUser->public_key = $public_key_bin;
$newStateUser->first_name = $json['user']['first_name'];
$newStateUser->last_name = $json['user']['last_name'];
$stateUserTable->save($newStateUser);
$session->write('StateUser.id', $newStateUser->id);
//echo $newStateUser->id;
}
}
}
@ -89,7 +97,7 @@ class DashboardController extends AppController
// for debugging
$this->set('user', $json['user']);
$this->set('json', $json);
//$this->set('json', $json);
$this->set('timeUsed', microtime(true) - $startTime);
} else {
@ -98,19 +106,25 @@ class DashboardController extends AppController
//echo $json['user']['email_checked'];
//var_dump($json);
//
return $this->redirect(Router::url('/', true) . 'account/', 303);
//return $this->redirect(Router::url('/', true) . 'account/', 303);
}
}
}
} catch(\Exception $e) {
$msg = $e->getMessage();
$this->Flash->error(__('error http request: ') . $msg);
//continue;
} catch(\Exception $e) {
$msg = $e->getMessage();
$this->Flash->error(__('error http request: ') . $msg);
//continue;
}
} else {
// login already in session
$user = $session->read('StateUser');
$this->set('user', $user);
$this->set('timeUsed', microtime(true) - $startTime);
}
} else {
// no login
return $this->redirect(Router::url('/', true) . 'account/', 303);
}
}

View File

@ -92,6 +92,8 @@ class TransactionCreationsController extends AppController
if ($this->request->is('post')) {
$requestData = $this->request->getData();
$mode = 'next';
if(isset($requestData['add'])) {$mode = 'add'; }
if($creationForm->validate($requestData)) {
$pubKeyHex = '';
@ -139,14 +141,27 @@ class TransactionCreationsController extends AppController
if($json['state'] != 'success') {
if($json['msg'] == 'session not found') {
$session->destroy();
$this->Flash->error(__('session not found, please login again'));
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)));
}
} else {
return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303);
$pendingTransactionCount = $session->read('Transactions.pending');
if($pendingTransactionCount == null) {
$pendingTransactionCount = 1;
} else {
$pendingTransactionCount++;
}
$session->write('Transactions.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);

View File

@ -12,7 +12,7 @@ class CreationForm extends Form
protected function _buildSchema(Schema $schema)
{
return $schema
->addField('receiver_pubkey_hex', ['type' => 'string'])
//->addField('receiver_pubkey_hex', ['type' => 'string'])
->addField('receiver', ['type' => 'select'])
->addField('amount', ['type' => 'decimal', 'precision' => 2])
->addField('memo', ['type' =>'string', 'default' => '']);
@ -37,12 +37,12 @@ class CreationForm extends Form
])
->ascii('memo', __('Only Ascii Character allowed'))
->allowEmptyString('memo', null, 'create')
->add('receiver_pubkey_hex', 'custom', [
/*->add('receiver_pubkey_hex', 'custom', [
'rule' => 'hexKey64',
'provider' => 'custom',
'message' => 'a valid pubkey in hex format is required (64 character)'
])
->allowEmptyString('receiver_pubkey_hex', null, 'create')
->allowEmptyString('receiver_pubkey_hex', null, 'create')*/
->add('amount', 'custom', [
'rule' => 'amount',
'provider' => 'custom',

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.Key</code>
*/
final class Key extends \Google\Protobuf\Internal\Message
class Key extends \Google\Protobuf\Internal\Message
{
protected $key;

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.ReceiverAmount</code>
*/
final class ReceiverAmount extends \Google\Protobuf\Internal\Message
class ReceiverAmount extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>bytes ed25519_receiver_pubkey = 1;</code>

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.SenderAmount</code>
*/
final class SenderAmount extends \Google\Protobuf\Internal\Message
class SenderAmount extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>bytes ed25519_sender_pubkey = 1;</code>

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.SignatureMap</code>
*/
final class SignatureMap extends \Google\Protobuf\Internal\Message
class SignatureMap extends \Google\Protobuf\Internal\Message
{
/**
* Each signature pair corresponds to a unique Key required to sign the transaction.

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.SignaturePair</code>
*/
final class SignaturePair extends \Google\Protobuf\Internal\Message
class SignaturePair extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>bytes pubKey = 1;</code>

View File

@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
*
* Generated from protobuf message <code>model.messages.gradido.StateCreateGroup</code>
*/
final class StateCreateGroup extends \Google\Protobuf\Internal\Message
class StateCreateGroup extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>string name = 1;</code>

View File

@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
*
* Generated from protobuf message <code>model.messages.gradido.StateGroupChangeParent</code>
*/
final class StateGroupChangeParent extends \Google\Protobuf\Internal\Message
class StateGroupChangeParent extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>.model.messages.gradido.Key groupPublicKey = 1;</code>

View File

@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
*
* Generated from protobuf message <code>model.messages.gradido.Timestamp</code>
*/
final class Timestamp extends \Google\Protobuf\Internal\Message
class Timestamp extends \Google\Protobuf\Internal\Message
{
/**
* Number of complete seconds since the start of the epoch

View File

@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil;
*
* Generated from protobuf message <code>model.messages.gradido.TimestampSeconds</code>
*/
final class TimestampSeconds extends \Google\Protobuf\Internal\Message
class TimestampSeconds extends \Google\Protobuf\Internal\Message
{
/**
* Number of complete seconds since the start of the epoch

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.Transaction</code>
*/
final class Transaction extends \Google\Protobuf\Internal\Message
class Transaction extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>uint64 id = 1;</code>

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.TransactionBody</code>
*/
final class TransactionBody extends \Google\Protobuf\Internal\Message
class TransactionBody extends \Google\Protobuf\Internal\Message
{
/**
* max 150 chars

View File

@ -14,7 +14,7 @@ use Google\Protobuf\Internal\GPBUtil;
*
* Generated from protobuf message <code>model.messages.gradido.TransactionCreation</code>
*/
final class TransactionCreation extends \Google\Protobuf\Internal\Message
class TransactionCreation extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code>

View File

@ -11,7 +11,7 @@ use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>model.messages.gradido.Transfer</code>
*/
final class Transfer extends \Google\Protobuf\Internal\Message
class Transfer extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>repeated .model.messages.gradido.SenderAmount senderAmounts = 1;</code>

View File

@ -9,17 +9,20 @@
if(isset($user)) {
//var_dump($user);
}
$this->assign('title', __('Willkommen') . '&nbsp;' . $user['first_name'] . '&nbsp;' . $user['last_name']);
?>
<div class="grd_container">
<h1>Willkommen <?= $user['first_name'] ?>&nbsp;<?= $user['last_name'] ?></h1>
<div class="grd_container_small">
<fieldset>
<h3>Geld ...</h3>
<?= $this->Html->link(__('schöpfen'), ['controller' => 'TransactionCreations', 'action' => 'create'], ['class' => 'grd_bn grd_bg-bn']); ?>
<a class="grd_bn grd_bg-bn">überweisen</a>
<h3>Gradido ...</h3>
<?= $this->Html->link(
__('schöpfen'),
['controller' => 'TransactionCreations', 'action' => 'create'],
['class' => 'grd-nav-bn grd-nav-bn-large']
); ?>
<a class="grd-nav-bn grd-nav-bn-large">überweisen</a>
</fieldset>
<fieldset class="grd-margin-top-10">
<h3>Account ...</h3>
<a class="grd-nav-bn" href="./account/user_delete"><?= __("löschen"); ?></a>
</fieldset>
</div>
</div>
<div class="grd-time-used">
<?= round($timeUsed * 1000.0, 4) ?> ms
</div>

View File

@ -52,7 +52,8 @@ $cakeDescription = 'Gradido';
<div class="container clearfix">
<?= $this->fetch('content') ?>
</div>
<footer>
</footer>
<div class="grd-time-used dev-info">
<?= round($timeUsed * 1000.0, 4) ?> ms
</div>
</body>
</html>

View File

@ -1,4 +1,5 @@
<?php
use Cake\Routing\Router;
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
@ -14,6 +15,9 @@
*/
$cakeDescription = 'Gradido';
$session = $this->getRequest()->getSession();
$transactionPendings = $session->read('Transactions.pending');
?>
<!DOCTYPE html>
<html>
@ -34,23 +38,34 @@ $cakeDescription = 'Gradido';
<?= $this->fetch('script') ?>
</head>
<body>
<nav class="top-bar expanded" data-topbar role="navigation">
<ul class="title-area large-3 medium-4 columns">
<li class="name">
<h1><a href=""><?= $this->fetch('title') ?></a></h1>
</li>
</ul>
<div class="top-bar-section">
<ul class="right">
<li><a href="./account/logout"><?= __("Logout"); ?></a></li>
<div class="versionstring dev-info">
<p class="grd_small">Community Server in Entwicklung</p>
<p class="grd_small">Alpha 0.4.2</p>
</div>
<nav class="grd-left-bar expanded" data-topbar role="navigation">
<div class="grd-left-bar-section">
<ul class="grd-no-style">
<li><?= $this->Html->link(__('Startseite'), ['controller' => 'dashboard'], ['class' => 'grd-nav-bn'])?>
<?php if(intval($transactionPendings) > 0) : ?>
<li>
<a href="<?= Router::url('/', true) ?>account/checkTransactions" class="grd-nav-bn">
<?= __("Transaktionen unterzeichnen") . '&nbsp;(' . intval($transactionPendings) . ')'?>
</a>
</li>
<?php else: ?>
<li><a href="<?= Router::url('/', true) ?>account/logout" class="grd-nav-bn"><?= __("Logout"); ?></a></li>
<?php endif; ?>
</ul>
</div>
</nav>
<?= $this->Flash->render() ?>
<div class="container clearfix">
<?= $this->fetch('content') ?>
<div class="grd_container">
<h1><?= $this->fetch('title') ?></h1>
<div class="flash-messages"><?= $this->Flash->render() ?></div>
<?= $this->fetch('content') ?>
</div>
<div class="grd-time-used dev-info">
<?= round($timeUsed * 1000.0, 4) ?> ms
</div>
<footer>
</footer>
</body>
</html>

View File

@ -1,34 +1,30 @@
<?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.
*/
$address_options = [__('Selbst eingeben:')];
foreach($receiverProposal as $i => $receiver) {
//var_dump($receiver);
array_push($address_options, [
'text' => $receiver['name'],
'value' => $i+1,
'title' => $receiver['key']
]);
}
?>
<div class="grd_container">
<h1><?= __('Schöpfungstransaktion') ?></h1>
<div class="grd_container_small">
<?= $this->Form->create($creationForm) ?>
<fieldset>
<?= $this->Form->control('memo'); ?>
<?= $this->Form->control('amount'); ?>
<?= $this->Form->control('receiver', ['options' => $address_options]); ?>
<?= $this->Form->control('receiver_pubkey_hex', []) ?>
</fieldset>
<?= $this->Form->button(__('Bestätigen')) ?>
<?= $this->Form->end() ?>
</div>
</div>
<div class="grd-time-used">
<?= round($timeUsed * 1000.0, 4) ?> ms
</div>
<?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.
*/
$address_options = [];//__('Selbst eingeben:')];
foreach($receiverProposal as $i => $receiver) {
//var_dump($receiver);
array_push($address_options, [
'text' => $receiver['name'],
'value' => $i+1,
'title' => $receiver['key']
]);
}
$this->assign('title', __('Schöpfungstransaktion'));
?>
<div class="grd_container_small">
<?= $this->Form->create($creationForm) ?>
<fieldset>
<?= $this->Form->control('memo'); ?>
<?= $this->Form->control('amount'); ?>
<?= $this->Form->control('receiver', ['options' => $address_options]); ?>
<!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>-->
</fieldset>
<?= $this->Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?>
<?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?>
<?= $this->Form->end() ?>
</div>