Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

26.5 KB
Raw Blame
<!DOCTYPE html>
<html>
<head>
    <!-- Authentication redirect script -->
    <script src="auth-redirect.js?v=20260518001" data-protected="false"></script>
    
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title data-i18n="auth.register">Register - Warracker</title>
    <!-- Favicons -->
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
    <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
    <link rel="apple-touch-icon" sizes="180x180" href="img/favicon-512x512.png">
    <link rel="manifest" href="manifest.json">
    <link rel="stylesheet" href="style.css?v=20261127001">
    <script src="theme-loader.js?v=20250119001"></script> <!-- Apply theme early -->
    <!-- Font Awesome for icons -->
    <link rel="stylesheet" href="vendor/fontawesome/css/all.min.css?v=20261001001">
    <!-- Load header fix styles to ensure consistent header styling -->
    <link rel="stylesheet" href="header-fix.css?v=20250119001">
    <!-- Mobile Header specific styles -->
    <link rel="stylesheet" href="mobile-header.css?v=20261127001">
    <!-- i18next Local Scripts -->
    <script src="js/lib/i18next.min.js?v=20250119001"></script>
    <script src="js/lib/i18nextHttpBackend.min.js?v=20250119001"></script>
    <script src="js/lib/i18nextBrowserLanguageDetector.min.js?v=20250119001"></script>
    <!-- i18n initialization script -->
    <script src="js/i18n.js?v=20261127001"></script>
    <script src="mobile-menu.js?v=20261127001" defer></script>
    <!-- Load fix for auth buttons -->
    <script src="fix-auth-buttons-loader.js?v=20250119001"></script>
    <script src="script.js?v=20261127001" defer></script>
    <style>
        .auth-container {
            max-width: 500px;
            margin: 50px auto;
            padding: 30px;
            background-color: var(--card-bg);
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        .auth-title {
            text-align: center;
            margin-bottom: 30px;
            color: var(--text-color);
        }
        
        .auth-form .form-group {
            margin-bottom: 20px;
        }
        
        .auth-links {
            margin-top: 20px;
            text-align: center;
            font-size: 0.9em;
        }
        
        .auth-links a {
            color: var(--primary-color);
            text-decoration: none;
            margin: 0 10px;
        }
        
        .auth-links a:hover {
            text-decoration: underline;
        }
        
        .auth-message {
            margin-top: 20px;
            padding: 10px;
            border-radius: 4px;
            text-align: center;
            display: none;
        }
        
        .auth-message.error {
            background-color: rgba(244, 67, 54, 0.1);
            color: #f44336;
            border: 1px solid rgba(244, 67, 54, 0.3);
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 20px;
        }
        
        .auth-message.error h3 {
            margin-top: 0;
            margin-bottom: 10px;
            font-size: 1.2rem;
            color: #d32f2f;
        }
        
        .auth-message.error p {
            margin-bottom: 10px;
        }
        
        .auth-message.error i {
            margin-right: 8px;
        }
        
        .auth-message.success {
            background-color: rgba(76, 175, 80, 0.1);
            color: #4caf50;
            border: 1px solid rgba(76, 175, 80, 0.3);
        }
        
        .btn-block {
            width: 100%;
        }
        
        .auth-form .password-container {
            position: relative;
        }
        
        .auth-form .password-toggle {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
        }
        
        .password-strength {
            height: 5px;
            margin-top: 5px;
            border-radius: 2px;
            transition: all 0.3s ease;
            background-color: #e0e0e0;
            width: 100%;
        }
        
        .password-strength.empty {
            background-color: #e0e0e0;
            width: 0%;
        }
        
        .password-strength.weak {
            background-color: #f44336; /* Red */
            width: 33%;
        }
        
        .password-strength.medium {
            background-color: #ff9800; /* Orange */
            width: 66%;
        }
        
        .password-strength.strong {
            background-color: #4caf50; /* Green */
            width: 100%;
        }
        
        .password-strength-text {
            font-size: 0.8em;
            margin-top: 5px;
            text-align: right;
        }
        
        .form-row {
            display: flex;
            gap: 20px;
        }
        
        .form-row .form-group {
            flex: 1;
        }
        
        @media (max-width: 768px) {
            .form-row {
                flex-direction: column;
                gap: 0;
            }
        }
        
        /* Password Requirements Styles */
        .password-requirements {
            margin-top: 10px;
            padding: 10px;
            background-color: var(--light-gray);
            border-radius: 4px;
            font-size: 0.9em;
        }
        
        .password-requirements h5 {
            margin-top: 0;
            margin-bottom: 8px;
            font-size: 0.95em;
            color: var(--text-color);
        }
        
        .password-requirements ul {
            margin: 0;
            padding-left: 20px;
        }
        
        .password-requirements li {
            margin-bottom: 4px;
            color: var(--text-muted);
        }
        
        .password-requirements li.met {
            color: var(--primary-color);
        }
        
        .password-requirements li.met::before {
            content: "✓ ";
        }
        
        .password-feedback {
            margin-top: 5px;
            font-size: 0.85em;
            color: var(--text-muted);
            text-align: right;
        }
        
        /* Password confirmation validation styles */
        input.valid {
            border-color: #4caf50 !important;
            background-color: rgba(76, 175, 80, 0.05);
        }
        
        input.invalid {
            border-color: #f44336 !important;
            background-color: rgba(244, 67, 54, 0.05);
        }
        
        .btn-sm {
            padding: 5px 10px;
            font-size: 0.875rem;
        }
        
        .mt-2 {
            margin-top: 10px;
        }
    </style>
    
    <!-- Registration status check script -->
    <script src="registration-status.js?v=20250119001"></script>
    <script>
        // Additional handling for the register page
        document.addEventListener('DOMContentLoaded', function() {
            // Only check if user is not logged in
            if (!localStorage.getItem('auth_token')) {
                fetch('/api/auth/registration-status')
                    .then(response => response.json())
                    .then(data => {
                        if (!data.enabled) {
                            // Show a more prominent message on the register page
                            const authMessage = document.getElementById('authMessage');
                            if (authMessage) {
                                authMessage.className = 'auth-message error';
                                authMessage.style.display = 'block';
                                authMessage.innerHTML = `
                                    <h3 data-i18n="auth.registration_disabled_title"><i class="fas fa-exclamation-triangle"></i> Registration Disabled</h3>
                                    <p data-i18n="auth.registration_disabled_message">The administrator has temporarily disabled new account registration.</p>
                                    <p data-i18n="auth.registration_disabled_contact">If you need an account, please contact the site administrator.</p>
                                    <p><a href="login.html" class="btn btn-primary btn-sm mt-2" data-i18n="auth.back_to_login">Go to Login</a></p>
                                `;
                            }
                            
                            // Hide the entire form
                            const registerForm = document.getElementById('registerForm');
                            if (registerForm) {
                                registerForm.style.display = 'none';
                            }
                            
                            // Hide the auth links
                            const authLinks = document.querySelector('.auth-links');
                            if (authLinks) {
                                authLinks.style.display = 'none';
                            }
                        }
                    })
                    .catch(error => {
                        console.error('Error checking registration status:', error);
                    });
            }
        });
    </script>
</head>
<body>
    <!-- Header -->
    <header>
        <div class="container">
            <div class="app-title">
                <i class="fas fa-shield-alt"></i>
                <h1>Warracker</h1>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <div class="container">
        <div class="auth-container">
            <h2 class="auth-title" data-i18n="auth.create_account_title">Create Your Account</h2>
            
            <div id="authMessage" class="auth-message"></div>
            
            <form id="registerForm" class="auth-form">
                <div class="form-row">
                    <div class="form-group">
                        <label for="firstName" data-i18n="auth.first_name_optional">First Name (Optional)</label>
                        <input type="text" id="firstName" name="first_name" class="form-control">
                    </div>
                    
                    <div class="form-group">
                        <label for="lastName" data-i18n="auth.last_name_optional">Last Name (Optional)</label>
                        <input type="text" id="lastName" name="last_name" class="form-control">
                    </div>
                </div>
                
                <div class="form-group">
                    <label for="username" data-i18n="auth.username">Username</label>
                    <input type="text" id="username" name="username" class="form-control" data-i18n-placeholder="auth.username" placeholder="Username" required>
                    <small class="form-text text-muted" data-i18n="auth.username_hint">Username must be unique and will be used for login.</small>
                </div>
                
                <div class="form-group">
                    <label for="email" data-i18n="auth.email_address">Email Address</label>
                    <input type="email" id="email" name="email" class="form-control" data-i18n-placeholder="auth.email_address" placeholder="Email Address" required>
                </div>
                
                <div class="form-group">
                    <label for="password" data-i18n="auth.password">Password</label>
                    <div class="password-container">
                        <input type="password" id="password" name="password" class="form-control" required>
                        <button type="button" class="password-toggle" title="Show/Hide Password" data-i18n-title="auth.toggle_password">
                            <i class="fas fa-eye"></i>
                        </button>
                    </div>
                    <div class="password-strength" id="passwordStrength"></div>
                    <div class="password-strength-text" id="passwordStrengthText"></div>
                    <small class="form-text text-muted" data-i18n="auth.password_hint_simple">Password must be at least 8 characters and include uppercase, lowercase, and numbers.</small>
                    
                    <!-- Password Requirements List -->
                    <div id="passwordRequirements" class="password-requirements" style="display: none;">
                        <h5 data-i18n="auth.password_requirements">Password Requirements:</h5>
                        <ul>
                            <li id="req-length" data-i18n="auth.req_length">At least 8 characters</li>
                            <li id="req-uppercase" data-i18n="auth.req_uppercase">At least 1 uppercase letter</li>
                            <li id="req-lowercase" data-i18n="auth.req_lowercase">At least 1 lowercase letter</li>
                            <li id="req-number" data-i18n="auth.req_number">At least 1 number</li>
                            <li id="req-special" data-i18n="auth.req_special">At least 1 special character</li>
                        </ul>
                    </div>
                    <div id="passwordFeedback" class="password-feedback"></div>
                </div>
                
                <div class="form-group">
                    <label for="confirmPassword" data-i18n="auth.confirm_password">Confirm Password</label>
                    <div class="password-container">
                        <input type="password" id="confirmPassword" name="confirmPassword" class="form-control" required>
                        <button type="button" class="password-toggle" title="Show/Hide Password" data-i18n-title="auth.toggle_password">
                            <i class="fas fa-eye"></i>
                        </button>
                    </div>
                    <div id="passwordMatchFeedback" class="password-feedback"></div>
                </div>
                
                <button type="submit" class="btn btn-primary btn-block">
                    <i class="fas fa-user-plus"></i> <span data-i18n="auth.create_account">Create Account</span>
                </button>
            </form>
            
            <div class="auth-links">
                <span data-i18n="auth.already_have_account">Already have an account?</span>
                <a href="login.html" data-i18n="auth.login">Login</a>
            </div>
        </div>
    </div>

    <!-- Script for authentication -->
    <script src="auth.js?v=20250119001"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const registerForm = document.getElementById('registerForm');
            const passwordInput = document.getElementById('password');
            const confirmPasswordInput = document.getElementById('confirmPassword');
            const passwordRequirements = document.getElementById('passwordRequirements');
            const passwordStrength = document.getElementById('passwordStrength');
            const passwordFeedback = document.getElementById('passwordFeedback');
            const authMessage = document.getElementById('authMessage');
            
            // Show password requirements when password field is focused
            if (passwordInput && passwordRequirements) {
                passwordInput.addEventListener('focus', function() {
                    passwordRequirements.style.display = 'block';
                });
                
                // Hide password requirements when focus is lost
                passwordInput.addEventListener('blur', function() {
                    passwordRequirements.style.display = 'none';
                });
            }
            
            // Password strength checker
            if (passwordInput && passwordStrength) {
                passwordInput.addEventListener('input', function() {
                    const password = this.value;
                    let strength = 0;
                    
                    // Update requirements list if elements exist
                    const reqLength = document.getElementById('req-length');
                    const reqUppercase = document.getElementById('req-uppercase');
                    const reqLowercase = document.getElementById('req-lowercase');
                    const reqNumber = document.getElementById('req-number');
                    const reqSpecial = document.getElementById('req-special');
                    
                    if (reqLength) reqLength.classList.toggle('met', password.length >= 8);
                    if (reqUppercase) reqUppercase.classList.toggle('met', /[A-Z]/.test(password));
                    if (reqLowercase) reqLowercase.classList.toggle('met', /[a-z]/.test(password));
                    if (reqNumber) reqNumber.classList.toggle('met', /[0-9]/.test(password));
                    if (reqSpecial) reqSpecial.classList.toggle('met', /[^A-Za-z0-9]/.test(password));
                    
                    // Calculate strength
                    if (password.length >= 8) strength += 1;
                    if (/[A-Z]/.test(password)) strength += 1;
                    if (/[a-z]/.test(password)) strength += 1;
                    if (/[0-9]/.test(password)) strength += 1;
                    if (/[^A-Za-z0-9]/.test(password)) strength += 1;
                    
                    // Update strength meter - first remove all classes
                    passwordStrength.className = 'password-strength';
                    const strengthText = document.getElementById('passwordStrengthText');
                    
                    // Then add the appropriate class based on strength
                    if (password.length === 0) {
                        passwordStrength.classList.add('empty');
                        if (strengthText) strengthText.textContent = '';
                        if (passwordFeedback) passwordFeedback.textContent = '';
                    } else if (strength < 3) {
                        passwordStrength.classList.add('weak');
                        if (strengthText) strengthText.textContent = 'Weak';
                        if (passwordFeedback) passwordFeedback.textContent = 'Weak password';
                    } else if (strength < 5) {
                        passwordStrength.classList.add('medium');
                        if (strengthText) strengthText.textContent = 'Medium';
                        if (passwordFeedback) passwordFeedback.textContent = 'Medium strength password';
                    } else {
                        passwordStrength.classList.add('strong');
                        if (strengthText) strengthText.textContent = 'Strong';
                        if (passwordFeedback) passwordFeedback.textContent = 'Strong password';
                    }
                    
                    // Force a reflow to ensure the CSS transition works
                    passwordStrength.offsetHeight;
                });
            }
            
            // Check if passwords match
            confirmPasswordInput.addEventListener('input', function() {
                const password = passwordInput.value;
                const confirmPassword = this.value;
                const passwordMatchFeedback = document.getElementById('passwordMatchFeedback');
                
                if (confirmPassword === '') {
                    this.classList.remove('invalid');
                    this.classList.remove('valid');
                    if (passwordMatchFeedback) passwordMatchFeedback.textContent = '';
                } else if (password === confirmPassword) {
                    this.classList.remove('invalid');
                    this.classList.add('valid');
                    if (passwordMatchFeedback) {
                        passwordMatchFeedback.textContent = 'Passwords match';
                        passwordMatchFeedback.style.color = '#4caf50';
                    }
                } else {
                    this.classList.add('invalid');
                    this.classList.remove('valid');
                    if (passwordMatchFeedback) {
                        passwordMatchFeedback.textContent = 'Passwords do not match';
                        passwordMatchFeedback.style.color = '#f44336';
                    }
                }
            });
            
            // Setup password toggle buttons
            const passwordToggles = document.querySelectorAll('.password-toggle');
            passwordToggles.forEach(toggle => {
                toggle.addEventListener('click', function() {
                    const passwordInput = this.parentElement.querySelector('input');
                    const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
                    passwordInput.setAttribute('type', type);
                    
                    // Toggle icon
                    const icon = this.querySelector('i');
                    icon.classList.toggle('fa-eye');
                    icon.classList.toggle('fa-eye-slash');
                });
            });
            
            // Form submission
            registerForm.addEventListener('submit', async function(e) {
                e.preventDefault();
                
                // Validate form
                const firstName = document.getElementById('firstName').value.trim();
                const lastName = document.getElementById('lastName').value.trim();
                const username = document.getElementById('username').value.trim();
                const email = document.getElementById('email').value.trim();
                const password = passwordInput.value;
                const confirmPassword = confirmPasswordInput.value;
                
                // Basic validation
                if (!username || !email || !password || !confirmPassword) {
                    showMessage('Please fill in all required fields', 'error');
                    return;
                }
                
                if (password !== confirmPassword) {
                    showMessage('Passwords do not match', 'error');
                    return;
                }
                
                // Email validation
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
                if (!emailRegex.test(email)) {
                    showMessage('Please enter a valid email address', 'error');
                    return;
                }
                
                // Password strength validation
                let strength = 0;
                if (password.length >= 8) strength += 1;
                if (/[A-Z]/.test(password)) strength += 1;
                if (/[a-z]/.test(password)) strength += 1;
                if (/[0-9]/.test(password)) strength += 1;
                if (/[^A-Za-z0-9]/.test(password)) strength += 1;
                
                if (strength < 3) {
                    showMessage('Password is too weak. Please make it stronger.', 'error');
                    return;
                }
                
                // Disable form and show loading
                const submitBtn = document.querySelector('button[type="submit"]');
                submitBtn.disabled = true;
                submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Registering...';
                
                try {
                    // Send registration request
                    const response = await fetch('/api/auth/register', {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        body: JSON.stringify({
                            username,
                            email,
                            password,
                            first_name: firstName,
                            last_name: lastName
                        })
                    });
                    
                    const data = await response.json();
                    
                    if (response.ok) {
                        // Store token and user info in localStorage
                        localStorage.setItem('auth_token', data.token);
                        localStorage.setItem('user_info', JSON.stringify(data.user));
                        
                        showMessage('Registration successful! Redirecting to dashboard...', 'success');
                        setTimeout(() => {
                            window.location.href = 'index.html';
                        }, 2000);
                    } else {
                        showMessage(data.error || data.message || 'Registration failed. Please try again.', 'error');
                    }
                } catch (error) {
                    showMessage('Network error. Please check your connection and try again.', 'error');
                    console.error('Registration error:', error);
                } finally {
                    // Re-enable form
                    submitBtn.disabled = false;
                    submitBtn.innerHTML = 'Register';
                }
            });
            
            // Helper function to show messages
            function showMessage(message, type) {
                authMessage.textContent = message;
                authMessage.className = 'auth-message';
                authMessage.classList.add(type);
                authMessage.style.display = 'block';
                // Scroll to message
                authMessage.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
            }
        });
        
        // Theme initialization
        function setTheme(isDark) {
            document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
        }

        function initializeTheme() {
            // Check for saved theme preference
            const savedTheme = localStorage.getItem('darkMode');
            
            if (savedTheme !== null) {
                // Use saved preference
                setTheme(savedTheme === 'true');
            } else {
                // Use system preference as fallback
                const prefersDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
                setTheme(prefersDarkMode);
            }
        }

        // Initialize theme when page loads
        document.addEventListener('DOMContentLoaded', initializeTheme);
    </script>

    <!-- Footer Width Fix -->
    <script src="footer-fix.js?v=20251024001"></script>
    
    <!-- Footer Content Manager -->
    <script src="footer-content.js?v=20250119001"></script>

    <!-- Powered by Warracker Footer -->
    <footer class="warracker-footer" id="warrackerFooter">
        <!-- Content will be dynamically generated by footer-content.js -->
    </footer>
</body>
</html>