Spaces:
Sleeping
Sleeping
Upload chat.html
Browse files- frontend/chat.html +100 -0
frontend/chat.html
CHANGED
|
@@ -781,6 +781,106 @@ document.addEventListener('DOMContentLoaded',()=>{
|
|
| 781 |
if(pc) pc.addEventListener('keydown',e=>{if(e.key==='Enter')submitChangePassword();});
|
| 782 |
});
|
| 783 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 784 |
</script>
|
| 785 |
<!-- CHANGE PASSWORD MODAL -->
|
| 786 |
<div id="changePwOverlay">
|
|
|
|
| 781 |
if(pc) pc.addEventListener('keydown',e=>{if(e.key==='Enter')submitChangePassword();});
|
| 782 |
});
|
| 783 |
|
| 784 |
+
// ββ Forgot Password βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 785 |
+
let _fpResetToken = '';
|
| 786 |
+
|
| 787 |
+
function showForgotPassword() {
|
| 788 |
+
document.getElementById('forgotOverlay').style.display = 'flex';
|
| 789 |
+
document.getElementById('fpStep1').style.display = 'block';
|
| 790 |
+
document.getElementById('fpStep2').style.display = 'none';
|
| 791 |
+
document.getElementById('fpStep3').style.display = 'none';
|
| 792 |
+
document.getElementById('fpError').style.display = 'none';
|
| 793 |
+
document.getElementById('fpSuccess').style.display = 'none';
|
| 794 |
+
document.getElementById('fpTitle').textContent = 'Reset Password';
|
| 795 |
+
document.getElementById('fpSubtitle').textContent = 'Enter your registered email';
|
| 796 |
+
document.getElementById('fpEmail').value = '';
|
| 797 |
+
document.getElementById('fpOTP').value = '';
|
| 798 |
+
document.getElementById('fpNewPw').value = '';
|
| 799 |
+
document.getElementById('fpConfirmPw').value = '';
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
function hideForgotPassword() {
|
| 803 |
+
document.getElementById('forgotOverlay').style.display = 'none';
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
function fpErr(msg) {
|
| 807 |
+
const e = document.getElementById('fpError');
|
| 808 |
+
e.textContent = msg; e.style.display = 'block';
|
| 809 |
+
document.getElementById('fpSuccess').style.display = 'none';
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
function fpOk(msg) {
|
| 813 |
+
const s = document.getElementById('fpSuccess');
|
| 814 |
+
s.textContent = msg; s.style.display = 'block';
|
| 815 |
+
document.getElementById('fpError').style.display = 'none';
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
async function fpSendOTP() {
|
| 819 |
+
const email = document.getElementById('fpEmail').value.trim();
|
| 820 |
+
if (!email) { fpErr('Please enter your email address.'); return; }
|
| 821 |
+
document.getElementById('fpError').style.display = 'none';
|
| 822 |
+
try {
|
| 823 |
+
await fetch(`${API}/auth/forgot-password`, {
|
| 824 |
+
method: 'POST', headers: {'Content-Type':'application/json'},
|
| 825 |
+
body: JSON.stringify({ email }),
|
| 826 |
+
});
|
| 827 |
+
document.getElementById('fpEmailShow').textContent = email;
|
| 828 |
+
document.getElementById('fpStep1').style.display = 'none';
|
| 829 |
+
document.getElementById('fpStep2').style.display = 'block';
|
| 830 |
+
document.getElementById('fpTitle').textContent = 'Enter Reset Code';
|
| 831 |
+
document.getElementById('fpSubtitle').textContent = 'Check your email inbox';
|
| 832 |
+
fpOk('Reset code sent! Check your inbox and spam folder.');
|
| 833 |
+
document.getElementById('fpOTP').focus();
|
| 834 |
+
} catch(e) { fpErr('Could not send reset code. Please try again.'); }
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
async function fpVerifyOTP() {
|
| 838 |
+
const email = document.getElementById('fpEmail').value.trim();
|
| 839 |
+
const otp = document.getElementById('fpOTP').value.trim();
|
| 840 |
+
if (!otp || otp.length < 6) { fpErr('Please enter the 6-digit code.'); return; }
|
| 841 |
+
try {
|
| 842 |
+
const res = await fetch(`${API}/auth/verify-otp`, {
|
| 843 |
+
method: 'POST', headers: {'Content-Type':'application/json'},
|
| 844 |
+
body: JSON.stringify({ email, otp }),
|
| 845 |
+
});
|
| 846 |
+
const data = await res.json();
|
| 847 |
+
if (!res.ok) throw new Error(data.detail || 'Invalid or expired code');
|
| 848 |
+
_fpResetToken = data.reset_token;
|
| 849 |
+
document.getElementById('fpStep2').style.display = 'none';
|
| 850 |
+
document.getElementById('fpStep3').style.display = 'block';
|
| 851 |
+
document.getElementById('fpTitle').textContent = 'Set New Password';
|
| 852 |
+
document.getElementById('fpSubtitle').textContent = 'Choose a new password';
|
| 853 |
+
document.getElementById('fpSuccess').style.display = 'none';
|
| 854 |
+
document.getElementById('fpNewPw').focus();
|
| 855 |
+
} catch(e) { fpErr(e.message); }
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
async function fpSetPassword() {
|
| 859 |
+
const newPw = document.getElementById('fpNewPw').value;
|
| 860 |
+
const confPw = document.getElementById('fpConfirmPw').value;
|
| 861 |
+
if (!newPw || newPw.length < 6) { fpErr('Password must be at least 6 characters.'); return; }
|
| 862 |
+
if (newPw !== confPw) { fpErr('Passwords do not match.'); return; }
|
| 863 |
+
try {
|
| 864 |
+
const res = await fetch(`${API}/auth/reset-password`, {
|
| 865 |
+
method: 'POST', headers: {'Content-Type':'application/json'},
|
| 866 |
+
body: JSON.stringify({ reset_token: _fpResetToken, new_password: newPw }),
|
| 867 |
+
});
|
| 868 |
+
const data = await res.json();
|
| 869 |
+
if (!res.ok) throw new Error(data.detail || 'Reset failed');
|
| 870 |
+
fpOk('Password reset successfully! Redirecting to login...');
|
| 871 |
+
setTimeout(() => { hideForgotPassword(); switchTab('login'); }, 2000);
|
| 872 |
+
} catch(e) { fpErr(e.message); }
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 876 |
+
const ov = document.getElementById('forgotOverlay');
|
| 877 |
+
if (ov) ov.addEventListener('click', e => { if (e.target === ov) hideForgotPassword(); });
|
| 878 |
+
const otp = document.getElementById('fpOTP');
|
| 879 |
+
if (otp) otp.addEventListener('keydown', e => { if (e.key === 'Enter') fpVerifyOTP(); });
|
| 880 |
+
const cp = document.getElementById('fpConfirmPw');
|
| 881 |
+
if (cp) cp.addEventListener('keydown', e => { if (e.key === 'Enter') fpSetPassword(); });
|
| 882 |
+
});
|
| 883 |
+
|
| 884 |
</script>
|
| 885 |
<!-- CHANGE PASSWORD MODAL -->
|
| 886 |
<div id="changePwOverlay">
|