<?php
// /admission33333/committee_login.php — secure login with all fixes
// نسخة محسنة وآمنة مع معالجة جميع التحذيرات

/* ===== Debug toggle: add ?debug=1 to see errors on page ===== */
$DEBUG = isset($_GET['debug']) && $_GET['debug'] === '1';
if ($DEBUG) {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    header("Content-Type: text/html; charset=UTF-8");
} else {
    error_reporting(0); // لا تعرض الأخطاء في الإنتاج
}

/* ===== Get role from URL parameter with validation ===== */
$allowed_roles = ['committee'];
$role = isset($_GET['role']) && in_array($_GET['role'], $allowed_roles) ? $_GET['role'] : 'committee';

/* ===== Helper to locate required files no matter current dir ===== */
function req_path($fname) {
    $candidates = [
        __DIR__ . "/$fname",
        dirname(__DIR__) . "/$fname",
        __DIR__ . "/../$fname",
    ];
    foreach ($candidates as $p) {
        if (is_file($p)) return $p;
    }
    return null;
}

/* ===== Include db + helpers safely ===== */
$dbphp = req_path('db.php');
$helphp = req_path('helpers.php');

if (!$dbphp || !$helphp) {
    http_response_code(500);
    if ($DEBUG) {
        echo "<h3>خطأ في تضمين الملفات</h3>";
        echo "<p>لم يتم العثور على <code>db.php</code> أو <code>helpers.php</code> في المسار: " . htmlspecialchars(__DIR__) . "</p>";
    } else {
        echo "خطأ في النظام. الرجاء الاتصال بالدعم الفني.";
    }
    exit;
}

require_once $dbphp;
require_once $helphp;

/* ===== Ensure session ===== */
if (function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

/* ===== Ensure core helpers exist ===== */
if (!function_exists('verify_csrf') || !function_exists('csrf_token')) {
    function csrf_token() { 
        return $_SESSION['csrf'] = $_SESSION['csrf'] ?? bin2hex(random_bytes(32)); 
    }
    function verify_csrf($t) { 
        return isset($_SESSION['csrf']) && hash_equals($_SESSION['csrf'], (string)$t); 
    }
}
if (!function_exists('e')) {
    function e($s) { 
        return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); 
    }
}

/* ===== Check database connection ===== */
if (!isset($mysqli1) || !($mysqli1 instanceof mysqli)) {
    http_response_code(500);
    if ($DEBUG) {
        echo "<h3>خطأ في قاعدة البيانات</h3>";
        echo "<p>لم يتم إنشاء اتصال قاعدة البيانات بشكل صحيح.</p>";
    } else {
        echo "خطأ في النظام. الرجاء الاتصال بالدعم الفني.";
    }
    exit;
}

$mysqli1->set_charset('utf8mb4');
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

/* ===== If already logged in with proper permissions, go to dashboard ===== */
if (!empty($_SESSION['committee_id'])) {
    // Check if user has permission to access committee dashboard
    $user_role_id = $_SESSION['committee_role_id'] ?? 0;
    
    // Only allow role_id = 1 (admin) or 2 (registrar) to access committee dashboard
    if (in_array($user_role_id, [1, 2])) {
        header("Location: committee_dashboard.php");
        exit;
    } else {
        // Destroy session if user doesn't have permission
        $_SESSION = array();
        if (ini_get("session.use_cookies")) {
            $params = session_get_cookie_params();
            setcookie(session_name(), '', time() - 42000,
                $params["path"], $params["domain"],
                $params["secure"], $params["httponly"]
            );
        }
        session_destroy();
    }
}

$error = '';
$username = '';

/* ===== Handle POST (login) ===== */
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        // Validate CSRF token
        if (!isset($_POST['csrf']) || !verify_csrf($_POST['csrf'])) {
            $error = 'رمز الأمان غير صالح. الرجاء تحديث الصفحة والمحاولة مرة أخرى.';
            error_log("[SECURITY] CSRF token validation failed from IP: " . ($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
        } else {
            // Sanitize and validate input
            $username = trim((string)($_POST['username'] ?? ''));
            $password = (string)($_POST['password'] ?? '');
            
            // Validate input length
            if (strlen($username) > 100 || strlen($password) > 255) {
                $error = 'بيانات الدخول غير صالحة.';
                error_log("[SECURITY] Input length validation failed - username length: " . strlen($username));
            } elseif ($username === '' || $password === '') {
                $error = 'اسم المستخدم وكلمة المرور مطلوبان.';
            } else {
                // Use prepared statement to prevent SQL injection
                $stmt = $mysqli1->prepare("SELECT id, username, password_hash, name, can_view_all, college_id, role_id FROM committee_users WHERE username = ? LIMIT 1");
                if (!$stmt) {
                    throw new Exception("فشل تحضير الاستعلام");
                }
                
                $stmt->bind_param("s", $username);
                $stmt->execute();
                $result = $stmt->get_result();
                $user = $result->fetch_assoc();
                $stmt->close();

                $ok = false;
                if ($user) {
                    // Secure password verification
                    $password_hash = $user['password_hash'];
                    
                    // Check if it's a valid password hash
                    $password_info = password_get_info($password_hash);
                    $hash_algo = $password_info['algo'] ?? 0;
                    
                    if ($hash_algo !== 0) {
                        // Modern password_hash format
                        $ok = password_verify($password, $password_hash);
                        
                        // Debug logging (only in debug mode)
                        if ($DEBUG) {
                            error_log("=== LOGIN DEBUG ===");
                            error_log("Username: " . $username);
                            error_log("Using password_verify: " . ($ok ? 'SUCCESS' : 'FAILED'));
                            error_log("Hash algorithm: " . ($password_info['algoName'] ?? 'unknown'));
                        }
                    } else {
                        // Legacy plain text (for backward compatibility only)
                        // WARNING: Remove this in production!
                        $ok = ($password_hash === $password);
                        
                        if ($DEBUG) {
                            error_log("=== LEGACY LOGIN ===");
                            error_log("Using plain text comparison: " . ($ok ? 'SUCCESS' : 'FAILED'));
                            error_log("SECURITY WARNING: Plain text passwords should not be used!");
                        }
                    }
                } else {
                    if ($DEBUG) {
                        error_log("=== LOGIN DEBUG ===");
                        error_log("User not found: " . $username);
                    }
                }

                if ($ok) {
                    // Validate user data before storing in session
                    $user_id = filter_var($user['id'], FILTER_VALIDATE_INT);
                    $user_role_id = isset($user['role_id']) ? filter_var($user['role_id'], FILTER_VALIDATE_INT) : 0;
                    $can_view_all = isset($user['can_view_all']) ? (bool)$user['can_view_all'] : false;
                    $college_id = isset($user['college_id']) ? filter_var($user['college_id'], FILTER_VALIDATE_INT) : null;
                    
                    // Only allow role_id = 1 (admin) or 2 (registrar)
                    if (!in_array($user_role_id, [1, 2])) {
                        $error = 'ليس لديك صلاحية للوصول إلى لوحة التحكم. الرجاء الاتصال بالمسؤول.';
                        error_log("[SECURITY] Access denied - User ID: $user_id, Role ID: $user_role_id attempted to access committee dashboard");
                    } else {
                        // Regenerate session ID to prevent session fixation
                        session_regenerate_id(true);
                        
                        // Store minimal necessary data in session
                        $_SESSION['committee_id'] = $user_id;
                        $_SESSION['committee_username'] = $user['username'];
                        $_SESSION['committee_name'] = $user['name'];
                        $_SESSION['committee_can_all'] = $can_view_all;
                        $_SESSION['committee_college_id'] = $college_id;
                        $_SESSION['committee_role_id'] = $user_role_id;
                        $_SESSION['user_role'] = $role;
                        $_SESSION['login_time'] = time();
                        $_SESSION['ip_address'] = $_SERVER['REMOTE_ADDR'] ?? '';
                        $_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'] ?? '';
                        
                        // Clear CSRF token after successful login
                        unset($_SESSION['csrf']);
                        
                        // Redirect to dashboard
                        header("Location: committee_dashboard.php");
                        exit;
                    }
                } else {
                    // Use generic error message to prevent user enumeration
                    $error = 'اسم المستخدم أو كلمة المرور غير صحيحة.';
                    
                    // Add delay to prevent brute force attacks
                    usleep(500000); // 0.5 second delay
                    
                    // Log failed attempt
                    error_log("[SECURITY] Failed login attempt for username: $username from IP: " . ($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
                }
            }
        }
    } catch (Throwable $e) {
        // Log error but don't expose details to user
        error_log("[ERROR] committee_login.php: " . $e->getMessage() . " at " . $e->getFile() . ":" . $e->getLine());
        $error = 'حدث خطأ في النظام. الرجاء المحاولة مرة أخرى لاحقاً.';
    }
}

// Generate new CSRF token for the form
$csrf_token = csrf_token();

// Page Title
$page_titles = [
    'committee' => 'مسجل الكلية',
];
$page_title = $page_titles[$role] ?? 'مسجل الكلية';
?>

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="robots" content="noindex, nofollow">
    <title>تسجيل الدخول - <?= e($page_title) ?></title>
    <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: #43A047;
            --secondary-color: #43A047;
            --accent-color: #ffd166;
            --light-bg: #f8fafc;
            --dark-text: #1e293b;
            --gray-border: #e2e8f0;
            --success: #10b981;
            --danger: #ef4444;
            --warning: #f59e0b;
        }

        * {
            font-family: 'Cairo', sans-serif;
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            direction: rtl;
        }

        .login-container {
            width: 100%;
            max-width: 1200px;
        }

        .login-card {
            background: white;
            border-radius: 24px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
            overflow: hidden;
            display: flex;
            min-height: 700px;
        }

        .login-left {
            flex: 1;
            background: linear-gradient(135deg, var(--primary-color) 0%, #2a7a9a 100%);
            padding: 60px 40px;
            color: white;
            display: flex;
            flex-direction: column;
            justify-content: center;
            position: relative;
        }

        .login-left::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -20%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            opacity: 0.3;
        }

        .login-right {
            flex: 1.2;
            padding: 60px 50px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .welcome-text {
            font-size: 2.8rem;
            font-weight: 800;
            line-height: 1.2;
            margin-bottom: 20px;
            position: relative;
            z-index: 1;
        }

        .system-name {
            font-size: 1.5rem;
            font-weight: 600;
            opacity: 0.9;
            margin-bottom: 40px;
            position: relative;
            z-index: 1;
        }

        .features-list {
            list-style: none;
            padding: 0;
            margin-top: 40px;
        }

        .features-list li {
            margin-bottom: 25px;
            display: flex;
            align-items: center;
            font-size: 1.1rem;
            position: relative;
            z-index: 1;
        }

        .features-list li i {
            background: rgba(255, 255, 255, 0.2);
            width: 36px;
            height: 36px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 15px;
            flex-shrink: 0;
        }

        .login-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .login-icon {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
            box-shadow: 0 10px 30px rgba(26, 95, 122, 0.2);
        }

        .login-icon i {
            font-size: 2.5rem;
            color: white;
        }

        .login-title {
            font-size: 2.2rem;
            font-weight: 800;
            color: var(--primary-color);
            margin-bottom: 10px;
        }

        .login-subtitle {
            color: #64748b;
            font-size: 1.1rem;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .input-container {
            position: relative;
            width: 100%;
        }

        .form-control {
            width: 100%;
            height: 60px;
            padding: 0 60px 0 60px;
            border: 2px solid var(--gray-border);
            border-radius: 14px;
            font-size: 1.1rem;
            transition: all 0.3s ease;
            background: white;
            color: var(--dark-text);
            text-align: center;
            direction: rtl;
        }

        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 4px rgba(26, 95, 122, 0.15);
            outline: none;
            background: #f8fafc;
        }

        .input-container .input-icon {
            position: absolute;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--primary-color);
            font-size: 1.3rem;
            z-index: 2;
            pointer-events: none;
        }

        .password-toggle {
            position: absolute;
            left: 20px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: #94a3b8;
            font-size: 1.2rem;
            padding: 0;
            z-index: 3;
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .password-toggle:hover {
            color: var(--primary-color);
            background: rgba(26, 95, 122, 0.1);
        }

        .login-btn {
            width: 100%;
            height: 60px;
            background: linear-gradient(135deg, var(--primary-color), #2a7a9a);
            color: white;
            border: none;
            border-radius: 14px;
            font-size: 1.2rem;
            font-weight: 700;
            transition: all 0.4s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 10px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .login-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 30px rgba(26, 95, 122, 0.25);
        }

        .login-btn:active {
            transform: translateY(-1px);
        }

        .login-btn i {
            margin-left: 12px;
            font-size: 1.3rem;
        }

        .back-home-link {
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, var(--primary-color), #2a7a9a);
            color: white;
            text-decoration: none;
            font-weight: 700;
            margin-top: 25px;
            padding: 15px 30px;
            border-radius: 14px;
            transition: all 0.3s ease;
            text-align: center;
            width: 100%;
            max-width: 320px;
            margin-left: auto;
            margin-right: auto;
            box-shadow: 0 6px 12px rgba(26, 95, 122, 0.2);
            border: none;
            cursor: pointer;
        }

        .back-home-link:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 20px rgba(26, 95, 122, 0.3);
            text-decoration: none;
            color: white;
        }

        .back-home-link i {
            margin-left: 12px;
            transition: transform 0.3s ease;
        }

        .back-home-link:hover i {
            transform: translateX(-5px);
        }

        .lang-btn {
            background: rgba(255, 255, 255, 0.2);
            border: 2px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 12px 24px;
            border-radius: 12px;
            font-weight: 700;
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .lang-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-2px);
        }

        .role-badge {
            display: inline-block;
            background: var(--accent-color);
            color: #854d0e;
            padding: 8px 20px;
            border-radius: 50px;
            font-weight: 700;
            font-size: 1rem;
            margin-bottom: 20px;
        }

        .alert-custom {
            border-radius: 14px;
            padding: 18px 24px;
            font-size: 1.1rem;
            border: none;
            background: #fee2e2;
            color: var(--danger);
            margin-bottom: 30px;
            display: flex;
            align-items: center;
            text-align: right;
            border-right: 5px solid var(--danger);
        }

        .alert-custom.info {
            background: #dbeafe;
            color: #1d4ed8;
            border-right: 5px solid #1d4ed8;
        }

        .alert-custom i {
            margin-left: 15px;
            font-size: 1.4rem;
        }

        .footer-links {
            text-align: center;
            margin-top: 40px;
            color: #475569;
            font-size: 1rem;
            padding-top: 25px;
            border-top: 2px solid var(--gray-border);
        }

        .footer-links p {
            margin-bottom: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .footer-links p i {
            margin-left: 10px;
            color: var(--secondary-color);
        }

        .language-switcher {
            position: absolute;
            top: 30px;
            left: 30px;
            z-index: 10;
        }

        @media (max-width: 992px) {
            .login-card {
                flex-direction: column;
                min-height: auto;
            }
            
            .login-left, .login-right {
                padding: 40px 30px;
            }
            
            .welcome-text {
                font-size: 2.2rem;
            }
            
            .login-title {
                font-size: 1.8rem;
            }
        }

        @media (max-width: 576px) {
            .login-left, .login-right {
                padding: 30px 20px;
            }
            
            .login-title {
                font-size: 1.6rem;
            }
            
            .form-control {
                height: 55px;
                padding: 0 50px 0 50px;
                font-size: 1rem;
            }
            
            .login-btn {
                height: 55px;
                font-size: 1.1rem;
            }
            
            .welcome-text {
                font-size: 1.8rem;
            }
            
            .back-home-link {
                max-width: 280px;
                padding: 12px 20px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-card">
            
            <!-- Left Panel - Welcome Section -->
            <div class="login-left">
                <div class="language-switcher">
                    <button class="lang-btn" type="button" onclick="alert('سيتم تفعيل الترجمة قريباً')">
                        EN
                    </button>
                </div>
                
                <h1 class="welcome-text">مرحبًا بعودتك</h1>
                <p class="system-name">نظام القبول والتسجيل الإلكتروني</p>
                
                <ul class="features-list">
                    <li>
                        <i class="fas fa-shield-alt"></i>
                        <span>تسجيل دخول آمن ومشفر</span>
                    </li>
                    <li>
                        <i class="fas fa-tachometer-alt"></i>
                        <span>لوحة تحكم متكاملة وسهلة الاستخدام</span>
                    </li>
                    <li>
                        <i class="fas fa-users-cog"></i>
                        <span>إدارة طلبات القبول والتسجيل بكفاءة</span>
                    </li>
                    <li>
                        <i class="fas fa-chart-line"></i>
                        <span>تقارير وإحصائيات تفصيلية</span>
                    </li>
                </ul>
                
                <div style="margin-top: auto; opacity: 0.8; font-size: 0.9rem;">
                    <p>© 2026 نظام القبول الإلكتروني. جميع الحقوق محفوظة.</p>
                </div>
            </div>
            
            <!-- Right Panel - Login Form -->
            <div class="login-right">
                <div class="login-header">
                    <div class="login-icon">
                        <i class="fas fa-user-tie"></i>
                    </div>
                    
                    <div class="role-badge">
                        <?= e($page_title) ?>
                    </div>
                    
                    <h2 class="login-title">تسجيل الدخول</h2>
                    <p class="login-subtitle">الرجاء إدخال بيانات الاعتماد الخاصة بك</p>
                </div>
                
                <?php if ($error): ?>
                    <div class="alert-custom" role="alert">
                        <i class="fas fa-exclamation-circle"></i>
                        <div><?= e($error) ?></div>
                    </div>
                <?php endif; ?>

                <?php if ($DEBUG): ?>
                    <div class="alert-custom info" role="alert">
                        <i class="fas fa-bug"></i>
                        <div>
                            <strong>وضع التصحيح نشط</strong>
                            <p class="mb-0">هذا الوضع مخصص للاختبار فقط</p>
                        </div>
                    </div>
                <?php endif; ?>

                <form method="post" action="committee_login.php?role=<?= e($role) ?><?= $DEBUG ? '&debug=1' : '' ?>" autocomplete="off">
                    <input type="hidden" name="csrf" value="<?= e($csrf_token) ?>">
                    
                    <div class="form-group">
                        <div class="input-container">
                            <input type="text"
                                   class="form-control"
                                   id="username" 
                                   name="username"
                                   placeholder="اسم المستخدم"
                                   required 
                                   value="<?= e($username) ?>"
                                   autocomplete="off"
                                   maxlength="100">
                            <i class="input-icon fas fa-user"></i>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <div class="input-container">
                            <input type="password"
                                   class="form-control"
                                   id="password" 
                                   name="password"
                                   placeholder="كلمة المرور"
                                   required
                                   autocomplete="off"
                                   maxlength="255">
                            <button type="button" class="password-toggle" id="togglePassword" tabindex="-1">
                                <i class="fas fa-eye"></i>
                            </button>
                            <i class="input-icon fas fa-lock"></i>
                        </div>
                    </div>
                    
                    <button class="login-btn" type="submit" id="submitBtn">
                        <i class="fas fa-sign-in-alt"></i>
                        تسجيل الدخول
                    </button>
                </form>
                
                <!-- Footer Links -->
                <div class="footer-links">
                    <p class="mb-2">
                        <i class="fas fa-info-circle"></i>
                        للمساعدة التقنية، الرجاء الاتصال بقسم الدعم
                    </p>
                    
                    <a href="https://nu.edu.sd/nu" class="back-home-link" rel="noopener noreferrer">
                        <i class="fas fa-arrow-right"></i>
                        العودة إلى الصفحة الرئيسية
                    </a>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Password visibility toggle
        document.getElementById('togglePassword').addEventListener('click', function(e) {
            e.preventDefault();
            const passwordInput = document.getElementById('password');
            const icon = this.querySelector('i');
            
            if (passwordInput.type === 'password') {
                passwordInput.type = 'text';
                icon.classList.remove('fa-eye');
                icon.classList.add('fa-eye-slash');
            } else {
                passwordInput.type = 'password';
                icon.classList.remove('fa-eye-slash');
                icon.classList.add('fa-eye');
            }
        });

        // Form submission handling
        document.querySelector('form').addEventListener('submit', function(e) {
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value;
            
            if (!username || !password) {
                e.preventDefault();
                alert('يرجى ملء جميع الحقول المطلوبة');
                return false;
            }
            
            // Prevent double submission
            const submitBtn = document.getElementById('submitBtn');
            if (submitBtn.disabled) {
                e.preventDefault();
                return false;
            }
            
            submitBtn.disabled = true;
            submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> جاري تسجيل الدخول...';
            
            // Re-enable after 10 seconds in case of timeout
            setTimeout(function() {
                submitBtn.disabled = false;
                submitBtn.innerHTML = '<i class="fas fa-sign-in-alt"></i> تسجيل الدخول';
            }, 10000);
        });

        // Auto-focus on username field
        document.addEventListener('DOMContentLoaded', function() {
            const usernameField = document.getElementById('username');
            if (usernameField && usernameField.value === '') {
                usernameField.focus();
            }
        });

        // Disable right-click on sensitive areas (optional security)
        document.querySelector('.login-right').addEventListener('contextmenu', function(e) {
            e.preventDefault();
            return false;
        });
    </script>
</body>
</html>