mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
request handler allow only specific clients
This commit is contained in:
parent
ed963059a6
commit
f7f9d0ddb8
@ -22,6 +22,8 @@ use Cake\Routing\RouteBuilder;
|
||||
use Cake\Routing\Router;
|
||||
use Cake\Routing\Route\DashedRoute;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
|
||||
/**
|
||||
* The default class to use for all routes
|
||||
*
|
||||
@ -58,7 +60,18 @@ Router::scope('/', function (RouteBuilder $routes) {
|
||||
$whitelist = ['JsonRequestHandler', 'ElopageWebhook'];
|
||||
foreach($whitelist as $entry) {
|
||||
if($request->getParam('controller') === $entry) {
|
||||
if($entry == 'ElopageWebhook') {
|
||||
return true;
|
||||
}
|
||||
if($request->clientIp() == '127.0.0.1' || $request->clientIp() == 'localhost') {
|
||||
return true;
|
||||
}
|
||||
$allowedCaller = Configure::read('API.allowedCaller');
|
||||
$callerIp = $request->clientIp();
|
||||
foreach($allowedCaller as $allowed) {
|
||||
$ip = gethostbyname($allowed);
|
||||
if($ip === $callerIp) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -57,6 +57,7 @@ class JsonRequestHandlerController extends AppController {
|
||||
case 'moveTransaction': return $this->moveTransaction($jsonData->pubkeys, $jsonData->memo, $jsonData->session_id);
|
||||
case 'checkUser': return $this->checkUser($jsonData->email, $jsonData->last_name);
|
||||
case 'getUsers' : return $this->getUsers($jsonData->page, $jsonData->limit);
|
||||
case 'getUserBalance': return $this->getUserBalance($jsonData->email, $jsonData->last_name);
|
||||
}
|
||||
return $this->returnJson(['state' => 'error', 'msg' => 'unknown method for post', 'details' => $method]);
|
||||
}
|
||||
@ -163,6 +164,24 @@ class JsonRequestHandlerController extends AppController {
|
||||
return $this->returnJson(['state' => 'not identical', 'user' => $user->toArray()]);
|
||||
}
|
||||
|
||||
private function getUserBalance($email, $last_name) {
|
||||
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
||||
$stateUsers = $stateUserTable->find('all')->where(['OR' => ['email' => $email, 'last_name' => $last_name]])->contain(['StateBalances']);
|
||||
$gdds = [];
|
||||
foreach($stateUsers as $stateUser) {
|
||||
foreach($stateUser->StateBalances as $stateBalance) {
|
||||
if(!isset($gdds[$stateBalance->email])) {
|
||||
$gdds[$stateBalance->email];
|
||||
}
|
||||
if(!isset($gdds[$stateBalance->email][$stateBalance->last_name])) {
|
||||
$gdds[$stateBalance->email][$stateBalance->last_name] = 0;
|
||||
}
|
||||
$gdds[$stateBalance->email][$stateBalance->last_name] += $stateBalance->amount;
|
||||
}
|
||||
}
|
||||
return $this->returnJson(['state' => 'success', 'gdds' => $gdds, 'stateUsers' => $stateUsers]);
|
||||
}
|
||||
|
||||
private function getUsers($page, $count) {
|
||||
|
||||
$userTable = TableRegistry::getTableLocator()->get('Users');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user