mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
adding missing files
This commit is contained in:
parent
5ad4addc43
commit
f131a4111b
119
src/Controller/DashboardController.php
Normal file
119
src/Controller/DashboardController.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
use Cake\Http\Client;
|
||||
use Cake\Routing\Router;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\Core\Configure;
|
||||
|
||||
/**
|
||||
* StateUsers Controller
|
||||
*
|
||||
* @property \App\Model\Table\StateUsersTable $StateUsers
|
||||
*
|
||||
* @method \App\Model\Entity\StateUser[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
|
||||
*/
|
||||
class DashboardController extends AppController
|
||||
{
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
//$this->Auth->allow(['add', 'edit']);
|
||||
$this->Auth->allow('index');
|
||||
}
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$this->viewBuilder()->setLayout('frontend');
|
||||
$session = $this->getRequest()->getSession();
|
||||
// check login
|
||||
// disable encryption for cookies
|
||||
//$this->Cookie->configKey('User', 'encryption', false);
|
||||
//$this->Cookie->read('GRADIDO_LOGIN');
|
||||
$session_id = intval($this->request->getCookie('GRADIDO_LOGIN', ''));
|
||||
$ip = $this->request->clientIp();
|
||||
if(!$session->check('client_ip')) {
|
||||
$session->write('client_ip', $ip);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for debugging
|
||||
|
||||
$this->set('user', $json['user']);
|
||||
$this->set('json', $json);
|
||||
$this->set('timeUsed', microtime(true) - $startTime);
|
||||
|
||||
} else {
|
||||
if($json['state'] === 'not found' ) {
|
||||
$this->Flash->error(__('invalid session'));
|
||||
//echo $json['user']['email_checked'];
|
||||
//var_dump($json);
|
||||
//
|
||||
return $this->redirect(Router::url('/', true) . 'account/', 303);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch(\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
$this->Flash->error(__('error http request: ') . $msg);
|
||||
|
||||
//continue;
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->redirect(Router::url('/', true) . 'account/', 303);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
66
src/Form/CreationForm.php
Normal file
66
src/Form/CreationForm.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// in src/Form/ContactForm.php
|
||||
namespace App\Form;
|
||||
|
||||
use Cake\Form\Form;
|
||||
use Cake\Form\Schema;
|
||||
use Cake\Validation\Validator;
|
||||
|
||||
class CreationForm extends Form
|
||||
{
|
||||
|
||||
protected function _buildSchema(Schema $schema)
|
||||
{
|
||||
return $schema
|
||||
->addField('receiver_pubkey_hex', ['type' => 'string'])
|
||||
->addField('receiver', ['type' => 'select'])
|
||||
->addField('amount', ['type' => 'decimal', 'precision' => 2])
|
||||
->addField('memo', ['type' =>'string', 'default' => '']);
|
||||
}
|
||||
|
||||
function validationDefault(Validator $validator)
|
||||
{
|
||||
$validator->setProvider('custom', 'App\Model\Validation\TransactionValidation');
|
||||
/*
|
||||
$validator->add('receiver_pubkey_hex', 'length', [
|
||||
'rule' => ['length', 64],
|
||||
'message' => 'a valid pubkey in hex format is required (64 character)'
|
||||
])->add('receiver_pubkey_hex_select', 'length', [
|
||||
'rule' => ['length', 64],
|
||||
'message' => 'a valid pubkey in hex format is required (64 character)',
|
||||
]);
|
||||
*/
|
||||
// TODO: add validation for used character to prevent hacking attempts
|
||||
$validator->add('memo', 'length', [
|
||||
'rule' => ['maxLength', 150],
|
||||
'message' => 'max 150 character'
|
||||
])
|
||||
->ascii('memo', __('Only Ascii Character allowed'))
|
||||
->allowEmptyString('memo', null, 'create')
|
||||
->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')
|
||||
->add('amount', 'custom', [
|
||||
'rule' => 'amount',
|
||||
'provider' => 'custom',
|
||||
'message' => __('Please give a valid number with maximal 2 decimal places')
|
||||
]);
|
||||
return $validator;
|
||||
}
|
||||
/*
|
||||
* $validator->add('title', 'custom', [
|
||||
'rule' => 'customRule',
|
||||
'provider' => 'custom',
|
||||
'message' => 'The title is not unique enough'
|
||||
]);
|
||||
*/
|
||||
|
||||
protected function _execute(array $data)
|
||||
{
|
||||
// Send an email.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
33
src/Model/Validation/TransactionValidation.php
Normal file
33
src/Model/Validation/TransactionValidation.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?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\Model\Validation;
|
||||
|
||||
use Cake\I18n\Number;
|
||||
|
||||
class TransactionValidation
|
||||
{
|
||||
public static function amount($value, array $context) {
|
||||
$checkFloatVal = Number::format($value, ['locale' => 'en_GB']);
|
||||
$numberparts = preg_split('/\./', $checkFloatVal);
|
||||
//var_dump($numberparts);
|
||||
if(isset($numberparts[1]) && strlen($numberparts[1]) > 2) return false;
|
||||
|
||||
$floatVal = floatval(Number::format($value, ['places' => 4, 'locale' => 'en_GB']));
|
||||
//echo "floatVal: $floatVal<br>";
|
||||
return $floatVal != 0.0;
|
||||
}
|
||||
|
||||
public static function hexKey64($value, array $context) {
|
||||
if(strlen($value) != 64) return false;
|
||||
if(preg_match('/^[[:xdigit:]]*$/', $value)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
25
src/Template/Dashboard/index.ctp
Normal file
25
src/Template/Dashboard/index.ctp
Normal file
@ -0,0 +1,25 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
if(isset($user)) {
|
||||
//var_dump($user);
|
||||
}
|
||||
?>
|
||||
<div class="grd_container">
|
||||
<h1>Willkommen <?= $user['first_name'] ?> <?= $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>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grd-time-used">
|
||||
<?= round($timeUsed * 1000.0, 4) ?> ms
|
||||
</div>
|
||||
34
src/Template/TransactionCreations/create.ctp
Normal file
34
src/Template/TransactionCreations/create.ctp
Normal file
@ -0,0 +1,34 @@
|
||||
<?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>
|
||||
Loading…
x
Reference in New Issue
Block a user