Update: 2026-05-03 23:57:27

This commit is contained in:
Hamza-Ayed
2026-05-03 23:57:27 +03:00
parent bef134ea77
commit b6db8da450
4 changed files with 425 additions and 7 deletions

View File

@@ -46,11 +46,22 @@ $encryptedName = Encryption::encrypt($data['name']);
$encryptedEmail = Encryption::encrypt($data['email']);
$emailHash = hash('sha256', strtolower($data['email'])); // For fast lookup during login
// 3. Determine Tenant ID
$tenantId = null;
if ($decoded['role'] === 'super_admin') {
if (empty($data['tenant_id'])) {
json_error('يجب اختيار المكتب المحاسبي', 422);
}
$tenantId = $data['tenant_id'];
} else {
$tenantId = $decoded['tenant_id'];
}
// 4. Save to Database
try {
$stmt = $db->prepare("INSERT INTO users (tenant_id, name, email, email_hash, password_hash, role, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([
$decoded['tenant_id'],
$tenantId,
$encryptedName,
$encryptedEmail,
$emailHash,