Sindbad~EG File Manager

Current Path : /home/copmadinaarea/.trash/
Upload File :
Current File : /home/copmadinaarea/.trash/admin-login.php

<?php
require_once 'config/config.php';
require_once 'classes/TwoFactorAuth.php';

// Redirect if already logged in
if (isLoggedIn()) {
    redirect('dashboard.php');
}

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $identifier = sanitize($_POST['identifier'] ?? '');
    $password = $_POST['password'] ?? '';
    
    if (empty($identifier) || empty($password)) {
        $error = 'Please enter both username/email and password';
    } else {
        // Admin login
        $auth = new Auth();
        $result = $auth->login($identifier, $password);
        
        if ($result['success']) {
            $userId = $_SESSION['user_id'];
            
            // Check if 2FA is enabled for this admin
            $twoFA = new TwoFactorAuth('admin');
            $twoFASettings = $twoFA->get2FASettings($userId);
            
            if ($twoFASettings && $twoFASettings['is_enabled']) {
                // 2FA is enabled - redirect to verification
                // Store user ID for 2FA verification
                $_SESSION['2fa_user_id'] = $userId;
                $_SESSION['2fa_user_type'] = 'admin';
                
                // Clear the normal session but keep 2FA session
                $temp_2fa_user_id = $_SESSION['2fa_user_id'];
                $temp_2fa_user_type = $_SESSION['2fa_user_type'];
                
                // Clear admin session
                unset($_SESSION['user_id']);
                unset($_SESSION['username']);
                unset($_SESSION['email']);
                unset($_SESSION['role']);
                
                // Restore 2FA session
                $_SESSION['2fa_user_id'] = $temp_2fa_user_id;
                $_SESSION['2fa_user_type'] = $temp_2fa_user_type;
                
                redirect('verify-2fa.php');
            } else {
                // No 2FA - already logged in by Auth class
                redirect('dashboard.php');
            }
        } else {
            $error = $result['message'];
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login - <?php echo APP_NAME; ?></title>
    
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <style>
        * {
            font-family: 'Inter', sans-serif;
        }
        
        .gradient-bg {
            background: linear-gradient(135deg, #1E40AF 0%, #9333EA 50%, #F97316 100%);
        }
        
        .login-card {
            backdrop-filter: blur(10px);
            background: rgba(255, 255, 255, 0.95);
        }
    </style>
</head>
<body class="gradient-bg min-h-screen flex items-center justify-center p-4">
    <div class="login-card w-full max-w-md rounded-2xl shadow-2xl p-8">
        <!-- Logo & Title -->
        <div class="text-center mb-8">
            <div class="inline-block p-4 bg-gradient-to-r from-blue-700 to-purple-600 rounded-full mb-4">
                <i class="fas fa-user-shield text-4xl text-white"></i>
            </div>
            <h1 class="text-3xl font-bold text-gray-800 mb-2">Admin Login</h1>
            <p class="text-gray-600">Secure access for administrators only</p>
        </div>
        
        <!-- Error Message -->
        <?php if (!empty($error)): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded-lg mb-6 flex items-center">
                <i class="fas fa-exclamation-circle mr-2"></i>
                <span><?php echo htmlspecialchars($error); ?></span>
            </div>
        <?php endif; ?>
        
        <!-- Login Form -->
        <form method="POST" action="" class="space-y-6" id="loginForm">
            <div>
                <label for="identifier" class="block text-sm font-medium text-gray-700 mb-2">
                    <i class="fas fa-user mr-2 text-purple-600"></i>Username or Email
                </label>
                <input type="text" 
                       id="identifier" 
                       name="identifier" 
                       required
                       class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition"
                       placeholder="Enter your username or email">
            </div>
            
            <div>
                <label for="password" class="block text-sm font-medium text-gray-700 mb-2">
                    <i class="fas fa-lock mr-2 text-purple-600"></i>Password
                </label>
                <div class="relative">
                    <input type="password" 
                           id="password" 
                           name="password" 
                           required
                           class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition"
                           placeholder="Enter your password">
                    <button type="button" 
                            onclick="togglePassword()" 
                            class="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700">
                        <i class="fas fa-eye" id="toggleIcon"></i>
                    </button>
                </div>
            </div>
            
            <div class="flex items-center justify-between">
                <label class="flex items-center">
                    <input type="checkbox" class="rounded border-gray-300 text-purple-600 focus:ring-purple-500">
                    <span class="ml-2 text-sm text-gray-600">Remember me</span>
                </label>
                <a href="admin-forgot-password.php" class="text-sm text-purple-600 hover:text-purple-700">
                    Forgot password?
                </a>
            </div>
            
            <button type="submit" 
                    class="w-full bg-gradient-to-r from-blue-700 to-purple-600 hover:from-blue-800 hover:to-purple-700 text-white font-semibold py-3 rounded-lg transition duration-200 transform hover:scale-105 shadow-lg">
                <i class="fas fa-sign-in-alt mr-2"></i>Login to Admin Panel
            </button>
        </form>
        
        <!-- Member Login Link -->
        <div class="mt-4 text-center">
            <a href="login.php" class="text-sm text-gray-600 hover:text-blue-600 inline-flex items-center">
                <i class="fas fa-users mr-2"></i>Member Login
            </a>
        </div>
        
        <!-- Home Link -->
        <div class="mt-6 text-center">
            <a href="index.php" class="text-purple-600 hover:text-purple-700 font-medium inline-flex items-center">
                <i class="fas fa-home mr-2"></i>Back to Home
            </a>
        </div>
        
        <!-- Footer -->
        <div class="mt-8 text-center text-sm text-gray-600">
            <p>&copy; <?php echo date('Y'); ?> <?php echo APP_NAME; ?>. All rights reserved.</p>
        </div>
    </div>
    
    <script>
        function togglePassword() {
            const passwordInput = document.getElementById('password');
            const toggleIcon = document.getElementById('toggleIcon');
            
            if (passwordInput.type === 'password') {
                passwordInput.type = 'text';
                toggleIcon.classList.remove('fa-eye');
                toggleIcon.classList.add('fa-eye-slash');
            } else {
                passwordInput.type = 'password';
                toggleIcon.classList.remove('fa-eye-slash');
                toggleIcon.classList.add('fa-eye');
            }
        }
    </script>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists