| 1 | <!DOCTYPE html>
|
|---|
| 2 | <html lang="en">
|
|---|
| 3 | <head>
|
|---|
| 4 | <meta charset="UTF-8">
|
|---|
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|---|
| 6 | <title>Verify 2FA - Handcraft Marketplace</title>
|
|---|
| 7 | <link rel="stylesheet" href="style.css">
|
|---|
| 8 | </head>
|
|---|
| 9 | <body>
|
|---|
| 10 | <header>
|
|---|
| 11 | <div class="logo-container">
|
|---|
| 12 | <img src="../images/administrative/logo.jpg" alt="Handcraft Marketplace Logo" onerror="this.style.display='none'">
|
|---|
| 13 | <h1>🎨 Handcraft Marketplace</h1>
|
|---|
| 14 | </div>
|
|---|
| 15 | <nav>
|
|---|
| 16 | <ul>
|
|---|
| 17 | <li><a href="index.html">Home</a></li>
|
|---|
| 18 | <li><a href="products.html">Products</a></li>
|
|---|
| 19 | <li><a href="login.html">Login</a></li>
|
|---|
| 20 | </ul>
|
|---|
| 21 | </nav>
|
|---|
| 22 | </header>
|
|---|
| 23 |
|
|---|
| 24 | <main>
|
|---|
| 25 | <div class="form-container">
|
|---|
| 26 | <h2>Two-Factor Authentication</h2>
|
|---|
| 27 | <p class="form-subtitle">Enter the verification code sent to your email</p>
|
|---|
| 28 |
|
|---|
| 29 | <form id="verify-2fa-form" class="form">
|
|---|
| 30 | <div class="form-group">
|
|---|
| 31 | <label for="code">Verification Code</label>
|
|---|
| 32 | <input type="text" id="code" maxlength="6" placeholder="000000" required>
|
|---|
| 33 | </div>
|
|---|
| 34 |
|
|---|
| 35 | <div class="form-group">
|
|---|
| 36 | <button type="submit" class="btn-primary btn-full">Verify</button>
|
|---|
| 37 | </div>
|
|---|
| 38 | </form>
|
|---|
| 39 |
|
|---|
| 40 | <div class="form-footer">
|
|---|
| 41 | <p>Didn't receive code? <a href="#" id="resend-code">Resend</a></p>
|
|---|
| 42 | <p><a href="login.html">Back to Login</a></p>
|
|---|
| 43 | </div>
|
|---|
| 44 | </div>
|
|---|
| 45 | </main>
|
|---|
| 46 |
|
|---|
| 47 | <footer>
|
|---|
| 48 | <div class="footer-content">
|
|---|
| 49 | <div class="footer-section">
|
|---|
| 50 | <h3>Handcraft Marketplace</h3>
|
|---|
| 51 | <p>Connecting artisans with buyers worldwide</p>
|
|---|
| 52 | </div>
|
|---|
| 53 | <div class="footer-section">
|
|---|
| 54 | <h3>Quick Links</h3>
|
|---|
| 55 | <ul>
|
|---|
| 56 | <li><a href="index.html">Home</a></li>
|
|---|
| 57 | <li><a href="products.html">Products</a></li>
|
|---|
| 58 | </ul>
|
|---|
| 59 | </div>
|
|---|
| 60 | </div>
|
|---|
| 61 | <div class="footer-bottom">
|
|---|
| 62 | <p>© 2025 Handcraft Marketplace. All rights reserved.</p>
|
|---|
| 63 | </div>
|
|---|
| 64 | </footer>
|
|---|
| 65 |
|
|---|
| 66 | <script src="script.js"></script>
|
|---|
| 67 | <script>
|
|---|
| 68 | document.addEventListener('DOMContentLoaded', () => {
|
|---|
| 69 | const urlParams = new URLSearchParams(window.location.search);
|
|---|
| 70 | const email = urlParams.get('email');
|
|---|
| 71 | const username = urlParams.get('username');
|
|---|
| 72 |
|
|---|
| 73 | const form = document.getElementById('verify-2fa-form');
|
|---|
| 74 | form.addEventListener('submit', async (e) => {
|
|---|
| 75 | e.preventDefault();
|
|---|
| 76 |
|
|---|
| 77 | const code = document.getElementById('code').value;
|
|---|
| 78 |
|
|---|
| 79 | try {
|
|---|
| 80 | const response = await fetch('/api/verify-2fa', {
|
|---|
| 81 | method: 'POST',
|
|---|
| 82 | headers: { 'Content-Type': 'application/json' },
|
|---|
| 83 | body: JSON.stringify({ email, code })
|
|---|
| 84 | });
|
|---|
| 85 |
|
|---|
| 86 | const data = await response.json();
|
|---|
| 87 |
|
|---|
| 88 | if (data.success) {
|
|---|
| 89 | if (data.requiresPasswordChange) {
|
|---|
| 90 | window.location.href = 'change-password.html?forced=true';
|
|---|
| 91 | } else {
|
|---|
| 92 | window.location.href = data.redirectTo || 'dashboard.html';
|
|---|
| 93 | }
|
|---|
| 94 | } else {
|
|---|
| 95 | alert(data.message || 'Verification failed');
|
|---|
| 96 | }
|
|---|
| 97 | } catch (error) {
|
|---|
| 98 | console.error('2FA verification error:', error);
|
|---|
| 99 | alert('An error occurred');
|
|---|
| 100 | }
|
|---|
| 101 | });
|
|---|
| 102 |
|
|---|
| 103 | document.getElementById('resend-code').addEventListener('click', async (e) => {
|
|---|
| 104 | e.preventDefault();
|
|---|
| 105 |
|
|---|
| 106 | try {
|
|---|
| 107 | const response = await fetch('/api/resend-2fa', {
|
|---|
| 108 | method: 'POST',
|
|---|
| 109 | headers: { 'Content-Type': 'application/json' },
|
|---|
| 110 | body: JSON.stringify({ email })
|
|---|
| 111 | });
|
|---|
| 112 |
|
|---|
| 113 | const data = await response.json();
|
|---|
| 114 |
|
|---|
| 115 | if (data.success) {
|
|---|
| 116 | alert('New verification code sent!');
|
|---|
| 117 | if (data.developmentCode) {
|
|---|
| 118 | console.log('New code:', data.developmentCode);
|
|---|
| 119 | }
|
|---|
| 120 | } else {
|
|---|
| 121 | alert(data.message || 'Failed to resend code');
|
|---|
| 122 | }
|
|---|
| 123 | } catch (error) {
|
|---|
| 124 | console.error('Resend error:', error);
|
|---|
| 125 | alert('An error occurred');
|
|---|
| 126 | }
|
|---|
| 127 | });
|
|---|
| 128 | });
|
|---|
| 129 | </script>
|
|---|
| 130 | </body>
|
|---|
| 131 | </html> |
|---|