Restore AppController

This commit is contained in:
Christine Slotty 2020-07-10 13:47:58 +02:00
parent a27a5af25f
commit 994fc42fac

View File

@ -54,28 +54,6 @@ public function initialize()
$this->loadComponent('Flash'); $this->loadComponent('Flash');
$this->loadComponent('Auth', [ $this->loadComponent('Auth', [
<<<<<<< Updated upstream
'loginAction' => [
'controller' => 'ServerUsers',
'action' => 'login'
],
'loginRedirect' => [
'controller' => 'Transactions',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display',
'gradido'
],
'authenticate' => [
'all' => ['userModel' => 'ServerUsers'],
'Form' => [
'userModel' => 'ServerUsers',
]
]
=======
'loginAction' => [ 'loginAction' => [
'controller' => 'ServerUsers', 'controller' => 'ServerUsers',
'action' => 'login' 'action' => 'login'
@ -159,6 +137,8 @@ public function initialize()
} else { } else {
$this->loginServerUrl = Router::url('/', true); $this->loginServerUrl = Router::url('/', true);
} }
} }
protected function requestLogin() protected function requestLogin()
@ -178,27 +158,24 @@ if (!$session->check('client_ip')) {
if($session_id != 0) { if($session_id != 0) {
$userStored = $session->read('StateUser'); $userStored = $session->read('StateUser');
$transactionPendings = $session->read('Transactions.pending'); $transactionPendings = $session->read('Transactions.pending');
$transactionExecutings = $session->read('Transaction.executing'); $transactionExecutings = $session->read('Transaction.executing');
if($session->read('session_id') != $session_id || if($session->read('session_id') != $session_id ||
( $userStored && (!isset($userStored['id']) || !$userStored['email_checked'])) || ( $userStored && (!isset($userStored['id']) || !$userStored['email_checked'])) ||
intval($transactionPendings) > 0 || intval($transactionPendings) > 0 ||
intval($transactionExecutings) > 0 ) { intval($transactionExecutings) > 0 ) {
$http = new Client(); $http = new Client();
try { try {
$url = $loginServer['host'] . ':' . $loginServer['port']; $url = $loginServer['host'] . ':' . $loginServer['port'];
( $userStored && !isset($userStored['id'])) ||
intval($transactionPendings) > 0 ||
intval($transactionExecutings) > 0) {
$http = new Client();
try {
$url = $loginServer['host'] . ':' . $loginServer['port'];
$response = $http->get($url . '/login', ['session_id' => $session_id]); $response = $http->get($url . '/login', ['session_id' => $session_id]);
$json = $response->getJson(); $json = $response->getJson();
if(isset($json) && count($json) > 0) { if(isset($json) && count($json) > 0) {
if($json['state'] === 'success') { if($json['state'] === 'success') {
//echo "email checked: " . $json['user']['email_checked'] . "; <br>"; //echo "email checked: " . $json['user']['email_checked'] . "; <br>";
if($session->read('session_id') != $session_id || if($session->read('session_id') != $session_id ||
@ -295,8 +272,7 @@ if ($session_id != 0) {
} }
*/ */
public function addAdminError($controller, $action, array $returnTable, $state_user_id) public function addAdminError($controller, $action, array $returnTable, $state_user_id) {
{
if(!is_array($returnTable)) { if(!is_array($returnTable)) {
$this->addAdminError('AppController', 'addAdminError', ['state' => 'error', 'msg' => 'returnTable isn\'t array', 'details' => gettype($returnTable)], $state_user_id); $this->addAdminError('AppController', 'addAdminError', ['state' => 'error', 'msg' => 'returnTable isn\'t array', 'details' => gettype($returnTable)], $state_user_id);
return false; return false;
@ -320,27 +296,24 @@ if ($session_id != 0) {
if(!$adminErrorTable->save($adminErrorEntity)) { if(!$adminErrorTable->save($adminErrorEntity)) {
$this->Flash->error( $this->Flash->error(
__('Serious error, couldn\'t save to db, please write the admin: ' . $this->getAdminEmailLink()), __('Serious error, couldn\'t save to db, please write the admin: ' . $this->getAdminEmailLink()),
['escape' => false] ['escape' => false]);
);
} }
return true; return true;
} }
public function getAdminEmailLink($text = '') public function getAdminEmailLink($text = '') {
{
$serverAdminEmail = Configure::read('ServerAdminEmail'); $serverAdminEmail = Configure::read('ServerAdminEmail');
return '<a href="mailto:' . $serverAdminEmail . '">'. $serverAdminEmail . '</a>'; return '<a href="mailto:' . $serverAdminEmail . '">'. $serverAdminEmail . '</a>';
} }
public function returnJsonEncoded($json) public function returnJsonEncoded($json) {
{
$this->autoRender = false; $this->autoRender = false;
$response = $this->response->withType('application/json'); $response = $this->response->withType('application/json');
return $response->withStringBody($json); return $response->withStringBody($json);
} }
public function returnJson($array) public function returnJson($array) {
{
$this->autoRender = false; $this->autoRender = false;
$response = $this->response->withType('application/json'); $response = $this->response->withType('application/json');
return $response->withStringBody(json_encode($array)); return $response->withStringBody(json_encode($array));
@ -354,4 +327,5 @@ if ($session_id != 0) {
$lastDay = $lastDay->addMonth(1); $lastDay = $lastDay->addMonth(1);
return [$firstDay, $lastDay]; return [$firstDay, $lastDay];
} }
} }