mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
check in send coins if receiver was disabled
This commit is contained in:
parent
224714b16d
commit
59031cc19a
@ -1 +1 @@
|
|||||||
Subproject commit a04d4769974b9d93ba72e490ed7dca3fbaed768c
|
Subproject commit 21d4a0a5e9a19f251e26c0ae07ce74be2fa99bbf
|
||||||
@ -137,13 +137,13 @@ class TransactionSendCoinsController extends AppController
|
|||||||
$session = $this->getRequest()->getSession();
|
$session = $this->getRequest()->getSession();
|
||||||
$user = $session->read('StateUser');
|
$user = $session->read('StateUser');
|
||||||
// var_dump($user);
|
// var_dump($user);
|
||||||
if (!$user) {
|
if(!$user) {
|
||||||
//return $this->redirect(Router::url('/', true) . 'account/', 303);
|
//return $this->redirect(Router::url('/', true) . 'account/', 303);
|
||||||
$result = $this->requestLogin();
|
$result = $this->requestLogin();
|
||||||
if ($result !== true) {
|
if($result !== true) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
$user = $session->read('StateUser');
|
$user = $session->read('StateUser');
|
||||||
}
|
}
|
||||||
|
|
||||||
$transferForm = new TransferForm();
|
$transferForm = new TransferForm();
|
||||||
@ -153,130 +153,137 @@ class TransactionSendCoinsController extends AppController
|
|||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
//$this->Flash->error(__('Wird zurzeit noch entwickelt!'));
|
//$this->Flash->error(__('Wird zurzeit noch entwickelt!'));
|
||||||
|
|
||||||
$requestData = $this->request->getData();
|
$requestData = $this->request->getData();
|
||||||
$mode = 'next';
|
$mode = 'next';
|
||||||
if (isset($requestData['add'])) {
|
if(isset($requestData['add'])) {$mode = 'add'; }
|
||||||
$mode = 'add';
|
if($transferForm->validate($requestData)) {
|
||||||
|
|
||||||
|
$receiverPubKeyHex = '';
|
||||||
|
$senderPubKeyHex = $user['public_hex'];
|
||||||
|
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||||
|
|
||||||
|
if(!isset($user['balance']) || $amountCent > $user['balance']) {
|
||||||
|
$this->Flash->error(__('Du hast nicht genug Geld!'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if ($transferForm->validate($requestData)) {
|
|
||||||
$receiverPubKeyHex = '';
|
|
||||||
$senderPubKeyHex = $user['public_hex'];
|
|
||||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
|
||||||
|
|
||||||
if (!isset($user['balance']) || $amountCent > $user['balance']) {
|
$receiverEmail = $requestData['email'];
|
||||||
$this->Flash->error(__('Du hast nicht genug Geld!'));
|
if($receiverEmail === $user['email']) {
|
||||||
return;
|
$this->Flash->error(__('Du kannst dir leider nicht selbst Geld schicken!'));
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
$receiverEmail = $requestData['email'];
|
$receiverPubkeyHex ='';
|
||||||
if ($receiverEmail === $user['email']) {
|
$requestAnswear = $this->JsonRequestClient->sendRequest(json_encode([
|
||||||
$this->Flash->error(__('Du kannst dir leider nicht selbst Geld schicken!'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$receiverPubkeyHex ='';
|
|
||||||
$response = $this->JsonRequestClient->sendRequest(json_encode([
|
|
||||||
'session_id' => $session->read('session_id'),
|
'session_id' => $session->read('session_id'),
|
||||||
'email' => $receiverEmail,
|
'email' => $receiverEmail,
|
||||||
'ask' => ['user.pubkeyhex']
|
'ask' => ['user.pubkeyhex', 'user.disabled']
|
||||||
]), '/getUserInfos');
|
]), '/getUserInfos');
|
||||||
if ('success' == $response['state'] && 'success' == $response['data']['state']) {
|
if('success' == $requestAnswear['state'] && 'success' == $requestAnswear['data']['state']) {
|
||||||
// will be allways 64 byte long, even if it is empty
|
// will be allways 64 byte long, even if it is empty
|
||||||
$receiverPubKeyHex = $response['data']['userData']['pubkeyhex'];
|
$receiverPubKeyHex = $requestAnswear['data']['userData']['pubkeyhex'];
|
||||||
} elseif ('success' == $response['state'] && 'not found' == $response['data']['state']) {
|
} else {
|
||||||
return $this->redirect($this->loginServerUrl . 'account', 303);
|
$this->addAdminError('TransactionSendCoins', 'create', $requestAnswear, $user['id']);
|
||||||
} else {
|
$this->Flash->error(__('Der Empfänger wurde nicht auf dem Login-Server gefunden, hat er sein Konto schon angelegt?'));
|
||||||
$this->addAdminError('TransactionSendCoins', 'create', $response, $user['id']);
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
$this->Flash->error(__('Der Empfänger wurde nicht auf dem Login-Server gefunden, hat er sein Konto schon angelegt?'));
|
return;
|
||||||
$this->set('timeUsed', microtime(true) - $startTime);
|
}
|
||||||
return;
|
if($requestAnswear['data']['userData']['disabled']) {
|
||||||
}
|
$this->Flash->error(__('Der Empfänger ist deaktiviert, daher können ihm zurzeit keine Gradidos gesendet werden.'));
|
||||||
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
if (0 == ord($receiverPubKeyHex)) {
|
return;
|
||||||
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
}
|
||||||
$receiverUser = $stateUserTable
|
|
||||||
|
|
||||||
|
if(0 == ord($receiverPubKeyHex)) {
|
||||||
|
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
||||||
|
$receiverUser = $stateUserTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->select(['public_key'])
|
->select(['public_key'])
|
||||||
->contain(false)
|
->contain(false)
|
||||||
->where(['email' => $receiverEmail]);
|
->where(['email' => $receiverEmail]);
|
||||||
|
|
||||||
|
|
||||||
if (!$receiverUser) {
|
if(!$receiverUser) {
|
||||||
$this->Flash->error(__('Diese E-Mail ist mir nicht bekannt, hat dein Empfänger denn schon ein Gradido-Konto?'));
|
$this->Flash->error(__('Diese E-Mail ist mir nicht bekannt, hat dein Empfänger denn schon ein Gradido-Konto?'));
|
||||||
$this->set('timeUsed', microtime(true) - $startTime);
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($receiverUser->public_key)) {
|
if(isset($receiverUser->public_key)) {
|
||||||
$receiverPubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
|
$receiverPubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('Das Konto mit der E-Mail: ' . $receiverEmail . ' wurde noch nicht aktiviert und kann noch keine GDD empfangen!'));
|
$this->Flash->error(__('Das Konto mit der E-Mail: ' . $receiverEmail . ' wurde noch nicht aktiviert und kann noch keine GDD empfangen!'));
|
||||||
$this->set('timeUsed', microtime(true) - $startTime);
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//var_dump($sessionStateUser);
|
|
||||||
|
}
|
||||||
|
//var_dump($sessionStateUser);
|
||||||
|
|
||||||
$builderResult = TransactionTransfer::build(
|
$builderResult = TransactionTransfer::build(
|
||||||
$amountCent,
|
$amountCent,
|
||||||
$requestData['memo'],
|
$requestData['memo'],
|
||||||
$receiverPubKeyHex,
|
$receiverPubKeyHex,
|
||||||
$senderPubKeyHex
|
$senderPubKeyHex
|
||||||
);
|
);
|
||||||
if ($builderResult['state'] === 'success') {
|
if($builderResult['state'] === 'success') {
|
||||||
$http = new Client();
|
|
||||||
try {
|
$http = new Client();
|
||||||
$loginServer = Configure::read('LoginServer');
|
try {
|
||||||
$url = $loginServer['host'] . ':' . $loginServer['port'];
|
$loginServer = Configure::read('LoginServer');
|
||||||
$session_id = $session->read('session_id');
|
$url = $loginServer['host'] . ':' . $loginServer['port'];
|
||||||
/*
|
$session_id = $session->read('session_id');
|
||||||
*
|
/*
|
||||||
* $response = $http->post(
|
*
|
||||||
* 'http://example.com/tasks',
|
* $response = $http->post(
|
||||||
* json_encode($data),
|
* 'http://example.com/tasks',
|
||||||
* ['type' => 'json']
|
* json_encode($data),
|
||||||
* );
|
* ['type' => 'json']
|
||||||
*/
|
* );
|
||||||
$response = $http->post($url . '/checkTransaction', json_encode([
|
*/
|
||||||
'session_id' => $session_id,
|
$response = $http->post($url . '/checkTransaction', json_encode([
|
||||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
'session_id' => $session_id,
|
||||||
'balance' => $user['balance']
|
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||||
]), ['type' => 'json']);
|
'balance' => $user['balance']
|
||||||
$json = $response->getJson();
|
]), ['type' => 'json']);
|
||||||
if ($json['state'] != 'success') {
|
$json = $response->getJson();
|
||||||
if ($json['msg'] == 'session not found') {
|
if($json['state'] != 'success') {
|
||||||
$session->destroy();
|
if($json['msg'] == 'session not found') {
|
||||||
return $this->redirect($this->loginServerUrl . 'account', 303);
|
$session->destroy();
|
||||||
//$this->Flash->error(__('session not found, please login again'));
|
return $this->redirect($this->loginServerUrl . 'account', 303);
|
||||||
} else {
|
//$this->Flash->error(__('session not found, please login again'));
|
||||||
$this->Flash->error(__('login server return error: ' . json_encode($json)));
|
} else {
|
||||||
}
|
$this->Flash->error(__('login server return error: ' . json_encode($json)));
|
||||||
} else {
|
}
|
||||||
$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($this->loginServerUrl . 'account/checkTransactions', 303);
|
|
||||||
} else {
|
|
||||||
$this->Flash->success(__('Transaction submitted for review.'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$msg = $e->getMessage();
|
|
||||||
$this->Flash->error(__('error http request: ') . $msg);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('No Valid Receiver Public given: ' . $receiverPubKeyHex));
|
$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($this->loginServerUrl . 'account/checkTransactions', 303);
|
||||||
|
} else {
|
||||||
|
$this->Flash->success(__('Transaction submitted for review.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// */
|
} catch(\Exception $e) {
|
||||||
|
$msg = $e->getMessage();
|
||||||
|
$this->Flash->error(__('error http request: ') . $msg);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('Something was invalid, please try again!'));
|
$this->Flash->error(__('No Valid Receiver Public given: ' . $receiverPubKeyHex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// */
|
||||||
|
} else {
|
||||||
|
$this->Flash->error(__('Something was invalid, please try again!'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set('timeUsed', microtime(true) - $startTime);
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
@ -291,37 +298,39 @@ class TransactionSendCoinsController extends AppController
|
|||||||
$this->set('transferRawForm', $transferRawForm);
|
$this->set('transferRawForm', $transferRawForm);
|
||||||
|
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
$requestData = $this->request->getData();
|
$requestData = $this->request->getData();
|
||||||
if ($transferRawForm->validate($requestData)) {
|
if($transferRawForm->validate($requestData)) {
|
||||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||||
$sender = ['priv' => $requestData['sender_privkey_hex'], 'pub' => $requestData['sender_pubkey_hex']];
|
$sender = ['priv' => $requestData['sender_privkey_hex'], 'pub' => $requestData['sender_pubkey_hex']];
|
||||||
$reciver = ['pub' => $requestData['receiver_pubkey_hex']];
|
$reciver = ['pub' => $requestData['receiver_pubkey_hex']];
|
||||||
|
|
||||||
$builderResult = TransactionTransfer::build(
|
$builderResult = TransactionTransfer::build(
|
||||||
$amountCent,
|
$amountCent,
|
||||||
$requestData['memo'],
|
$requestData['memo'],
|
||||||
$reciver['pub'],
|
$reciver['pub'],
|
||||||
$sender['pub']
|
$sender['pub']
|
||||||
);
|
);
|
||||||
if ($builderResult['state'] === 'success') {
|
if($builderResult['state'] === 'success') {
|
||||||
$protoTransaction = Transaction::build($builderResult['transactionBody'], $sender);
|
$protoTransaction = Transaction::build($builderResult['transactionBody'], $sender);
|
||||||
$transaction = new Transaction($protoTransaction);
|
$transaction = new Transaction($protoTransaction);
|
||||||
if (!$transaction->validate()) {
|
if(!$transaction->validate()) {
|
||||||
$this->Flash->error(__('Error validating transaction'));
|
$this->Flash->error(__('Error validating transaction'));
|
||||||
} else {
|
} else {
|
||||||
if (!$transaction->save()) {
|
if(!$transaction->save()) {
|
||||||
$this->Flash->error(__('Error saving transaction'));
|
$this->Flash->error(__('Error saving transaction'));
|
||||||
} else {
|
|
||||||
$this->Flash->success(__('Gradidos erfolgreich überwiesen!'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('Error building transaction'));
|
$this->Flash->success(__('Gradidos erfolgreich überwiesen!'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->Flash->error(__('Error building transaction'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
//var_dump($requestData);
|
//var_dump($requestData);
|
||||||
//
|
//
|
||||||
//var_dump($data);
|
//var_dump($data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set('timeUsed', microtime(true) - $startTime);
|
$this->set('timeUsed', microtime(true) - $startTime);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user