Update: 2026-05-06 21:24:56
This commit is contained in:
@@ -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