FEAT_API_RATE_LIMIT&GOOGLE_SHEET_POC
This commit is contained in:
parent
43bec44d07
commit
5177acc3a4
@ -20,6 +20,8 @@ use App\Filters\SecurityInputFilter;
|
|||||||
use App\Filters\GlobalPostFileUploadGuard;
|
use App\Filters\GlobalPostFileUploadGuard;
|
||||||
use App\Filters\AclFilter;
|
use App\Filters\AclFilter;
|
||||||
use App\Filters\RateLimitFilter;
|
use App\Filters\RateLimitFilter;
|
||||||
|
use App\Filters\JwtApiRateLimitFilter;
|
||||||
|
use App\Filters\AuthApiRateLimitFilter;
|
||||||
|
|
||||||
use App\Filters\AuthJWT;
|
use App\Filters\AuthJWT;
|
||||||
|
|
||||||
@ -51,6 +53,8 @@ class Filters extends BaseConfig
|
|||||||
'GlobalPostFileUploadGuard' => GlobalPostFileUploadGuard::class,
|
'GlobalPostFileUploadGuard' => GlobalPostFileUploadGuard::class,
|
||||||
'AclFilter' => AclFilter::class,
|
'AclFilter' => AclFilter::class,
|
||||||
'ratelimit' => RateLimitFilter::class,
|
'ratelimit' => RateLimitFilter::class,
|
||||||
|
'AuthApiRateLimitFilter' => AuthApiRateLimitFilter::class,
|
||||||
|
'JwtApiRateLimitFilter' => JwtApiRateLimitFilter::class,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,15 @@ $routes->options('(:any)', function() {
|
|||||||
// But having this route ensures OPTIONS isn't rejected as 404
|
// But having this route ensures OPTIONS isn't rejected as 404
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$routes->group('sheet', function ($routes) {
|
||||||
|
$routes->get('(:any)', 'GoogleSheetController::editor/$1');
|
||||||
|
$routes->get('(:any)/fetch', 'GoogleSheetController::fetch/$1');
|
||||||
|
$routes->post('(:any)/save', 'GoogleSheetController::save/$1');
|
||||||
|
$routes->get('(:any)/download', 'GoogleSheetController::download/$1');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var RouteCollection $routes
|
* @var RouteCollection $routes
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -3669,7 +3669,7 @@ class EmployeeController extends AdminController
|
|||||||
"policyStartDate" => $policyStartDate,
|
"policyStartDate" => $policyStartDate,
|
||||||
"policyEndDate" => $policyEndDate,
|
"policyEndDate" => $policyEndDate,
|
||||||
"plan" => $primary["wellness_plan_id"] ?? null,
|
"plan" => $primary["wellness_plan_id"] ?? null,
|
||||||
"source" => $primary['short_name'] ?? null,
|
"source" => 'NHANCE',
|
||||||
"employer" => $primary['short_name'] ?? null,
|
"employer" => $primary['short_name'] ?? null,
|
||||||
"employeeCode" => $empCode,
|
"employeeCode" => $empCode,
|
||||||
"accountNumber" => "", // Fill from DB if available
|
"accountNumber" => "", // Fill from DB if available
|
||||||
@ -3690,8 +3690,8 @@ class EmployeeController extends AdminController
|
|||||||
"name" => $row["name"],
|
"name" => $row["name"],
|
||||||
"phone" => $row["mobile"],
|
"phone" => $row["mobile"],
|
||||||
"email" => $row["email_corporate"],
|
"email" => $row["email_corporate"],
|
||||||
"relationshipName" => strtoupper($row["relationship"] ?? ''),
|
"relationshipName" => $this->mapRelationship($row["relationship"],$row["gender"]),
|
||||||
"gender" => $row["gender"],
|
"gender" => $row["gender"] == 'M' ? 'Male' : 'Female',
|
||||||
"dob" => $row["dob"]
|
"dob" => $row["dob"]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -3700,6 +3700,42 @@ class EmployeeController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function mapRelationship(string $relationship, ?string $gender = null): string
|
||||||
|
{
|
||||||
|
// Normalize input
|
||||||
|
$key = strtolower(trim($relationship));
|
||||||
|
$key = str_replace(['-', '_'], ' ', $key);
|
||||||
|
$key = preg_replace('/\s+/', ' ', $key);
|
||||||
|
|
||||||
|
// Base mapping
|
||||||
|
$map = [
|
||||||
|
'self' => 'self',
|
||||||
|
'son' => 'son',
|
||||||
|
'daughter' => 'daughter',
|
||||||
|
'father' => 'father',
|
||||||
|
'mother' => 'mother',
|
||||||
|
'father in law' => 'father in law',
|
||||||
|
'father-in-law' => 'father in law',
|
||||||
|
'mother in law' => 'mother in law',
|
||||||
|
'mother-in-law' => 'mother in law',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Special handling for spouse
|
||||||
|
if ($key === 'spouse') {
|
||||||
|
if ($gender === 'M') {
|
||||||
|
return 'husband';
|
||||||
|
}
|
||||||
|
if ($gender === 'F') {
|
||||||
|
return 'wife';
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback if gender missing (better to throw error)
|
||||||
|
throw new Exception("Gender required to map 'Spouse'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map[$key] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send each family payload to API and attach the response
|
* Send each family payload to API and attach the response
|
||||||
|
|||||||
@ -15,6 +15,7 @@ class HttpRequestHelper
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'ip' => $request->getIPAddress(),
|
'ip' => $request->getIPAddress(),
|
||||||
|
'real_ip' => getRealClientIP(),
|
||||||
'platform' => $platform,
|
'platform' => $platform,
|
||||||
'browser' => $browser,
|
'browser' => $browser,
|
||||||
'method' => strtoupper($request->getMethod()),
|
'method' => strtoupper($request->getMethod()),
|
||||||
|
|||||||
@ -1069,22 +1069,39 @@ function getRealClientIP()
|
|||||||
return $request->getIPAddress();
|
return $request->getIPAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateFingerprint()
|
function generateFingerprint(): string
|
||||||
{
|
{
|
||||||
$request = service('request');
|
$request = service('request');
|
||||||
|
|
||||||
$ua = $request->getUserAgent()->getAgentString();
|
$ua = $request->getUserAgent()->getAgentString();
|
||||||
$ip = getRealClientIP();
|
$ip = getRealClientIP();
|
||||||
|
|
||||||
// Use only subnet (first 3 blocks) to tolerate IP change
|
// Normalize localhost
|
||||||
$ipParts = explode('.', $ip);
|
if ($ip === '127.0.0.1' || $ip === '::1') {
|
||||||
$ipSubnet = $ipParts[0] . '.' . $ipParts[1] . '.' . $ipParts[2];
|
$ipGroup = 'localhost';
|
||||||
|
|
||||||
// $secret = env('app.sessionFingerprintSalt');
|
|
||||||
|
|
||||||
// return hash('sha256', $ua . '|' . $ipSubnet . '|' . $secret);
|
|
||||||
return hash('sha256', $ua . '|' . $ipSubnet );
|
|
||||||
}
|
}
|
||||||
|
// IPv4 handling
|
||||||
|
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||||
|
$parts = explode('.', $ip);
|
||||||
|
// Use /24 subnet (first 3 octets)
|
||||||
|
$ipGroup = $parts[0] . '.' . $parts[1] . '.' . $parts[2];
|
||||||
|
}
|
||||||
|
// IPv6 handling
|
||||||
|
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||||
|
// Use first 4 blocks of IPv6 (rough /64 grouping)
|
||||||
|
$blocks = explode(':', $ip);
|
||||||
|
$ipGroup = implode(':', array_slice($blocks, 0, 4));
|
||||||
|
}
|
||||||
|
// Fallback
|
||||||
|
else {
|
||||||
|
$ipGroup = 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash('sha256', $ua . '|' . $ipGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('convertGoogleDriveToDownloadLink')) {
|
if (!function_exists('convertGoogleDriveToDownloadLink')) {
|
||||||
function convertGoogleDriveToDownloadLink(?string $url): ?string
|
function convertGoogleDriveToDownloadLink(?string $url): ?string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user