Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/login.php

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

// Redirect if already logged in
if (MemberAuth::isMemberLoggedIn()) {
    redirect('members/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 {
        // Member login
        $memberAuth = new MemberAuth();
        $result = $memberAuth->authenticateMember($identifier, $password);
        
        if ($result['success']) {
            $account = $result['account'];
            
            // Check if 2FA is enabled for this member
            $twoFA = new TwoFactorAuth('member');
            $twoFASettings = $twoFA->get2FASettings($account['member_id']);
            
            if ($twoFASettings && $twoFASettings['is_enabled']) {
                // 2FA is enabled - redirect to verification
                $_SESSION['2fa_user_id'] = $account['member_id'];
                $_SESSION['2fa_user_type'] = 'member';
                $_SESSION['2fa_account_data'] = $account; // Store account data temporarily
                
                redirect('verify-2fa.php');
            } else {
                // No 2FA - proceed with normal login
                $_SESSION['member_id'] = $account['member_id'];
                $_SESSION['member_account_id'] = $account['id'];
                $_SESSION['member_username'] = $account['username'];
                $_SESSION['member_full_name'] = $account['full_name'];
                $_SESSION['member_title'] = $account['title'] ?? '';
                
                redirect('members/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>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, #3B82F6 0%, #60A5FA 50%, #FCD34D 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-500 to-yellow-400 rounded-full mb-4">
                <i class="fas fa-users text-4xl text-white"></i>
            </div>
            <h1 class="text-3xl font-bold text-gray-800 mb-2">Member Login</h1>
            <p class="text-gray-600">Welcome back! Please login to your account.</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-blue-500"></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-blue-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-blue-500"></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-blue-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-blue-500 focus:ring-blue-500">
                    <span class="ml-2 text-sm text-gray-600">Remember me</span>
                </label>
                <a href="forgot-password.php" class="text-sm text-blue-500 hover:text-blue-600">
                    Forgot password?
                </a>
            </div>
            
            <button type="submit" 
                    class="w-full bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-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
            </button>
        </form>
        
        <!-- Admin Login Link -->
        <div class="mt-4 text-center">
            <a href="admin-login.php" class="text-sm text-gray-600 hover:text-blue-600 inline-flex items-center">
                <i class="fas fa-user-tie mr-2"></i>Admin Login
            </a>
        </div>
        
        <!-- Home Link -->
        <div class="mt-6 text-center">
            <a href="index.php" class="text-blue-500 hover:text-blue-600 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