|
1 | | -<div class="auth-container"> |
2 | | - <h1>Reset Password</h1> |
3 | | - <p class="auth-description">Enter your new password below.</p> |
| 1 | +<div class="login-container"> |
| 2 | + <h2 data-i18n="auth.forgot_password">Forgot Password</h2> |
| 3 | + <p data-i18n="auth.reset_password_email_description">Enter your email address below and we'll send you a link to reset your password.</p> |
4 | 4 |
|
5 | | - <form id="reset-password-form" class="auth-form"> |
| 5 | + <form id="reset-password-email-form"> |
6 | 6 | <div class="form-group"> |
7 | | - <label for="password">New Password</label> |
8 | | - <input type="password" id="password" name="password" required minlength="8" placeholder="Enter your new password"> |
9 | | - <small>Password must be at least 8 characters</small> |
| 7 | + <label for="email" data-i18n="auth.email">Email</label> |
| 8 | + <input type="email" id="email" name="email" required> |
10 | 9 | </div> |
11 | 10 |
|
12 | | - <div class="form-group"> |
13 | | - <label for="confirm-password">Confirm Password</label> |
14 | | - <input type="password" id="confirm-password" name="confirm-password" required minlength="8" placeholder="Confirm your new password"> |
15 | | - </div> |
16 | | - |
17 | | - <button type="submit" class="btn btn-primary">Reset Password</button> |
| 11 | + <button type="submit" class="login-button" data-i18n="auth.send_reset_link">Send Reset Link</button> |
18 | 12 | </form> |
19 | 13 |
|
20 | | - <div class="auth-links"> |
21 | | - <a href="/login">Back to Login</a> |
22 | | - </div> |
| 14 | + <p class="login-link"><a href="/login" data-i18n="navigation.back_to_login">Back to Login</a></p> |
23 | 15 | </div> |
24 | 16 |
|
25 | 17 | <script> |
26 | 18 | document.addEventListener('DOMContentLoaded', () => { |
27 | | - const form = document.getElementById('reset-password-form'); |
| 19 | + const form = document.getElementById('reset-password-email-form'); |
28 | 20 | if (!form) return; |
29 | 21 |
|
30 | 22 | form.addEventListener('submit', async (e) => { |
31 | 23 | e.preventDefault(); |
32 | 24 |
|
33 | | - const password = document.getElementById('password').value; |
34 | | - const confirmPassword = document.getElementById('confirm-password').value; |
35 | | - |
36 | | - if (password !== confirmPassword) { |
37 | | - alert('Passwords do not match'); |
38 | | - return; |
39 | | - } |
| 25 | + const email = document.getElementById('email').value; |
40 | 26 |
|
41 | 27 | // Show loading state |
42 | 28 | const submitButton = form.querySelector('button[type="submit"]'); |
43 | 29 | const originalButtonText = submitButton.textContent; |
44 | | - submitButton.textContent = 'Resetting...'; |
| 30 | + submitButton.textContent = window.i18n.t('auth.sending'); |
45 | 31 | submitButton.disabled = true; |
46 | 32 |
|
47 | 33 | try { |
48 | | - // Import Supabase client for JWT authentication |
49 | | - const { createClient } = await import('https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/+esm'); |
50 | | - const supabaseUrl = 'https://arokhsfbkdnfuklmqajh.supabase.co'; // Should match server config |
51 | | - const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFyb2toc2Zia2RuZnVrbG1xYWpoIiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODI0NTI4MDAsImV4cCI6MTk5ODAyODgwMH0.KxwHdxWXLLrJtFzLAYI-fwzgz8m5xsHD4XGdNw_xJm8'; // Public anon key |
52 | | - |
53 | | - console.log('Creating Supabase client for password reset'); |
54 | | - const supabase = createClient(supabaseUrl, supabaseAnonKey); |
| 34 | + // Import the API client |
| 35 | + const { ApiClient } = await import('./api-client.js'); |
55 | 36 |
|
56 | | - // Get the JWT token from localStorage |
57 | | - const jwtToken = localStorage.getItem('jwt_token'); |
58 | | - |
59 | | - if (!jwtToken) { |
60 | | - throw new Error('You must be logged in to reset your password'); |
61 | | - } |
62 | | - |
63 | | - // Update the user's password |
64 | | - const { error } = await supabase.auth.updateUser({ |
65 | | - password: password |
| 37 | + // Send password reset request to the server API |
| 38 | + const response = await fetch('/api/1/auth/reset-password', { |
| 39 | + method: 'POST', |
| 40 | + headers: { |
| 41 | + 'Content-Type': 'application/json' |
| 42 | + }, |
| 43 | + body: JSON.stringify({ email }) |
66 | 44 | }); |
67 | 45 |
|
68 | | - if (error) { |
69 | | - throw error; |
| 46 | + if (!response.ok) { |
| 47 | + const errorData = await response.json(); |
| 48 | + throw new Error(errorData.error || response.statusText); |
70 | 49 | } |
71 | 50 |
|
72 | 51 | // Show success message |
73 | | - alert('Password reset successfully! Please log in with your new password.'); |
| 52 | + alert(window.i18n.t('auth.reset_email_sent')); |
74 | 53 |
|
75 | | - // Redirect to login page |
76 | | - window.router.navigate('/login'); |
| 54 | + // Clear the form |
| 55 | + form.reset(); |
| 56 | + submitButton.textContent = originalButtonText; |
| 57 | + submitButton.disabled = false; |
77 | 58 | } catch (error) { |
78 | | - console.error('Password reset error:', error); |
| 59 | + console.error('Password reset email error:', error); |
79 | 60 | submitButton.textContent = originalButtonText; |
80 | 61 | submitButton.disabled = false; |
81 | 62 |
|
82 | 63 | // Show error message |
83 | | - alert('Password reset failed: ' + (error.message || 'An unknown error occurred')); |
| 64 | + alert(window.i18n.t('errors.reset_email_failed') + ': ' + (error.message || window.i18n.t('errors.unknown_error'))); |
84 | 65 | } |
85 | 66 | }); |
86 | 67 | }); |
|
0 commit comments