if email couldn't sended make warning not error and transmit to login-server

This commit is contained in:
Dario Rekowski on RockPI 2021-06-07 14:36:57 +00:00
parent d842884490
commit d2497c9c7c
5 changed files with 31 additions and 4 deletions

View File

@ -387,6 +387,10 @@ class JsonRequestHandlerController extends AppController {
//echo "after validate <br>"; //echo "after validate <br>";
if ($transaction->save()) { if ($transaction->save()) {
$result = ['state' => 'success'];
if($transaction->hasWarnings()) {
$result['warnings'] = $transaction->getWarnings();
}
// success // success
return $this->returnJson(['state' => 'success']); return $this->returnJson(['state' => 'success']);
} else { } else {

View File

@ -25,7 +25,7 @@ class Transaction extends TransactionBase {
//$transactionBin = base64_decode($base64Data, true); //$transactionBin = base64_decode($base64Data, true);
//if($transactionBin == false) { //if($transactionBin == false) {
//sodium_base64_VARIANT_URLSAFE_NO_PADDING //sodium_base64_VARIANT_URLSAFE_NO_PADDING
if(is_a($base64Data, '\Proto\Gradido\Transaction')) { if(is_a($base64Data, '\Proto\Gradido\GradidoTransaction')) {
$this->mProtoTransaction = $base64Data; $this->mProtoTransaction = $base64Data;
$this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes()); $this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes());
return; return;
@ -93,7 +93,11 @@ class Transaction extends TransactionBase {
return $this->mTransactionBody; return $this->mTransactionBody;
} }
public function getFirstPublic() { public function getFirstPublic()
{
if(!$this->mProtoTransaction || !$this->mProtoTransaction->getSigMap()) {
return '';
}
$sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair(); $sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair();
return $sigPairs[0]->getPubKey(); return $sigPairs[0]->getPubKey();
} }
@ -111,6 +115,7 @@ class Transaction extends TransactionBase {
$sigMap = $this->mProtoTransaction->getSigMap(); $sigMap = $this->mProtoTransaction->getSigMap();
if(!$sigMap) { if(!$sigMap) {
$this->addError('Transaction', 'signature map is zero'); $this->addError('Transaction', 'signature map is zero');
//var_dump($this->mProtoTransaction);
return false; return false;
} }
//var_dump($sigMap); //var_dump($sigMap);
@ -193,8 +198,10 @@ class Transaction extends TransactionBase {
$connection->commit(); $connection->commit();
$this->mTransactionBody->getSpecificTransaction()->sendNotificationEmail($this->mTransactionBody->getMemo()); $specificTransaction = $this->mTransactionBody->getSpecificTransaction();
$specificTransaction->sendNotificationEmail($this->mTransactionBody->getMemo());
$this->addWarnings($specificTransaction->getWarnings());
return true; return true;
} }

View File

@ -6,24 +6,38 @@ use Cake\ORM\TableRegistry;
class TransactionBase { class TransactionBase {
private $errors = []; private $errors = [];
private $warnings = [];
static $tables = []; static $tables = [];
public function getErrors() { public function getErrors() {
return $this->errors; return $this->errors;
} }
public function getWarnings() {
return $this->warnings;
}
public function addError($functionName, $errorName) { public function addError($functionName, $errorName) {
array_push($this->errors, [$functionName => $errorName]); array_push($this->errors, [$functionName => $errorName]);
} }
public function addWarning($functionName, $warningName) {
$this->warnings[] = [$functionName => $warningName];
}
public function addErrors($errors) { public function addErrors($errors) {
$this->errors = array_merge($this->errors, $errors); $this->errors = array_merge($this->errors, $errors);
} }
public function addWarnings($warnings) {
$this->warnings = array_merge($this->warnings, $warnings);
}
public function hasErrors() { public function hasErrors() {
return count($this->errors) > 0; return count($this->errors) > 0;
} }
public function hasWarnings() {
return count($this->warnings) > 0;
}
public static function getTable($tableName) { public static function getTable($tableName) {
if(!isset(self::$tables[$tableName])) { if(!isset(self::$tables[$tableName])) {
self::$tables[$tableName] = TableRegistry::getTableLocator()->get($tableName); self::$tables[$tableName] = TableRegistry::getTableLocator()->get($tableName);

View File

@ -209,6 +209,7 @@ class TransactionCreation extends TransactionBase {
->send(); ->send();
} catch(Exception $e) { } catch(Exception $e) {
// $this->addError('TransactionCreation::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage()); // $this->addError('TransactionCreation::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage());
$this->addWarning('TransactionCreation::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage());
return false; return false;
} }
return true; return true;

View File

@ -211,6 +211,7 @@ class TransactionTransfer extends TransactionBase {
->send(); ->send();
} catch(Exception $e) { } catch(Exception $e) {
//$this->addError('TransactionTransfer::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage()); //$this->addError('TransactionTransfer::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage());
$this->addWarning('TransactionTransfer::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage());
return false; return false;
} }
return true; return true;