Update: 2026-07-30 02:27:45
This commit is contained in:
@@ -88,16 +88,25 @@ try {
|
||||
date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
json_success(null, 'تم إضافة المستخدم بنجاح');
|
||||
|
||||
// Audit BEFORE responding: json_success() calls exit(), so anything after it
|
||||
// never ran and user creation was never recorded in the audit log.
|
||||
AuditLogger::log('user.created', 'user', null, null, [
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'role' => $data['role'],
|
||||
], $decoded);
|
||||
|
||||
json_success(null, 'تم إضافة المستخدم بنجاح');
|
||||
} catch (\Exception $e) {
|
||||
if (str_contains($e->getMessage(), 'Duplicate entry')) {
|
||||
$msg = $e->getMessage();
|
||||
if (str_contains($msg, 'Duplicate entry')) {
|
||||
// Say which field actually collided - reporting "email" for a duplicate
|
||||
// phone sent admins hunting for the wrong problem.
|
||||
if (str_contains($msg, 'phone')) {
|
||||
json_error('رقم الهاتف مسجل مسبقاً لمستخدم آخر', 409);
|
||||
}
|
||||
json_error('البريد الإلكتروني مسجل مسبقاً', 409);
|
||||
}
|
||||
error_log('[users/create] ' . $msg);
|
||||
json_error('حدث خطأ أثناء حفظ البيانات', 500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user