Update codebase

This commit is contained in:
Hamza-Ayed
2026-08-09 16:56:13 +03:00
parent 95e2e4f35d
commit b64debaa88
1058 changed files with 164327 additions and 113928 deletions
+214
View File
@@ -0,0 +1,214 @@
<?php
/**
* scripts/seed_tester_accounts.php
*
* ينشئ (أو يعيد تعيين كلمة مرور) حسابَي الفحص المخصصين لمراجعي المتاجر:
* راكب واحد وسائق واحد، بالبريدين الموجودين في ALLOWED_TESTER_EMAILS.
*
* الاستخدام:
* php seed_tester_accounts.php --password='...' # كلمة مرور واحدة للحسابين
* php seed_tester_accounts.php --passenger-password='...' --driver-password='...'
* php seed_tester_accounts.php --password='...' --dry-run # عرض ما سيحدث دون كتابة
*
* ملاحظات:
* - آمن لإعادة التشغيل: إن وُجد الحساب فيُحدَّث الباسورد فقط، دون إنشاء سجل ثانٍ.
* - يضبط سجل تحقق الهاتف على verified/is_verified = 1 حتى لا يُحجب الدخول.
* - كلمة المرور تُخزَّن بـ password_hash (bcrypt) لتطابق password_verify في مسار الدخول.
*/
declare(strict_types=1);
if (PHP_SAPI !== 'cli') {
http_response_code(403);
exit("This script runs from the command line only.\n");
}
require_once __DIR__ . '/../core/bootstrap.php';
$options = getopt('', ['dry-run', 'password::', 'passenger-password::', 'driver-password::']);
$dryRun = isset($options['dry-run']);
$sharedPassword = $options['password'] ?? null;
$passengerPassword = $options['passenger-password'] ?? $sharedPassword;
$driverPassword = $options['driver-password'] ?? $sharedPassword;
if (!$passengerPassword || !$driverPassword) {
exit("✘ مطلوب --password أو (--passenger-password و --driver-password).\n");
}
if (strlen($passengerPassword) < 8 || strlen($driverPassword) < 8) {
exit("✘ كلمة المرور يجب أن تكون 8 محارف على الأقل.\n");
}
/** @var EncryptionHelper $encryptionHelper */
global $encryptionHelper, $blindIndex;
// البريدان يجب أن يطابقا القائمة البيضاء في مسارَي الدخول حرفياً
$allowedEnv = getenv('ALLOWED_TESTER_EMAILS') ?: ($_ENV['ALLOWED_TESTER_EMAILS'] ?? '');
$allowed = array_values(array_filter(array_map(
fn($e) => strtolower(trim($e)),
explode(',', $allowedEnv)
)));
if (empty($allowed)) {
$allowed = ['driver_tester@siromove.com', 'passenger_tester@siromove.com'];
}
$passengerEmail = null;
$driverEmail = null;
foreach ($allowed as $e) {
if ($driverEmail === null && str_contains($e, 'driver')) {
$driverEmail = $e;
} elseif ($passengerEmail === null) {
$passengerEmail = $e;
}
}
if (!$passengerEmail || !$driverEmail) {
exit("✘ ALLOWED_TESTER_EMAILS يجب أن يحتوي بريد سائق (يتضمن 'driver') وبريد راكب.\n");
}
$passengerPhone = '+963900000000';
$driverPhone = '+963900000001';
$con = Database::get('main');
echo ($dryRun ? "— وضع المعاينة (لا كتابة) —\n" : "— تنفيذ فعلي —\n");
// ── الراكب ────────────────────────────────────────────────
$emailEnc = $encryptionHelper->encryptData($passengerEmail);
$emailBidx = $blindIndex ? $blindIndex->index('passengers.email', $passengerEmail) : null;
$hash = password_hash($passengerPassword, PASSWORD_BCRYPT);
$stmt = $con->prepare(
"SELECT id FROM passengers WHERE email = ? OR (? IS NOT NULL AND email_bidx = ?) LIMIT 1"
);
$stmt->execute([$emailEnc, $emailBidx, $emailBidx]);
$existing = $stmt->fetchColumn();
$phoneKey = otpPhoneKey($passengerPhone);
if ($existing) {
echo "• الراكب $passengerEmail موجود (id=$existing) — إعادة تعيين الباسورد.\n";
if (!$dryRun) {
$con->prepare("UPDATE passengers SET password = ?, updated_at = NOW() WHERE id = ?")
->execute([$hash, $existing]);
}
$passengerId = $existing;
} else {
$passengerId = substr(md5(uniqid((string) mt_rand(), true)), 0, 20);
echo "• إنشاء الراكب $passengerEmail (id=$passengerId).\n";
if (!$dryRun) {
$unknown = $encryptionHelper->encryptData('unknown');
$con->prepare("
INSERT INTO passengers
(id, first_name, last_name, email, phone, password, gender, birthdate, site,
sosPhone, education, employmentType, maritalStatus, status, created_at, updated_at,
phone_bidx, email_bidx, name_bidx, phone_key)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', NOW(), NOW(), ?, ?, ?, ?)
")->execute([
$passengerId,
$encryptionHelper->encryptData('Siro'),
$encryptionHelper->encryptData('Tester'),
$emailEnc,
$encryptionHelper->encryptData($passengerPhone),
$hash,
$unknown, $unknown, $unknown, $unknown, $unknown, $unknown, $unknown,
$blindIndex ? $blindIndex->index('passengers.phone', $passengerPhone) : null,
$emailBidx,
$blindIndex ? $blindIndex->index('passengers.name', 'Siro Tester') : null,
$phoneKey,
]);
}
}
// سجل تحقق الهاتف للراكب — الدخول يقرأ verified من هذا الجدول
$stmt = $con->prepare("SELECT id FROM phone_verification_passenger WHERE phone_number = ? LIMIT 1");
$stmt->execute([$phoneKey]);
$verifRow = $stmt->fetchColumn();
if ($verifRow) {
echo " ↳ تحديث سجل التحقق (verified = 1).\n";
if (!$dryRun) {
$con->prepare("UPDATE phone_verification_passenger SET verified = 1, status = 'verified' WHERE id = ?")
->execute([$verifRow]);
}
} else {
echo " ↳ إنشاء سجل التحقق (verified = 1).\n";
if (!$dryRun) {
$con->prepare("
INSERT INTO phone_verification_passenger (phone_number, verified, status, created_at)
VALUES (?, 1, 'verified', NOW())
")->execute([$phoneKey]);
}
}
// ── السائق ────────────────────────────────────────────────
$dEmailEnc = $encryptionHelper->encryptData($driverEmail);
$dEmailBidx = $blindIndex ? $blindIndex->index('driver.email', $driverEmail) : null;
$dHash = password_hash($driverPassword, PASSWORD_BCRYPT);
$stmt = $con->prepare(
"SELECT id FROM driver WHERE email = ? OR (? IS NOT NULL AND email_bidx = ?) LIMIT 1"
);
$stmt->execute([$dEmailEnc, $dEmailBidx, $dEmailBidx]);
$existingDriver = $stmt->fetchColumn();
$dPhoneKey = otpPhoneKey($driverPhone);
if ($existingDriver) {
echo "• السائق $driverEmail موجود (id=$existingDriver) — إعادة تعيين الباسورد.\n";
if (!$dryRun) {
$con->prepare("UPDATE driver SET password = ?, updated_at = NOW() WHERE id = ?")
->execute([$dHash, $existingDriver]);
}
$driverId = $existingDriver;
} else {
$driverId = substr(md5(uniqid((string) mt_rand(), true)), 0, 20);
echo "• إنشاء السائق $driverEmail (id=$driverId).\n";
if (!$dryRun) {
$con->prepare("
INSERT INTO driver
(id, phone, email, password, gender, license_type, national_number, name_arabic,
issue_date, expiry_date, license_categories, address, licenseIssueDate, status,
birthdate, site, first_name, last_name, created_at, updated_at,
phone_bidx, email_bidx, name_bidx, phone_key)
VALUES (?, ?, ?, ?, 'Male', 'private', ?, ?, '2020-01-01', '2030-01-01', 'B',
'Damascus', '2020-01-01', 'notDeleted', ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?, ?)
")->execute([
$driverId,
$encryptionHelper->encryptData($driverPhone),
$dEmailEnc,
$dHash,
$encryptionHelper->encryptData('00000000'),
'سيرو فاحص',
$encryptionHelper->encryptData('1990-01-01'),
$encryptionHelper->encryptData('Damascus'),
$encryptionHelper->encryptData('Siro'),
$encryptionHelper->encryptData('Captain'),
$blindIndex ? $blindIndex->index('driver.phone', $driverPhone) : null,
$dEmailBidx,
$blindIndex ? $blindIndex->index('driver.name', 'Siro Captain') : null,
$dPhoneKey,
]);
}
}
// سجل تحقق الهاتف للسائق
$stmt = $con->prepare("SELECT id FROM phone_verification WHERE phone_number = ? LIMIT 1");
$stmt->execute([$dPhoneKey]);
$dVerifRow = $stmt->fetchColumn();
if ($dVerifRow) {
echo " ↳ تحديث سجل التحقق (is_verified = 1).\n";
if (!$dryRun) {
$con->prepare("UPDATE phone_verification SET is_verified = 1, driverId = ? WHERE id = ?")
->execute([$driverId, $dVerifRow]);
}
} else {
echo " ↳ إنشاء سجل التحقق (is_verified = 1).\n";
if (!$dryRun) {
$con->prepare("
INSERT INTO phone_verification (phone_number, driverId, email, is_verified, created_at)
VALUES (?, ?, ?, 1, NOW())
")->execute([$dPhoneKey, $driverId, $dEmailEnc]);
}
}
echo "\n✔ تم." . ($dryRun ? " (معاينة فقط — أعد التشغيل دون --dry-run للكتابة)" : "") . "\n";
echo "سلّم للمتجر: $passengerEmail و $driverEmail مع كلمتَي المرور المستخدمتين أعلاه.\n";