brewmaster-pos / index.html
Ino1213213's picture
7. Main Modules & Instructions
37fed12 verified
Raw History Blame Contribute Delete
51.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Engr's Brew Point of Sale System - Login to manage your coffee shop operations"> <title>Engr's Brew | POS Login</title> <style> /* CSS Reset */ * { box-sizing: border-box; margin: 0; padding: 0; } :root { --primary-color: #4d2c1d; --primary-dark: #3a2115; --background-color: #f7e3c1; --error-color: #d00; --success-color: #0a0; --text-color: #333; --light-text: #666; --white: #fff; --shadow: 0 4px 10px rgba(0,0,0,0.2); --border-radius: 30px; --transition: all 0.3s ease; } body { margin: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; height: 100vh; overflow: hidden; background-color: var(--background-color); line-height: 1.6; color: var(--text-color); } /* Skip link for accessibility */ .skip-link { position: absolute; top: -40px; left: 0; background: var(--primary-color); color: var(--white); padding: 8px 16px; z-index: 100; text-decoration: none; border-radius: 0 0 4px 0; font-weight: 600; transition: var(--transition); } .skip-link:focus { top: 0; outline: 2px solid var(--primary-color); outline-offset: 2px; } .left { flex: 0 0 55%; /* Reduced from 60% */ background-color: var(--background-color); display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; } .fixed-img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; } .left:hover .fixed-img { transform: scale(1.02); } .image-overlay { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.7), transparent); color: var(--white); padding: 30px; text-align: center; } .image-overlay h1 { font-size: 2.5rem; margin-bottom: 10px; text-shadow: 0 2px 4px rgba(0,0,0,0.5); } .image-overlay p { font-size: 1.2rem; opacity: 0.9; max-width: 80%; margin: 0 auto; } .right { flex: 0 0 45%; /* Adjusted to match left side */ display: flex; align-items: center; justify-content: center; padding: 30px; /* Reduced padding */ background: var(--background-color); } .form-container { width: 100%; max-width: 380px; /* Slightly smaller max-width */ background: var(--white); padding: 30px; border-radius: var(--border-radius); box-shadow: var(--shadow); text-align: center; transition: var(--transition); } .form-container:hover { box-shadow: 0 6px 15px rgba(0,0,0,0.15); } .form-container p { margin-bottom: 20px; color: var(--primary-color); font-size: 1.1rem; } .form-container img { width: 80px; /* Slightly smaller logo */ margin-bottom: 15px; transition: transform 0.3s ease; } .form-container img:hover { transform: scale(1.05); } .form-container h2 { color: var(--primary-color); margin-bottom: 15px; font-size: 1.6rem; /* Slightly smaller heading */ } .form-group { margin-bottom: 18px; /* Reduced spacing */ text-align: left; position: relative; } label { display: block; font-size: 14px; color: var(--primary-color); margin-bottom: 8px; font-weight: 600; } input, select { width: 100%; padding: 12px 15px; border: 1px solid #ccc; border-radius: 8px; font-size: 16px; transition: var(--transition); background-color: #f9f9f9; } /* Focus styles for accessibility */ input:focus, select:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; border-color: var(--primary-color); background-color: var(--white); box-shadow: 0 0 0 3px rgba(77, 44, 29, 0.1); } .password-wrapper { position: relative; display: flex; align-items: center; } .password-wrapper input { padding-right: 50px; } .toggle { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); cursor: pointer; font-size: 18px; color: var(--light-text); padding: 5px; border-radius: 3px; transition: var(--transition); background: none; border: none; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; } .toggle:hover { background-color: rgba(0,0,0,0.05); } .toggle:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; } .form-remember-container { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .form-remember { display: flex; align-items: center; gap: 8px; } .form-remember input[type="checkbox"] { width: 18px; height: 18px; margin: 0; } .form-remember label { margin: 0; font-size: 14px; color: var(--primary-color); cursor: pointer; font-weight: normal; } .forgot-password { font-size: 14px; color: var(--primary-color); cursor: pointer; text-decoration: underline; transition: color 0.2s; font-weight: 500; background: none; border: none; } .forgot-password:hover { color: var(--primary-dark); } .btn { width: 100%; padding: 14px; background: var(--primary-color); color: var(--white); border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 10px; transition: var(--transition); position: relative; overflow: hidden; } .btn:hover { background: var(--primary-dark); transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.2); } .btn:active { transform: translateY(0); } .btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; } .btn-text, .btn-loading { display: inline-block; transition: opacity 0.3s; } .btn-loading { display: none; } .link { margin-top: 15px; font-size: 14px; color: var(--primary-color); cursor: pointer; display: block; text-decoration: underline; transition: color 0.2s; font-weight: 500; background: none; border: none; margin-left: 60px; } .form-container .link { text-align: center; margin-left: 0; width: 100%; } .link:hover { color: var(--primary-dark); } .feedback { font-size: 12px; margin-top: 5px; min-height: 16px; padding-left: 5px; } .error-message { background: #ffe6e6; color: var(--error-color); padding: 12px 15px; border-radius: 8px; margin-bottom: 20px; font-size: 14px; display: none; border-left: 4px solid var(--error-color); } .success-message { background: #e6ffe6; color: var(--success-color); padding: 12px 15px; border-radius: 8px; margin-bottom: 20px; font-size: 14px; display: none; border-left: 4px solid var(--success-color); } /* PIN Input Styles */ .pin-container { display: flex; justify-content: space-between; margin-bottom: 20px; } .pin-input { width: 50px; height: 60px; text-align: center; font-size: 24px; font-weight: bold; border: 2px solid #ddd; border-radius: 8px; background-color: #f9f9f9; transition: var(--transition); } .pin-input:focus { border-color: var(--primary-color); outline: none; box-shadow: 0 0 0 3px rgba(77, 44, 29, 0.1); } .pin-input.filled { border-color: var(--primary-color); background-color: #fff; } .resend-container { text-align: center; margin-top: 15px; } .resend-text { font-size: 14px; align-items: center; color: var(--light-text); } .resend-link { color: var(--primary-color); cursor: pointer; text-decoration: underline; font-weight: 500; background: none; border: none; } .resend-link:hover { color: var(--primary-dark); } .resend-link:disabled { color: var(--light-text); cursor: not-allowed; } /* Loading animation */ @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .loading-spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: var(--white); animation: spin 1s ease-in-out infinite; margin-right: 10px; vertical-align: middle; } /* Responsive */ @media (max-width: 1024px) { .left { flex: 0 0 50%; } .right { flex: 0 0 50%; padding: 30px; } } @media (max-width: 768px) { body { flex-direction: column; overflow: auto; height: auto; min-height: 100vh; } .left { flex: 0 0 40vh; min-height: 200px; } .right { flex: 1; width: 100%; padding: 20px; } .form-container { padding: 25px; margin: 0; max-width: 100%; } .image-overlay h1 { font-size: 2rem; } .image-overlay p { font-size: 1rem; } .form-remember-container { flex-direction: column; align-items: flex-start; gap: 10px; } .pin-container { justify-content: space-around; } .pin-input { width: 45px; height: 55px; } } @media (max-width: 480px) { .form-container { padding: 20px 15px; } .right { padding: 15px; } .pin-input { width: 40px; height: 50px; font-size: 20px; } } </style> </head> <body> <a href="#main-content" class="skip-link">Skip to main content</a> <div class="left"> <img src="img/EB_bg.jpg" alt="Engr's Brew coffee shop interior with warm lighting, showcasing the cozy atmosphere and coffee preparation area" class="fixed-img"> <div class="image-overlay"> <!-- Text removed as requested --> </div> </div> <div class="right"> <!-- LOGIN FORM --> <div class="form-container" id="loginForm" role="main" id="main-content"> <img src="img/EB_logo.png" alt="Engr's Brew Logo - A stylized coffee cup with engineering elements"> <h2>Engr's Brew</h2> <p>Let's login to your account</p> <div id="loginError" class="error-message" role="alert" aria-live="polite"></div> <div id="loginSuccess" class="success-message" role="alert" aria-live="polite"></div> <form action="login.php" method="POST" id="loginFormElement" novalidate> <!-- CSRF Token (would be generated by server in production) --> <input type="hidden" name="csrf_token" id="loginCsrfToken"> <div class="form-group"> <label for="loginEmail">Email Address</label> <input type="email" name="email" id="loginEmail" required aria-describedby="email-help" autocomplete="email"> </div> <div class="form-group"> <label for="loginPassword">Password</label> <div class="password-wrapper"> <input type="password" name="password" id="loginPassword" required aria-describedby="password-help" autocomplete="current-password"> <button type="button" class="toggle" onclick="togglePassword('loginPassword', this)" tabindex="0" aria-label="Show password"> <span aria-hidden="true">👁️</span> </button> </div> </div> <div class="form-remember-container"> <div class="form-remember"> <input type="checkbox" id="remember" name="remember"> <label for="remember">Remember me</label> </div> <button type="button" class="forgot-password" onclick="switchForm('forgotPasswordForm')" tabindex="0" aria-label="Forgot password">Forgot Password?</button> </div> <button type="submit" class="btn" id="loginBtn" aria-label="Login to your account"> <span class="btn-text">Login</span> <span class="btn-loading"><span class="loading-spinner" aria-hidden="true"></span>Logging in...</span> </button> </form> <button class="link" onclick="switchForm('signupForm')" tabindex="0" role="button" aria-label="Switch to sign up form">Don't have an account? Sign Up</button> <button class="link" onclick="window.location.href='documentation.html'" tabindex="0" role="button" aria-label="View documentation" style="margin-top: 10px;">View Documentation</button> </div> <!-- SIGNUP FORM --> <div class="form-container" id="signupForm" style="display:none;" role="main"> <img src="img/EB_logo.png" alt="Engr's Brew Logo - A stylized coffee cup with engineering elements"> <h2>Engr's Brew</h2> <p>Let's create an account</p> <div id="signupError" class="error-message" role="alert" aria-live="polite"></div> <div id="signupSuccess" class="success-message" role="alert" aria-live="polite"></div> <form action="signup.php" method="POST" id="signupFormElement" novalidate> <!-- CSRF Token (would be generated by server in production) --> <input type="hidden" name="csrf_token" id="signupCsrfToken"> <div class="form-group"> <label for="fullname">Full Name</label> <input type="text" name="fullname" id="fullname" required autocomplete="name"> </div> <div class="form-group"> <label for="signupEmail">Email Address</label> <input type="email" name="email" id="signupEmail" required autocomplete="email"> <div id="emailFeedback" class="feedback"></div> </div> <div class="form-group"> <label for="signupPassword">Password</label> <div class="password-wrapper"> <input type="password" name="password" id="signupPassword" required autocomplete="new-password"> <button type="button" class="toggle" onclick="togglePassword('signupPassword', this)" tabindex="0" aria-label="Show password"> <span aria-hidden="true">👁️</span> </button> </div> <div id="passwordFeedback" class="feedback"></div> </div> <div class="form-group"> <label for="confirmPassword">Confirm Password</label> <div class="password-wrapper"> <input type="password" name="confirm_password" id="confirmPassword" required autocomplete="new-password"> <button type="button" class="toggle" onclick="togglePassword('confirmPassword', this)" tabindex="0" aria-label="Show password"> <span aria-hidden="true">👁️</span> </button> </div> <div id="confirmFeedback" class="feedback"></div> </div> <button type="submit" class="btn" id="signupBtn"> <span class="btn-text">Sign Up</span> <span class="btn-loading"><span class="loading-spinner" aria-hidden="true"></span>Creating account...</span> </button> </form> <button class="link" onclick="switchForm('loginForm')" tabindex="0" role="button" aria-label="Switch to login form">Already have an account? Login</button> </div> <!-- FORGOT PASSWORD FORM --> <div class="form-container" id="forgotPasswordForm" style="display:none;" role="main"> <img src="img/EB_logo.png" alt="Engr's Brew Logo - A stylized coffee cup with engineering elements"> <h2>Forgot Password</h2> <p>Enter your email to receive a reset code</p> <div id="forgotError" class="error-message" role="alert" aria-live="polite"></div> <div id="forgotSuccess" class="success-message" role="alert" aria-live="polite"></div> <form id="forgotPasswordFormElement" novalidate> <input type="hidden" name="csrf_token" id="forgotCsrfToken"> <div class="form-group"> <label for="forgotEmail">Email Address</label> <input type="email" name="email" id="forgotEmail" required autocomplete="email"> </div> <button type="submit" class="btn" id="sendCodeBtn"> <span class="btn-text">Send Reset Code</span> <span class="btn-loading"><span class="loading-spinner" aria-hidden="true"></span>Sending code...</span> </button> </form> <button class="link" onclick="switchForm('loginForm')" tabindex="0" role="button" aria-label="Switch to login form">Back to Login</button> </div> <!-- VERIFY CODE FORM --> <div class="form-container" id="verifyCodeForm" style="display:none;" role="main"> <img src="img/EB_logo.png" alt="Engr's Brew Logo - A stylized coffee cup with engineering elements"> <h2>Verify Code</h2> <p>Enter the 6-digit code sent to your email</p> <div id="verifyError" class="error-message" role="alert" aria-live="polite"></div> <div id="verifySuccess" class="success-message" role="alert" aria-live="polite"></div> <form id="verifyCodeFormElement" novalidate> <input type="hidden" name="csrf_token" id="verifyCsrfToken"> <input type="hidden" name="email" id="verifyEmail"> <div class="form-group"> <label for="pin-inputs">Verification Code</label> <div class="pin-container" id="pin-container"> <input type="text" class="pin-input" maxlength="1" data-index="0"> <input type="text" class="pin-input" maxlength="1" data-index="1"> <input type="text" class="pin-input" maxlength="1" data-index="2"> <input type="text" class="pin-input" maxlength="1" data-index="3"> <input type="text" class="pin-input" maxlength="1" data-index="4"> <input type="text" class="pin-input" maxlength="1" data-index="5"> </div> <input type="hidden" name="code" id="pinCode"> </div> <div class="resend-container"> <span class="resend-text">Didn't receive the code?</span> <button type="button" class="resend-link" id="resendCodeBtn" onclick="resendCode()">Resend Code</button> <span id="countdown" class="resend-text" style="display: none;"></span> </div> <button type="submit" class="btn" id="verifyCodeBtn"> <span class="btn-text">Verify Code</span> <span class="btn-loading"><span class="loading-spinner" aria-hidden="true"></span>Verifying...</span> </button> </form> <button class="link" onclick="switchForm('forgotPasswordForm')" tabindex="0" role="button" aria-label="Switch to forgot password form">Back</button> </div> <!-- RESET PASSWORD FORM --> <div class="form-container" id="resetPasswordForm" style="display:none;" role="main"> <img src="img/EB_logo.png" alt="Engr's Brew Logo - A stylized coffee cup with engineering elements"> <h2>Reset Password</h2> <p>Create your new password</p> <div id="resetError" class="error-message" role="alert" aria-live="polite"></div> <div id="resetSuccess" class="success-message" role="alert" aria-live="polite"></div> <form id="resetPasswordFormElement" novalidate> <input type="hidden" name="csrf_token" id="resetCsrfToken"> <input type="hidden" name="email" id="resetEmail"> <input type="hidden" name="code" id="resetCode"> <div class="form-group"> <label for="resetNewPassword">New Password</label> <div class="password-wrapper"> <input type="password" name="new_password" id="resetNewPassword" required autocomplete="new-password"> <button type="button" class="toggle" onclick="togglePassword('resetNewPassword', this)" tabindex="0" aria-label="Show password"> <span aria-hidden="true">👁️</span> </button> </div> <div id="resetPasswordFeedback" class="feedback"></div> </div> <div class="form-group"> <label for="resetConfirmPassword">Confirm Password</label> <div class="password-wrapper"> <input type="password" name="confirm_password" id="resetConfirmPassword" required autocomplete="new-password"> <button type="button" class="toggle" onclick="togglePassword('resetConfirmPassword', this)" tabindex="0" aria-label="Show password"> <span aria-hidden="true">👁️</span> </button> </div> <div id="resetConfirmFeedback" class="feedback"></div> </div> <button type="submit" class="btn" id="resetPasswordBtn"> <span class="btn-text">Reset Password</span> <span class="btn-loading"><span class="loading-spinner" aria-hidden="true"></span>Resetting password...</span> </button> </form> <button class="link" onclick="switchForm('loginForm')" tabindex="0" role="button" aria-label="Switch to login form">Back to Login</button> </div> </div> <script> // Generate a simple CSRF token (in production, this would come from the server) function generateCsrfToken() { return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); } // Initialize CSRF tokens and form event listeners document.addEventListener('DOMContentLoaded', function() { document.getElementById('loginCsrfToken').value = generateCsrfToken(); document.getElementById('signupCsrfToken').value = generateCsrfToken(); document.getElementById('forgotCsrfToken').value = generateCsrfToken(); document.getElementById('verifyCsrfToken').value = generateCsrfToken(); document.getElementById('resetCsrfToken').value = generateCsrfToken(); // Add form submission event listeners document.getElementById('loginFormElement').addEventListener('submit', handleLoginSubmit); document.getElementById('signupFormElement').addEventListener('submit', handleSignupSubmit); document.getElementById('forgotPasswordFormElement').addEventListener('submit', handleForgotPasswordSubmit); document.getElementById('verifyCodeFormElement').addEventListener('submit', handleVerifyCodeSubmit); document.getElementById('resetPasswordFormElement').addEventListener('submit', handleResetPasswordSubmit); // Initialize PIN input functionality initPinInputs(); // Initialize password validation for reset form initResetPasswordValidation(); }); function switchForm(formId) { // Clear the current form before switching clearFormFields(); // Hide all forms document.getElementById("loginForm").style.display = "none"; document.getElementById("signupForm").style.display = "none"; document.getElementById("forgotPasswordForm").style.display = "none"; document.getElementById("verifyCodeForm").style.display = "none"; document.getElementById("resetPasswordForm").style.display = "none"; // Show the target form document.getElementById(formId).style.display = "block"; // Reset errors when switching forms hideMessages('loginError', 'loginSuccess'); hideMessages('signupError', 'signupSuccess'); hideMessages('forgotError', 'forgotSuccess'); hideMessages('verifyError', 'verifySuccess'); hideMessages('resetError', 'resetSuccess'); // Focus on the first input of the form if (formId === 'loginForm') { document.getElementById('loginEmail').focus(); } else if (formId === 'signupForm') { document.getElementById('fullname').focus(); } else if (formId === 'forgotPasswordForm') { document.getElementById('forgotEmail').focus(); } else if (formId === 'verifyCodeForm') { document.querySelector('.pin-input').focus(); } else if (formId === 'resetPasswordForm') { document.getElementById('resetNewPassword').focus(); } } function clearFormFields() { // Clear login form fields document.getElementById('loginEmail').value = ''; document.getElementById('loginPassword').value = ''; document.getElementById('remember').checked = false; // Reset password visibility for login form const loginToggle = document.querySelector('#loginPassword').nextElementSibling; if (loginToggle && loginToggle.classList.contains('toggle')) { loginToggle.innerHTML = '<span aria-hidden="true">👁️</span>'; loginToggle.setAttribute('aria-label', 'Show password'); } document.getElementById('loginPassword').type = 'password'; // Clear signup form fields document.getElementById('fullname').value = ''; document.getElementById('signupEmail').value = ''; document.getElementById('signupPassword').value = ''; document.getElementById('confirmPassword').value = ''; // Reset password visibility for signup form const signupToggle = document.querySelector('#signupPassword').nextElementSibling; if (signupToggle && signupToggle.classList.contains('toggle')) { signupToggle.innerHTML = '<span aria-hidden="true">👁️</span>'; signupToggle.setAttribute('aria-label', 'Show password'); } document.getElementById('signupPassword').type = 'password'; const confirmToggle = document.querySelector('#confirmPassword').nextElementSibling; if (confirmToggle && confirmToggle.classList.contains('toggle')) { confirmToggle.innerHTML = '<span aria-hidden="true">👁️</span>'; confirmToggle.setAttribute('aria-label', 'Show password'); } document.getElementById('confirmPassword').type = 'password'; // Clear forgot password form document.getElementById('forgotEmail').value = ''; // Clear verify code form document.querySelectorAll('.pin-input').forEach(input => { input.value = ''; input.classList.remove('filled'); }); document.getElementById('pinCode').value = ''; // Clear reset password form document.getElementById('resetNewPassword').value = ''; document.getElementById('resetConfirmPassword').value = ''; // Reset password visibility for reset form const resetToggle = document.querySelector('#resetNewPassword').nextElementSibling; if (resetToggle && resetToggle.classList.contains('toggle')) { resetToggle.innerHTML = '<span aria-hidden="true">👁️</span>'; resetToggle.setAttribute('aria-label', 'Show password'); } document.getElementById('resetNewPassword').type = 'password'; const resetConfirmToggle = document.querySelector('#resetConfirmPassword').nextElementSibling; if (resetConfirmToggle && resetConfirmToggle.classList.contains('toggle')) { resetConfirmToggle.innerHTML = '<span aria-hidden="true">👁️</span>'; resetConfirmToggle.setAttribute('aria-label', 'Show password'); } document.getElementById('resetConfirmPassword').type = 'password'; // Clear feedback messages if (document.getElementById('emailFeedback')) { document.getElementById('emailFeedback').textContent = ''; } if (document.getElementById('passwordFeedback')) { document.getElementById('passwordFeedback').textContent = ''; } if (document.getElementById('confirmFeedback')) { document.getElementById('confirmFeedback').textContent = ''; } if (document.getElementById('resetPasswordFeedback')) { document.getElementById('resetPasswordFeedback').textContent = ''; } if (document.getElementById('resetConfirmFeedback')) { document.getElementById('resetConfirmFeedback').textContent = ''; } // Reset resend code button const resendBtn = document.getElementById('resendCodeBtn'); if (resendBtn) { resendBtn.disabled = false; resendBtn.textContent = 'Resend Code'; } const countdown = document.getElementById('countdown'); if (countdown) { countdown.style.display = 'none'; } } function togglePassword(id, el) { let input = document.getElementById(id); if (input.type === "password") { input.type = "text"; el.innerHTML = '<span aria-hidden="true">🙈</span>'; el.setAttribute('aria-label', 'Hide password'); } else { input.type = "password"; el.innerHTML = '<span aria-hidden="true">👁️</span>'; el.setAttribute('aria-label', 'Show password'); } // Refocus on the input for better UX input.focus(); } // Enable toggle with keyboard document.querySelectorAll('.toggle').forEach(toggle => { toggle.addEventListener('keydown', function(e) { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); const inputId = this.parentElement.querySelector('input').id; togglePassword(inputId, this); } }); }); function setButtonLoading(btn, isLoading) { const btnText = btn.querySelector('.btn-text'); const btnLoading = btn.querySelector('.btn-loading'); if (isLoading) { btn.disabled = true; btnText.style.display = 'none'; btnLoading.style.display = 'inline'; } else { btn.disabled = false; btnText.style.display = 'inline'; btnLoading.style.display = 'none'; } } function hideMessages(errorId, successId) { const errorElement = document.getElementById(errorId); const successElement = document.getElementById(successId); if (errorElement) errorElement.style.display = 'none'; if (successElement) successElement.style.display = 'none'; } // PIN Input Functionality function initPinInputs() { const pinInputs = document.querySelectorAll('.pin-input'); pinInputs.forEach((input, index) => { // Handle input input.addEventListener('input', (e) => { const value = e.target.value; if (value.length === 1) { input.classList.add('filled'); // Move to next input if available if (index < pinInputs.length - 1) { pinInputs[index + 1].focus(); } } else { input.classList.remove('filled'); } updatePinCode(); }); // Handle backspace input.addEventListener('keydown', (e) => { if (e.key === 'Backspace' && input.value === '' && index > 0) { pinInputs[index - 1].focus(); } }); // Handle paste input.addEventListener('paste', (e) => { e.preventDefault(); const pasteData = e.clipboardData.getData('text').slice(0, 6); pasteData.split('').forEach((char, i) => { if (pinInputs[i]) { pinInputs[i].value = char; pinInputs[i].classList.add('filled'); } }); // Focus the last filled input const lastFilledIndex = Math.min(pasteData.length, pinInputs.length - 1); pinInputs[lastFilledIndex].focus(); updatePinCode(); }); }); }handleVerifyCodeSubmit function updatePinCode() { const pinInputs = document.querySelectorAll('.pin-input'); let code = ''; pinInputs.forEach(input => { code += input.value; }); document.getElementById('pinCode').value = code; } // Resend Code Functionality function resendCode() { const email = document.getElementById('verifyEmail').value; const btn = document.getElementById('resendCodeBtn'); if (!email) { showMessage('verifyError', 'Email is required to resend code'); return; } // Disable resend button and start countdown btn.disabled = true; startResendCountdown(); // Make AJAX call to resend code fetch('forgot-password.php', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email: email, resend: true, csrf_token: document.getElementById('verifyCsrfToken').value }) }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { if (data.success) { showMessage('verifySuccess', 'A new code has been sent to your email', 'success'); } else { showMessage('verifyError', data.message || 'Failed to resend code'); btn.disabled = false; document.getElementById('countdown').style.display = 'none'; } }) .catch(error => { console.error('Error:', error); showMessage('verifyError', 'An error occurred. Please try again.'); btn.disabled = false; document.getElementById('countdown').style.display = 'none'; }); } function startResendCountdown() { const countdownElement = document.getElementById('countdown'); const btn = document.getElementById('resendCodeBtn'); let timeLeft = 60; // 60 seconds countdownElement.style.display = 'inline'; countdownElement.textContent = ` (${timeLeft}s)`; const countdownInterval = setInterval(() => { timeLeft--; countdownElement.textContent = ` (${timeLeft}s)`; if (timeLeft <= 0) { clearInterval(countdownInterval); countdownElement.style.display = 'none'; btn.disabled = false; btn.textContent = 'Resend Code'; } }, 1000); } // Forgot Password Function function handleForgotPasswordSubmit(e) { e.preventDefault(); const form = e.target; const btn = document.getElementById('sendCodeBtn'); setButtonLoading(btn, true); const email = document.getElementById('forgotEmail').value.trim(); if (!email) { showMessage('forgotError', 'Please enter your email address'); setButtonLoading(btn, false); return false; } if (!isEmailValid(email)) { showMessage('forgotError', 'Please enter a valid email address'); setButtonLoading(btn, false); return false; } // Create FormData object const formData = new FormData(form); // Make AJAX call to forgot-password.php fetch('forgot-password.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams(formData) }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { setButtonLoading(btn, false); if (data.success) { showMessage('forgotSuccess', data.message, 'success'); // Store email for next step document.getElementById('verifyEmail').value = email; document.getElementById('resetEmail').value = email; // Switch to verify code form after a short delay setTimeout(() => { switchForm('verifyCodeForm'); startResendCountdown(); // Start countdown for resend button }, 1500); } else { showMessage('forgotError', data.message); } }) .catch(error => { setButtonLoading(btn, false); console.error('Error:', error); showMessage('forgotError', 'An error occurred. Please try again.'); }); return false; } // Verify Code Function function handleVerifyCodeSubmit(e) { e.preventDefault(); const form = e.target; const btn = document.getElementById('verifyCodeBtn'); setButtonLoading(btn, true); const code = document.getElementById('pinCode').value; const email = document.getElementById('verifyEmail').value; if (!code || code.length !== 6) { showMessage('verifyError', 'Please enter the 6-digit code'); setButtonLoading(btn, false); return false; } // Create FormData object const formData = new FormData(form); console.log("Sending verification request:", { email: email, code: code }); // Make AJAX call to verify-code.php fetch('verify-code.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ 'email': email, 'code': code, 'csrf_token': document.getElementById('verifyCsrfToken').value }) }) .then(response => { console.log("Response status:", response.status); if (!response.ok) { throw new Error('Network response was not ok: ' + response.status); } return response.json(); }) .then(data => { console.log("Response data:", data); setButtonLoading(btn, false); if (data.success) { showMessage('verifySuccess', data.message, 'success'); // Store code for next step document.getElementById('resetCode').value = code; // Switch to reset password form after a short delay setTimeout(() => { switchForm('resetPasswordForm'); }, 1000); } else { showMessage('verifyError', data.message); } }) .catch(error => { setButtonLoading(btn, false); console.error('Error:', error); showMessage('verifyError', 'An error occurred: ' + error.message); }); return false; } // Reset Password Validation function initResetPasswordValidation() { const newPasswordInput = document.getElementById("resetNewPassword"); const newPasswordFeedback = document.getElementById("resetPasswordFeedback"); const confirmInput = document.getElementById("resetConfirmPassword"); const confirmFeedback = document.getElementById("resetConfirmFeedback"); newPasswordInput?.addEventListener("input", () => { const pass = newPasswordInput.value; if (pass.length === 0) { newPasswordFeedback.textContent = ""; return; } if (isPasswordValid(pass)) { newPasswordFeedback.textContent = "✓ Strong password"; newPasswordFeedback.style.color = "green"; } else { newPasswordFeedback.textContent = "✗ Password must be at least 8 characters with uppercase, lowercase, number, and symbol"; newPasswordFeedback.style.color = "red"; } // Update confirm password validation validateResetPasswordMatch(); }); confirmInput?.addEventListener("input", validateResetPasswordMatch); } function validateResetPasswordMatch() { const password = document.getElementById("resetNewPassword").value; const confirm = document.getElementById("resetConfirmPassword").value; const confirmFeedback = document.getElementById("resetConfirmFeedback"); if (confirm.length === 0) { confirmFeedback.textContent = ""; } else if (password === confirm) { confirmFeedback.textContent = "✓ Passwords match"; confirmFeedback.style.color = "green"; } else { confirmFeedback.textContent = "✗ Passwords do not match"; confirmFeedback.style.color = "red"; } } // Reset Password Function function handleResetPasswordSubmit(e) { e.preventDefault(); const form = e.target; const btn = document.getElementById('resetPasswordBtn'); setButtonLoading(btn, true); const newPassword = document.getElementById('resetNewPassword').value; const confirmPassword = document.getElementById('resetConfirmPassword').value; // Validate form if (!newPassword || !confirmPassword) { showMessage('resetError', 'Please fill in all fields'); setButtonLoading(btn, false); return false; } if (newPassword !== confirmPassword) { showMessage('resetError', 'Passwords do not match'); setButtonLoading(btn, false); return false; } if (!isPasswordValid(newPassword)) { showMessage('resetError', 'Password must be at least 8 characters and contain uppercase, lowercase, number, and symbol'); setButtonLoading(btn, false); return false; } // Create FormData object const formData = new FormData(form); // Make AJAX call to reset-password.php fetch('reset-password.php', { method: 'POST', body: formData }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { setButtonLoading(btn, false); if (data.success) { showMessage('resetSuccess', data.message, 'success'); // Switch to login form after successful password reset setTimeout(() => { switchForm('loginForm'); }, 2000); } else { showMessage('resetError', data.message); } }) .catch(error => { setButtonLoading(btn, false); console.error('Error:', error); showMessage('resetError', 'An error occurred. Please try again.'); }); return false; } // Updated Login Function with Real AJAX function handleLoginSubmit(e) { e.preventDefault(); const form = e.target; const btn = form.querySelector('.btn'); setButtonLoading(btn, true); // Simple validation const email = document.getElementById('loginEmail').value; const password = document.getElementById('loginPassword').value; if (!email || !password) { showMessage('loginError', 'Please fill in all fields'); setButtonLoading(btn, false); return false; } // Create FormData object const formData = new FormData(form); // Make AJAX call to login.php fetch('login.php', { method: 'POST', body: formData }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { setButtonLoading(btn, false); if (data.success) { showMessage('loginSuccess', data.message, 'success'); // Redirect after successful login setTimeout(() => { if (data.redirect) { window.location.href = data.redirect; } else { window.location.href = 'dashboard.php'; } }, 1000); } else { showMessage('loginError', data.message); } }) .catch(error => { setButtonLoading(btn, false); console.error('Error:', error); showMessage('loginError', 'An error occurred. Please try again.'); }); return false; // Prevent default form submission } // Updated Signup Function with Real AJAX function handleSignupSubmit(e) { e.preventDefault(); const form = e.target; const btn = form.querySelector('.btn'); setButtonLoading(btn, true); // Validate form first if (!validateSignupForm()) { setButtonLoading(btn, false); return false; } // Create FormData object const formData = new FormData(form); // Make AJAX call to signup.php fetch('signup.php', { method: 'POST', body: formData }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { setButtonLoading(btn, false); if (data.success) { showMessage('signupSuccess', data.message, 'success'); // Switch to login form after successful signup setTimeout(() => { switchForm('loginForm'); }, 2000); } else { showMessage('signupError', data.message); } }) .catch(error => { setButtonLoading(btn, false); console.error('Error:', error); showMessage('signupError', 'An error occurred. Please try again.'); }); return false; // Prevent default form submission } function validateSignupForm() { const fullname = document.getElementById('fullname').value.trim(); const email = document.getElementById('signupEmail').value.trim(); const password = document.getElementById('signupPassword').value; const confirmPassword = document.getElementById('confirmPassword').value; // Check if all fields are filled if (!fullname || !email || !password || !confirmPassword) { showMessage('signupError', 'Please fill in all fields'); return false; } // Check if passwords match if (password !== confirmPassword) { showMessage('signupError', 'Passwords do not match'); return false; } // Check if password is valid if (!isPasswordValid(password)) { showMessage('signupError', 'Password must be at least 8 characters and contain uppercase, lowercase, number, and symbol'); return false; } // Check if email is valid if (!isEmailValid(email)) { showMessage('signupError', 'Please enter a valid email address'); return false; } // Clear any previous errors document.getElementById('signupError').style.display = 'none'; return true; } // Updated showMessage function to handle success and error messages function showMessage(elementId, message, type = 'error') { const messageElement = document.getElementById(elementId); const oppositeType = type === 'error' ? 'success' : 'error'; const oppositeElement = document.getElementById(elementId.replace('Error', 'Success').replace('Success', 'Error')); // Hide the opposite message type if (oppositeElement) { oppositeElement.style.display = 'none'; } messageElement.textContent = message; messageElement.style.display = 'block'; if (type === 'success') { messageElement.className = 'success-message'; } else { messageElement.className = 'error-message'; } // Scroll to the message for better visibility messageElement.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } // Utility functions function isEmailValid(email) { const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/; return pattern.test(email); } function isPasswordValid(password) { if (password.length < 8) return false; if (!/[A-Z]/.test(password)) return false; if (!/[a-z]/.test(password)) return false; if (!/[0-9]/.test(password)) return false; if (!/[!@#$%^&*(),.?":{}|<>]/.test(password)) return false; return true; } // Signup validations const emailInput = document.getElementById("signupEmail"); const emailFeedback = document.getElementById("emailFeedback"); emailInput?.addEventListener("input", () => { if (emailInput.value === "") { emailFeedback.textContent = ""; } else if (isEmailValid(emailInput.value)) { emailFeedback.textContent = "✓ Valid email"; emailFeedback.style.color = "green"; } else { emailFeedback.textContent = "✗ Invalid email format"; emailFeedback.style.color = "red"; } }); const passwordInput = document.getElementById("signupPassword"); const passwordFeedback = document.getElementById("passwordFeedback"); const confirmInput = document.getElementById("confirmPassword"); const confirmFeedback = document.getElementById("confirmFeedback"); passwordInput?.addEventListener("input", () => { const pass = passwordInput.value; if (pass.length === 0) { passwordFeedback.textContent = ""; return; } if (isPasswordValid(pass)) { passwordFeedback.textContent = "✓ Strong password"; passwordFeedback.style.color = "green"; } else { passwordFeedback.textContent = "✗ Password must be at least 8 characters with uppercase, lowercase, number, and symbol"; passwordFeedback.style.color = "red"; } // Update confirm password validation validatePasswordMatch(); }); confirmInput?.addEventListener("input", validatePasswordMatch); function validatePasswordMatch() { const password = passwordInput.value; const confirm = confirmInput.value; if (confirm.length === 0) { confirmFeedback.textContent = ""; } else if (password === confirm) { confirmFeedback.textContent = "✓ Passwords match"; confirmFeedback.style.color = "green"; } else { confirmFeedback.textContent = "✗ Passwords do not match"; confirmFeedback.style.color = "red"; } } </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Engr's Brew Point of Sale System - Login to manage your coffee shop operations">
<title>Engr's Brew | POS Login</title>
<style>
/* CSS Reset */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--primary-color: #4d2c1d;
--primary-dark: #3a2115;
--background-color: #f7e3c1;
--error-color: #d00;
--success-color: #0a0;
--text-color: #333;
--light-text: #666;
--white: #fff;
--shadow: 0 4px 10px rgba(0,0,0,0.2);
--border-radius: 30px;
--transition: all 0.3s ease;
}
body {
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
height: 100vh;
overflow: hidden;
background-color: var(--background-color);
line-height: 1.6;
color: var(--text-color);
}
/* Skip link for accessibility */
.skip-link {
position: absolute;
top: -40px;
left: 0;
background: var(--primary-color);
color: var(--white);
padding: 8px 16px;
z-index: 100;
text-decoration: none;
border-radius: 0 0 4px 0;
font-weight: 600;
transition: var(--transition);
}
.skip-link:focus {
top: 0;
outline: 2px solid var(--primary-color);
outline-offset: 2px;
}
.left {
flex: 0 0 55%; /* Reduced from 60% */
background-color: var(--background-color);
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
position: relative;
}
.fixed-img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s ease;
}
.left:hover .fixed-img {
transform: scale(1.02);
}
.image-overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
color: var(--white);
padding: 30px;
text-align: center;
}
.image-overlay h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.image-overlay p {