Update: 2026-05-06 21:24:56
This commit is contained in:
@@ -19,6 +19,10 @@ class Cache
|
||||
$pass = env('REDIS_PASSWORD', null);
|
||||
|
||||
try {
|
||||
if (!class_exists('\Predis\Client')) {
|
||||
throw new \Exception('Predis client is not installed. Please run composer install.');
|
||||
}
|
||||
|
||||
self::$client = new \Predis\Client([
|
||||
'scheme' => 'tcp',
|
||||
'host' => $host,
|
||||
@@ -26,7 +30,7 @@ class Cache
|
||||
'password' => $pass,
|
||||
]);
|
||||
self::$client->connect();
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) { // Catch \Throwable instead of \Exception to catch fatal class errors
|
||||
error_log("Redis Connection Error: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,12 @@ define('STORAGE_PATH', ROOT_PATH . '/storage');
|
||||
require_once APP_PATH . '/bootstrap/env.php';
|
||||
require_once APP_PATH . '/helpers/helpers.php';
|
||||
|
||||
// Load Composer Autoloader
|
||||
$vendorAutoload = ROOT_PATH . '/vendor/autoload.php';
|
||||
if (file_exists($vendorAutoload)) {
|
||||
require_once $vendorAutoload;
|
||||
}
|
||||
|
||||
// Self-healing Storage
|
||||
$dirs = ['/cache', '/logs', '/invoices', '/exports'];
|
||||
foreach ($dirs as $d) {
|
||||
|
||||
@@ -41,10 +41,14 @@ try {
|
||||
$stmt->execute([$phoneHash]);
|
||||
$user = $stmt->fetch();
|
||||
} catch (\PDOException $e) {
|
||||
// Fallback to searching by plain phone if phone_hash column doesn't exist
|
||||
$stmt = $db->prepare("SELECT id, tenant_id, name, is_active FROM users WHERE phone = ? LIMIT 1");
|
||||
$stmt->execute([$phone]);
|
||||
$user = $stmt->fetch();
|
||||
try {
|
||||
// Fallback to searching by plain phone if phone_hash column doesn't exist
|
||||
$stmt = $db->prepare("SELECT id, tenant_id, name, is_active FROM users WHERE phone = ? LIMIT 1");
|
||||
$stmt->execute([$phone]);
|
||||
$user = $stmt->fetch();
|
||||
} catch (\PDOException $fallbackException) {
|
||||
json_error('حدث خطأ في قاعدة البيانات: ' . $fallbackException->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
|
||||
@@ -30,6 +30,7 @@ if (!in_array($data['role'] ?? '', $allowedRoles, true)) {
|
||||
$errors = Validator::validate($data, [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
'phone' => 'required',
|
||||
'password' => 'required',
|
||||
'role' => 'required'
|
||||
]);
|
||||
@@ -45,6 +46,9 @@ $encryptedName = Encryption::encrypt($data['name']);
|
||||
$encryptedEmail = Encryption::encrypt($data['email']);
|
||||
$emailHash = hash('sha256', strtolower($data['email'])); // For fast lookup during login
|
||||
|
||||
$encryptedPhone = Encryption::encrypt($data['phone']);
|
||||
$phoneHash = hash('sha256', preg_replace('/[^0-9+]/', '', $data['phone']));
|
||||
|
||||
// 3. Determine Tenant ID
|
||||
$tenantId = null;
|
||||
if ($decoded['role'] === 'super_admin') {
|
||||
@@ -62,13 +66,15 @@ if ($decoded['role'] === 'super_admin') {
|
||||
|
||||
// 4. Save to Database
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO users (id, tenant_id, name, email, email_hash, password_hash, role, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt = $db->prepare("INSERT INTO users (id, tenant_id, name, email, email_hash, phone, phone_hash, password_hash, role, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([
|
||||
\App\Core\Database::generateUuid(),
|
||||
$tenantId,
|
||||
$encryptedName,
|
||||
$encryptedEmail,
|
||||
$emailHash,
|
||||
$encryptedPhone,
|
||||
$phoneHash,
|
||||
password_hash($data['password'], PASSWORD_DEFAULT),
|
||||
$data['role'],
|
||||
date('Y-m-d H:i:s')
|
||||
|
||||
Reference in New Issue
Block a user