75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/config.php';
|
|
require_once __DIR__ . '/includes/Security.php';
|
|
|
|
echo "=== اختبار نظام إدارة المستخدمين ===\n\n";
|
|
|
|
try {
|
|
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
|
|
|
|
if ($conn->connect_error) {
|
|
throw new Exception("فشل الاتصال: " . $conn->connect_error);
|
|
}
|
|
|
|
// تسجيل مستخدم جديد
|
|
$username = "test_user_" . time();
|
|
$email = "test_" . time() . "@example.com";
|
|
$password = "TestPass123!";
|
|
$hashed_password = Security::hashPassword($password);
|
|
|
|
$stmt = $conn->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
|
|
$stmt->bind_param("sss", $username, $email, $hashed_password);
|
|
|
|
if ($stmt->execute()) {
|
|
$user_id = $conn->insert_id;
|
|
echo "تم تسجيل المستخدم بنجاح (ID: $user_id)\n";
|
|
}
|
|
|
|
// محاولة تسجيل الدخول
|
|
$stmt = $conn->prepare("SELECT * FROM users WHERE email = ?");
|
|
$stmt->bind_param("s", $email);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$user = $result->fetch_assoc();
|
|
|
|
if (Security::verifyPassword($password, $user['password'])) {
|
|
echo "تم تسجيل الدخول بنجاح\n";
|
|
} else {
|
|
echo "فشل تسجيل الدخول\n";
|
|
}
|
|
|
|
// تحديث معلومات المستخدم
|
|
$new_email = "updated_" . time() . "@example.com";
|
|
$stmt = $conn->prepare("UPDATE users SET email = ? WHERE id = ?");
|
|
$stmt->bind_param("si", $new_email, $user_id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo "تم تحديث معلومات المستخدم بنجاح\n";
|
|
}
|
|
|
|
// التحقق من التحديث
|
|
$stmt = $conn->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->bind_param("i", $user_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$updated_user = $result->fetch_assoc();
|
|
|
|
echo "\nمعلومات المستخدم المحدثة:\n";
|
|
echo "اسم المستخدم: " . $updated_user['username'] . "\n";
|
|
echo "البريد الإلكتروني: " . $updated_user['email'] . "\n";
|
|
echo "نوع المستخدم: " . $updated_user['role'] . "\n";
|
|
|
|
// تنظيف البيانات
|
|
$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
|
|
$stmt->bind_param("i", $user_id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo "\nتم حذف بيانات الاختبار بنجاح\n";
|
|
}
|
|
|
|
$conn->close();
|
|
|
|
} catch (Exception $e) {
|
|
echo "خطأ: " . $e->getMessage() . "\n";
|
|
}
|