Tech Stack Advisor - Code Viewer

← Back to File Tree

login.html

Language: html | Path: backend/static/login.html | Lines: 343
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - Tech Stack Advisor</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .auth-container {
            background: white;
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            padding: 40px;
            max-width: 450px;
            width: 100%;
        }

        .logo {
            text-align: center;
            margin-bottom: 30px;
        }

        .logo h1 {
            font-size: 2em;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .logo p {
            color: #666;
            margin-top: 10px;
        }

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

        label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
        }

        input {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        input:focus {
            outline: none;
            border-color: #667eea;
        }

        .btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s;
        }

        .btn:hover:not(:disabled) {
            transform: translateY(-2px);
        }

        .btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        .alert {
            padding: 12px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: none;
        }

        .alert.error {
            background: #fee;
            color: #c33;
            border: 1px solid #fcc;
        }

        .alert.success {
            background: #efe;
            color: #3c3;
            border: 1px solid #cfc;
        }

        .divider {
            text-align: center;
            margin: 30px 0;
            position: relative;
        }

        .divider::before {
            content: '';
            position: absolute;
            left: 0;
            right: 0;
            top: 50%;
            height: 1px;
            background: #ddd;
        }

        .divider span {
            background: white;
            padding: 0 15px;
            position: relative;
            color: #666;
        }

        .oauth-buttons {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .oauth-btn {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            background: white;
            transition: all 0.3s;
        }

        .oauth-btn:hover:not(.disabled) {
            border-color: #667eea;
            background: #f8f9fa;
        }

        .oauth-btn.disabled {
            opacity: 0.4;
            cursor: not-allowed;
            background: #f5f5f5;
        }

        .oauth-btn.disabled:hover {
            border-color: #ddd;
            background: #f5f5f5;
        }

        .oauth-btn img {
            width: 20px;
            height: 20px;
        }

        .footer-link {
            text-align: center;
            margin-top: 20px;
            color: #666;
        }

        .footer-link a {
            color: #667eea;
            text-decoration: none;
            font-weight: 600;
        }

        .footer-link a:hover {
            text-decoration: underline;
        }

        .loading {
            display: none;
            text-align: center;
            color: #667eea;
            margin: 10px 0;
        }
    </style>
</head>
<body>
    <div class="auth-container">
        <div class="logo">
            <h1>🚀 Tech Stack Advisor</h1>
            <p>Welcome back! Please login to continue.</p>
        </div>

        <div id="alert" class="alert"></div>
        <div id="loading" class="loading">Loading...</div>

        <form id="loginForm">
            <div class="form-group">
                <label for="email">Email</label>
                <input type="email" id="email" name="email" required placeholder="you@example.com">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" id="password" name="password" required placeholder="Enter your password">
            </div>

            <button type="submit" class="btn" id="loginBtn">Login</button>
        </form>

        <div class="divider">
            <span>OR</span>
        </div>

        <div class="oauth-buttons">
            <button class="oauth-btn" onclick="loginWithGoogle()">
                <img src="https://www.google.com/favicon.ico" alt="Google">
                Continue with Google
            </button>
            <button class="oauth-btn disabled" onclick="loginWithMicrosoft()">
                <img src="https://www.microsoft.com/favicon.ico" alt="Microsoft">
                Continue with Microsoft
            </button>
            <button class="oauth-btn disabled" onclick="loginWithLinkedIn()">
                <img src="https://www.linkedin.com/favicon.ico" alt="LinkedIn">
                Continue with LinkedIn
            </button>
            <button class="oauth-btn disabled" onclick="loginWithFacebook()">
                <img src="https://www.facebook.com/favicon.ico" alt="Facebook">
                Continue with Facebook
            </button>
        </div>

        <div class="footer-link">
            Don't have an account? <a href="/register.html">Sign up</a>
        </div>
    </div>

    <script src="/auth.js"></script>
    <script>
        const loginForm = document.getElementById('loginForm');
        const loginBtn = document.getElementById('loginBtn');
        const alert = document.getElementById('alert');
        const loading = document.getElementById('loading');

        // Check if already logged in
        if (isAuthenticated()) {
            window.location.href = '/';
        }

        loginForm.addEventListener('submit', async (e) => {
            e.preventDefault();

            const email = document.getElementById('email').value;
            const password = document.getElementById('password').value;

            // Disable form
            loginBtn.disabled = true;
            loading.style.display = 'block';
            hideAlert();

            try {
                const response = await fetch('/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ email, password }),
                });

                const data = await response.json();

                if (response.ok) {
                    // Save token
                    saveToken(data.token);
                    showAlert('Login successful! Redirecting...', 'success');

                    // Redirect to main page
                    setTimeout(() => {
                        window.location.href = '/';
                    }, 1000);
                } else {
                    showAlert(data.detail || 'Login failed. Please check your credentials.', 'error');
                }
            } catch (error) {
                console.error('Login error:', error);
                showAlert('An error occurred. Please try again.', 'error');
            } finally {
                loginBtn.disabled = false;
                loading.style.display = 'none';
            }
        });

        function showAlert(message, type) {
            alert.textContent = message;
            alert.className = `alert ${type}`;
            alert.style.display = 'block';
        }

        function hideAlert() {
            alert.style.display = 'none';
        }

        // OAuth login functions
        function loginWithGoogle() {
            // Redirect to Google OAuth login endpoint
            window.location.href = '/auth/google/login';
        }

        function loginWithMicrosoft() {
            showAlert('Microsoft OAuth coming soon!', 'error');
        }

        function loginWithLinkedIn() {
            showAlert('LinkedIn OAuth coming soon!', 'error');
        }

        function loginWithFacebook() {
            showAlert('Facebook OAuth coming soon!', 'error');
        }
    </script>
</body>
</html>