Allplmpliedl manual JWT check and restored all driver fields68j2

This commit is contained in:
Hamza-Ayed
2026-04-25 21:28:42 +03:00
parent fca292f2a4
commit fadb373d42
6 changed files with 119 additions and 19 deletions

View File

@@ -323,25 +323,28 @@ class AuthController extends Controller
'created_at' => now(),
]);
// 11. Insert Documents
// 11. Insert Documents (Wait, the user said registration response MUST return jwt, api_secret, and hmac immediately to allow subsequent protected file uploads)
// So we don't need to insert documents here if they are uploaded later. But keeping the existing code won't hurt, just the response changes.
$docKeys = [
'driver_license_front', 'driver_license_back',
'car_license_front', 'car_license_back'
];
$docUrls = [];
foreach ($docKeys as $k) {
$url = $request->input($k);
$docUrls[$k] = $url;
$name = basename(parse_url($url, PHP_URL_PATH) ?? '');
if ($name === '') { $name = $k . '_' . time() . '.jpg'; }
if ($request->has($k)) {
$url = $request->input($k);
$docUrls[$k] = $url;
$name = basename(parse_url($url, PHP_URL_PATH) ?? '');
if ($name === '') { $name = $k . '_' . time() . '.jpg'; }
DB::connection('primary')->table('driver_documents')->insert([
'driverID' => $data['id'],
'doc_type' => $k,
'image_name' => $name,
'link' => $url,
'upload_date' => now(),
]);
DB::connection('primary')->table('driver_documents')->insert([
'driverID' => $data['id'],
'doc_type' => $k,
'image_name' => $name,
'link' => $url,
'upload_date' => now(),
]);
}
}
DB::connection('primary')->commit();
@@ -360,11 +363,29 @@ class AuthController extends Controller
\Illuminate\Support\Facades\Log::error("FCM Admin notification failed: " . $e->getMessage());
}
// Generate JWT and API Keys
$fingerprint = $request->input('fingerprint', 'unknown');
$jwt = $this->createJwt($data['id'], 'driver', $fingerprint, 14400);
$apiKey = bin2hex(random_bytes(16));
$apiSecret = bin2hex(random_bytes(32));
DB::connection('primary')->table('driver')->where('id', $data['id'])->update([
'api_key' => $apiKey,
'api_secret' => $apiSecret
]);
// To be compatible with frontend, generate Wallet HMAC
$hmac = hash_hmac('sha256', $jwt, config('intaleq.secret_key_hmac', ''));
return response()->json([
'status' => 'success',
'driverID' => $data['id'],
'carRegID' => $carRegId,
'documents' => $docUrls
'documents' => $docUrls,
'jwt' => $jwt,
'api_key' => $apiKey,
'api_secret' => $apiSecret,
'hmac' => $hmac
]);
} catch (\Exception $e) {