Update: 2026-05-25 21:44:11
This commit is contained in:
@@ -18,8 +18,8 @@ $data = input();
|
||||
$errors = Validator::validate($data, [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
'phone' => 'required',
|
||||
'manager_name' => 'required',
|
||||
'manager_email' => 'required|email',
|
||||
'manager_password' => 'required'
|
||||
]);
|
||||
|
||||
@@ -43,12 +43,23 @@ try {
|
||||
$encryptedTenantName = \App\Core\Encryption::encrypt($data['name']);
|
||||
$encryptedTenantEmail = \App\Core\Encryption::encrypt($data['email']);
|
||||
|
||||
$phone = preg_replace('/[^0-9+]/', '', $data['phone']);
|
||||
$phone = ltrim($phone, '+');
|
||||
if (str_starts_with($phone, '07')) {
|
||||
$phone = '962' . substr($phone, 1);
|
||||
} elseif (str_starts_with($phone, '7')) {
|
||||
$phone = '962' . $phone;
|
||||
}
|
||||
|
||||
$encryptedPhone = \App\Core\Encryption::encrypt($phone);
|
||||
$phoneHash = hash('sha256', $phone);
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO tenants (id, name, email, phone, status, created_at) VALUES (?, ?, ?, ?, 'active', NOW())");
|
||||
$stmt->execute([
|
||||
$tenantId,
|
||||
$encryptedTenantName,
|
||||
$encryptedTenantEmail,
|
||||
$data['phone'] ?? null
|
||||
$phone
|
||||
]);
|
||||
|
||||
// Generate User UUID
|
||||
@@ -60,17 +71,19 @@ try {
|
||||
|
||||
// Encrypt sensitive user data
|
||||
$encryptedName = \App\Core\Encryption::encrypt($data['manager_name']);
|
||||
$encryptedEmail = \App\Core\Encryption::encrypt($data['manager_email']);
|
||||
$emailHash = hash('sha256', strtolower($data['manager_email']));
|
||||
$encryptedEmail = \App\Core\Encryption::encrypt($data['email']);
|
||||
$emailHash = hash('sha256', strtolower($data['email']));
|
||||
|
||||
// 2. Create Initial Manager (Admin) for this Tenant
|
||||
$stmtUser = $db->prepare("INSERT INTO users (id, tenant_id, name, email, email_hash, password_hash, role, created_at) VALUES (?, ?, ?, ?, ?, ?, 'admin', NOW())");
|
||||
$stmtUser = $db->prepare("INSERT INTO users (id, tenant_id, name, email, email_hash, phone, phone_hash, password_hash, role, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'admin', NOW())");
|
||||
$stmtUser->execute([
|
||||
$userId,
|
||||
$tenantId,
|
||||
$encryptedName,
|
||||
$encryptedEmail,
|
||||
$emailHash,
|
||||
$encryptedPhone,
|
||||
$phoneHash,
|
||||
password_hash($data['manager_password'], PASSWORD_DEFAULT)
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user