ZeroNinerOne commited on
Commit
4aa03f2
Β·
verified Β·
1 Parent(s): 5282e4c

Upload chat.html

Browse files
Files changed (1) hide show
  1. frontend/chat.html +266 -3
frontend/chat.html CHANGED
@@ -130,6 +130,17 @@
130
  .session-loading.visible{display:flex;}
131
  .spin{width:18px;height:18px;border:2px solid var(--border);border-top-color:var(--teal);border-radius:50%;animation:spin 0.7s linear infinite;}
132
  @keyframes spin{to{transform:rotate(360deg);}}
 
 
 
 
 
 
 
 
 
 
 
133
  /* ── RISK PANEL ─────────────────────────────────────────────── */
134
  #riskPanel{flex:2;min-width:0;background:#F8F5F0;border-left:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;transition:flex 0.22s ease,opacity 0.22s;overflow:hidden;}
135
  #riskPanel.hidden{flex:0;min-width:0;max-width:0;opacity:0;pointer-events:none;overflow:hidden;}
@@ -182,6 +193,9 @@
182
  header{padding:8px 10px;}
183
  }
184
  /* Mobile input fixes β€” prevent iOS zoom on focus */
 
 
 
185
  /* ── RISK PANEL ─────────────────────────────────────────────── */
186
  #riskPanel{flex:2;min-width:0;background:#F8F5F0;border-left:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;transition:flex 0.22s ease,opacity 0.22s;overflow:hidden;}
187
  #riskPanel.hidden{flex:0;min-width:0;max-width:0;opacity:0;pointer-events:none;overflow:hidden;}
@@ -256,6 +270,58 @@
256
  <input type="password" id="authPassword" placeholder="β€’β€’β€’β€’β€’β€’β€’β€’" autocomplete="current-password">
257
  </div>
258
  <button class="auth-btn" id="authSubmitBtn" onclick="submitAuth()">Sign In</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  </div>
260
  </div>
261
 
@@ -276,6 +342,7 @@
276
  <div class="user-dropdown" id="userDropdown">
277
  <a onclick="newChat()">οΌ‹ New Chat</a>
278
  <hr>
 
279
  <a onclick="signOut()" class="danger">Sign Out</a>
280
  </div>
281
  </div>
@@ -384,6 +451,8 @@ function switchTab(tab) {
384
  document.getElementById('authSubmitBtn').textContent = tab==='login' ? 'Sign In' : 'Create Account';
385
  document.querySelectorAll('.auth-register-only').forEach(el => el.style.display = tab==='register' ? 'block' : 'none');
386
  document.getElementById('emailLabel').textContent = tab==='login' ? 'Email or Username' : 'Email';
 
 
387
  clearAuthError();
388
  }
389
 
@@ -552,6 +621,8 @@ async function sendMessage() {
552
  typing.remove();
553
  addBubble('ai', data.response, new Date().toISOString());
554
  loadSessionList();
 
 
555
  } catch(err) {
556
  typing.remove();
557
  addBubble('ai', `⚠️ Error: ${err.message}`, new Date().toISOString());
@@ -664,10 +735,21 @@ function resetRiskPanel() {
664
  }
665
 
666
  function scheduleRiskUpdate(text) {
667
- if (!text || text.trim().length < 8) return;
668
- if (!_riskText.includes(text)) _riskText += ' ' + text;
 
669
  clearTimeout(_riskDebounce);
670
- _riskDebounce = setTimeout(() => _fetchRisk(_riskText.trim()), 900);
 
 
 
 
 
 
 
 
 
 
671
  }
672
 
673
  async function _fetchRisk(text) {
@@ -714,6 +796,187 @@ function renderRiskPanel(data) {
714
  } else { aBox.style.display = 'none'; }
715
  }
716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
717
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
718
  </body>
719
  </html>
 
130
  .session-loading.visible{display:flex;}
131
  .spin{width:18px;height:18px;border:2px solid var(--border);border-top-color:var(--teal);border-radius:50%;animation:spin 0.7s linear infinite;}
132
  @keyframes spin{to{transform:rotate(360deg);}}
133
+ /* ── CHANGE PASSWORD MODAL ──────────────────────────────────────── */
134
+ #changePwOverlay{position:fixed;inset:0;background:rgba(11,31,58,0.7);backdrop-filter:blur(4px);display:none;align-items:center;justify-content:center;z-index:200;}
135
+ #changePwOverlay.open{display:flex;}
136
+ .changepw-card{background:#fff;border-radius:16px;padding:32px 36px;width:380px;max-width:95vw;box-shadow:0 16px 48px rgba(0,0,0,0.25);}
137
+ .changepw-card h3{font-family:'Libre Baskerville',serif;font-size:18px;color:var(--navy);margin-bottom:20px;}
138
+ .changepw-error{background:#FEE2E2;border:1px solid #FECACA;border-radius:8px;padding:9px 14px;font-size:13px;color:#B91C1C;margin-bottom:14px;display:none;}
139
+ .changepw-success{background:#D1FAE5;border:1px solid #6EE7B7;border-radius:8px;padding:9px 14px;font-size:13px;color:#065F46;margin-bottom:14px;display:none;}
140
+ .changepw-card .auth-btn{margin-top:4px;}
141
+ .changepw-cancel{width:100%;padding:10px;background:none;border:1.5px solid var(--border);border-radius:9px;font-family:'DM Sans',sans-serif;font-size:14px;color:var(--muted);cursor:pointer;margin-top:8px;transition:background 0.15s;}
142
+ .changepw-cancel:hover{background:var(--sand);}
143
+
144
  /* ── RISK PANEL ─────────────────────────────────────────────── */
145
  #riskPanel{flex:2;min-width:0;background:#F8F5F0;border-left:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;transition:flex 0.22s ease,opacity 0.22s;overflow:hidden;}
146
  #riskPanel.hidden{flex:0;min-width:0;max-width:0;opacity:0;pointer-events:none;overflow:hidden;}
 
193
  header{padding:8px 10px;}
194
  }
195
  /* Mobile input fixes β€” prevent iOS zoom on focus */
196
+ /* ── CHANGE PASSWORD MODAL ──────────────────────────────────────── */
197
+
198
+
199
  /* ── RISK PANEL ─────────────────────────────────────────────── */
200
  #riskPanel{flex:2;min-width:0;background:#F8F5F0;border-left:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;transition:flex 0.22s ease,opacity 0.22s;overflow:hidden;}
201
  #riskPanel.hidden{flex:0;min-width:0;max-width:0;opacity:0;pointer-events:none;overflow:hidden;}
 
270
  <input type="password" id="authPassword" placeholder="β€’β€’β€’β€’β€’β€’β€’β€’" autocomplete="current-password">
271
  </div>
272
  <button class="auth-btn" id="authSubmitBtn" onclick="submitAuth()">Sign In</button>
273
+ <p id="forgotLink" style="text-align:center;margin-top:12px;font-size:13px;color:var(--muted);">
274
+ Forgot your password?
275
+ <a onclick="showForgotPassword()" style="color:var(--teal);cursor:pointer;text-decoration:underline;">Reset it</a>
276
+ </p>
277
+ </div>
278
+ </div>
279
+
280
+ <!-- FORGOT PASSWORD MODAL -->
281
+ <div id="forgotOverlay" style="position:fixed;inset:0;background:rgba(11,31,58,0.85);backdrop-filter:blur(6px);display:none;align-items:center;justify-content:center;z-index:2000;">
282
+ <div class="auth-card">
283
+ <div class="auth-logo">
284
+ <div class="auth-logo-mark">NC</div>
285
+ <div><h2>Reset Password</h2><p id="forgotStepLabel">Enter your registered email</p></div>
286
+ </div>
287
+ <div id="forgotError" class="auth-error"></div>
288
+ <div id="forgotSuccess" style="background:#D1FAE5;border:1px solid #6EE7B7;border-radius:8px;padding:10px 14px;font-size:13px;color:#065F46;margin-bottom:14px;display:none;"></div>
289
+
290
+ <!-- Step 1: Email -->
291
+ <div id="fpStep1">
292
+ <div class="auth-field">
293
+ <label>Email Address</label>
294
+ <input type="email" id="fpEmail" placeholder="your@email.com" autocomplete="email">
295
+ </div>
296
+ <button class="auth-btn" onclick="sendOTP()">Send Reset Code</button>
297
+ <button onclick="hideForgotPassword()" style="width:100%;padding:10px;background:none;border:1.5px solid var(--border);border-radius:9px;font-family:DM Sans,sans-serif;font-size:14px;color:var(--muted);cursor:pointer;margin-top:8px;">Cancel</button>
298
+ </div>
299
+
300
+ <!-- Step 2: OTP -->
301
+ <div id="fpStep2" style="display:none;">
302
+ <p style="font-size:13px;color:var(--muted);margin-bottom:16px;">A 6-digit code was sent to <strong id="fpEmailDisplay"></strong>. Enter it below:</p>
303
+ <div class="auth-field">
304
+ <label>Reset Code</label>
305
+ <input type="text" id="fpOTP" placeholder="000000" maxlength="6" style="letter-spacing:8px;font-size:22px;text-align:center;font-family:monospace;">
306
+ </div>
307
+ <button class="auth-btn" onclick="verifyOTP()">Verify Code</button>
308
+ <p style="text-align:center;margin-top:10px;font-size:12px;color:var(--muted);">
309
+ Didn't receive it? <a onclick="sendOTP()" style="color:var(--teal);cursor:pointer;">Resend</a>
310
+ </p>
311
+ </div>
312
+
313
+ <!-- Step 3: New Password -->
314
+ <div id="fpStep3" style="display:none;">
315
+ <div class="auth-field">
316
+ <label>New Password</label>
317
+ <input type="password" id="fpNewPw" placeholder="Min 6 characters">
318
+ </div>
319
+ <div class="auth-field">
320
+ <label>Confirm New Password</label>
321
+ <input type="password" id="fpConfirmPw" placeholder="Repeat new password">
322
+ </div>
323
+ <button class="auth-btn" onclick="submitNewPassword()">Set New Password</button>
324
+ </div>
325
  </div>
326
  </div>
327
 
 
342
  <div class="user-dropdown" id="userDropdown">
343
  <a onclick="newChat()">οΌ‹ New Chat</a>
344
  <hr>
345
+ <a onclick="showChangePassword()">πŸ”‘ Change Password</a>
346
  <a onclick="signOut()" class="danger">Sign Out</a>
347
  </div>
348
  </div>
 
451
  document.getElementById('authSubmitBtn').textContent = tab==='login' ? 'Sign In' : 'Create Account';
452
  document.querySelectorAll('.auth-register-only').forEach(el => el.style.display = tab==='register' ? 'block' : 'none');
453
  document.getElementById('emailLabel').textContent = tab==='login' ? 'Email or Username' : 'Email';
454
+ const fl = document.getElementById('forgotLink');
455
+ if (fl) fl.style.display = tab==='login' ? 'block' : 'none';
456
  clearAuthError();
457
  }
458
 
 
621
  typing.remove();
622
  addBubble('ai', data.response, new Date().toISOString());
623
  loadSessionList();
624
+ // Re-analyze with full accumulated text after every AI response
625
+ rebuildRiskFromHistory();
626
  } catch(err) {
627
  typing.remove();
628
  addBubble('ai', `⚠️ Error: ${err.message}`, new Date().toISOString());
 
735
  }
736
 
737
  function scheduleRiskUpdate(text) {
738
+ if (!text || text.trim().length < 3) return;
739
+ // Always append new text to accumulate full conversation context
740
+ _riskText = (_riskText + ' ' + text).trim();
741
  clearTimeout(_riskDebounce);
742
+ _riskDebounce = setTimeout(() => _fetchRisk(_riskText), 700);
743
+ }
744
+
745
+ function rebuildRiskFromHistory() {
746
+ // Re-run analysis using ALL human messages in current conversation
747
+ const msgs = document.getElementById('messages').querySelectorAll('.msg-row.user .bubble');
748
+ const allText = Array.from(msgs).map(b => b.innerText || b.textContent).join(' ').trim();
749
+ if (allText.length > 5) {
750
+ _riskText = allText;
751
+ _fetchRisk(_riskText);
752
+ }
753
  }
754
 
755
  async function _fetchRisk(text) {
 
796
  } else { aBox.style.display = 'none'; }
797
  }
798
 
799
+ // ── Forgot Password ────────────────────────────────────────────────────────
800
+ let _resetToken = '';
801
+
802
+ function showForgotPassword() {
803
+ document.getElementById('forgotOverlay').style.display = 'flex';
804
+ document.getElementById('fpStep1').style.display = 'block';
805
+ document.getElementById('fpStep2').style.display = 'none';
806
+ document.getElementById('fpStep3').style.display = 'none';
807
+ document.getElementById('forgotError').style.display = 'none';
808
+ document.getElementById('forgotSuccess').style.display = 'none';
809
+ document.getElementById('forgotStepLabel').textContent = 'Enter your registered email';
810
+ document.getElementById('fpEmail').value = '';
811
+ document.getElementById('fpOTP').value = '';
812
+ document.getElementById('fpNewPw').value = '';
813
+ document.getElementById('fpConfirmPw').value = '';
814
+ }
815
+
816
+ function hideForgotPassword() {
817
+ document.getElementById('forgotOverlay').style.display = 'none';
818
+ }
819
+
820
+ function fpShowError(msg) {
821
+ const e = document.getElementById('forgotError');
822
+ e.textContent = msg; e.style.display = 'block';
823
+ document.getElementById('forgotSuccess').style.display = 'none';
824
+ }
825
+
826
+ function fpShowSuccess(msg) {
827
+ const s = document.getElementById('forgotSuccess');
828
+ s.textContent = msg; s.style.display = 'block';
829
+ document.getElementById('forgotError').style.display = 'none';
830
+ }
831
+
832
+ async function sendOTP() {
833
+ const email = document.getElementById('fpEmail').value.trim();
834
+ if (!email) { fpShowError('Please enter your email address.'); return; }
835
+ fpShowError('');
836
+ try {
837
+ const res = await fetch(`${API}/auth/forgot-password`, {
838
+ method: 'POST', headers: {'Content-Type':'application/json'},
839
+ body: JSON.stringify({ email }),
840
+ });
841
+ const data = await res.json();
842
+ // Show step 2 regardless (don't reveal if email exists)
843
+ document.getElementById('fpEmailDisplay').textContent = email;
844
+ document.getElementById('fpStep1').style.display = 'none';
845
+ document.getElementById('fpStep2').style.display = 'block';
846
+ document.getElementById('forgotStepLabel').textContent = 'Enter the code from your email';
847
+ fpShowSuccess('Reset code sent! Check your inbox (and spam folder).');
848
+ document.getElementById('fpOTP').focus();
849
+ } catch(e) { fpShowError('Could not send reset code. Please try again.'); }
850
+ }
851
+
852
+ async function verifyOTP() {
853
+ const email = document.getElementById('fpEmail').value.trim();
854
+ const otp = document.getElementById('fpOTP').value.trim();
855
+ if (!otp || otp.length < 6) { fpShowError('Please enter the 6-digit code.'); return; }
856
+ try {
857
+ const res = await fetch(`${API}/auth/verify-otp`, {
858
+ method: 'POST', headers: {'Content-Type':'application/json'},
859
+ body: JSON.stringify({ email, otp }),
860
+ });
861
+ const data = await res.json();
862
+ if (!res.ok) throw new Error(data.detail || 'Invalid code');
863
+ _resetToken = data.reset_token;
864
+ document.getElementById('fpStep2').style.display = 'none';
865
+ document.getElementById('fpStep3').style.display = 'block';
866
+ document.getElementById('forgotStepLabel').textContent = 'Set your new password';
867
+ document.getElementById('forgotSuccess').style.display = 'none';
868
+ document.getElementById('fpNewPw').focus();
869
+ } catch(e) { fpShowError(e.message); }
870
+ }
871
+
872
+ async function submitNewPassword() {
873
+ const newPw = document.getElementById('fpNewPw').value;
874
+ const confPw = document.getElementById('fpConfirmPw').value;
875
+ if (!newPw || newPw.length < 6) { fpShowError('Password must be at least 6 characters.'); return; }
876
+ if (newPw !== confPw) { fpShowError('Passwords do not match.'); return; }
877
+ try {
878
+ const res = await fetch(`${API}/auth/reset-password`, {
879
+ method: 'POST', headers: {'Content-Type':'application/json'},
880
+ body: JSON.stringify({ reset_token: _resetToken, new_password: newPw }),
881
+ });
882
+ const data = await res.json();
883
+ if (!res.ok) throw new Error(data.detail || 'Reset failed');
884
+ fpShowSuccess('βœ… Password reset! Redirecting to login…');
885
+ setTimeout(() => {
886
+ hideForgotPassword();
887
+ switchTab('login');
888
+ }, 2000);
889
+ } catch(e) { fpShowError(e.message); }
890
+ }
891
+
892
+ // ── Change Password ────────────────────────────────────────────────────────
893
+ function showChangePassword() {
894
+ document.getElementById('userDropdown').classList.remove('open');
895
+ document.getElementById('changePwOverlay').style.display = 'flex';
896
+ document.getElementById('pwOld').value = '';
897
+ document.getElementById('pwNew').value = '';
898
+ document.getElementById('pwConfirm').value = '';
899
+ document.getElementById('changePwError').style.display = 'none';
900
+ document.getElementById('changePwSuccess').style.display = 'none';
901
+ document.getElementById('pwOld').focus();
902
+ }
903
+
904
+ function hideChangePassword() {
905
+ document.getElementById('changePwOverlay').style.display = 'none';
906
+ }
907
+
908
+ async function submitChangePassword() {
909
+ const oldPw = document.getElementById('pwOld').value;
910
+ const newPw = document.getElementById('pwNew').value;
911
+ const confPw = document.getElementById('pwConfirm').value;
912
+ const errEl = document.getElementById('changePwError');
913
+ const okEl = document.getElementById('changePwSuccess');
914
+ errEl.style.display = 'none';
915
+ okEl.style.display = 'none';
916
+
917
+ if (!oldPw || !newPw || !confPw) {
918
+ errEl.textContent = 'Please fill in all fields.';
919
+ errEl.style.display = 'block'; return;
920
+ }
921
+ if (newPw.length < 6) {
922
+ errEl.textContent = 'New password must be at least 6 characters.';
923
+ errEl.style.display = 'block'; return;
924
+ }
925
+ if (newPw !== confPw) {
926
+ errEl.textContent = 'New passwords do not match.';
927
+ errEl.style.display = 'block'; return;
928
+ }
929
+
930
+ try {
931
+ const res = await authFetch('/auth/change-password', {
932
+ method: 'POST',
933
+ headers: { 'Content-Type': 'application/json' },
934
+ body: JSON.stringify({ old_password: oldPw, new_password: newPw }),
935
+ });
936
+ const data = await res.json();
937
+ if (!res.ok) throw new Error(data.detail || 'Failed to change password');
938
+ okEl.textContent = 'βœ… Password changed successfully!';
939
+ okEl.style.display = 'block';
940
+ setTimeout(hideChangePassword, 2000);
941
+ } catch(e) {
942
+ errEl.textContent = e.message;
943
+ errEl.style.display = 'block';
944
+ }
945
+ }
946
+
947
+ // Close modal on background click
948
+ document.addEventListener('DOMContentLoaded', () => {
949
+ const cpOverlay = document.getElementById('changePwOverlay');
950
+ if (cpOverlay) cpOverlay.addEventListener('click', function(e) {
951
+ if (e.target === this) hideChangePassword();
952
+ });
953
+ document.getElementById('pwConfirm').addEventListener('keydown', e => {
954
+ if (e.key === 'Enter') submitChangePassword();
955
+ });
956
+ });
957
  </script>
958
+
959
+ <!-- CHANGE PASSWORD MODAL -->
960
+ <div id="changePwOverlay" style="position:fixed;inset:0;background:rgba(11,31,58,0.7);backdrop-filter:blur(4px);display:none;align-items:center;justify-content:center;z-index:500;">
961
+ <div class="changepw-card">
962
+ <h3>πŸ”‘ Change Password</h3>
963
+ <div id="changePwError" class="changepw-error"></div>
964
+ <div id="changePwSuccess" class="changepw-success"></div>
965
+ <div class="auth-field">
966
+ <label>Current Password</label>
967
+ <input type="password" id="pwOld" placeholder="Your current password">
968
+ </div>
969
+ <div class="auth-field">
970
+ <label>New Password</label>
971
+ <input type="password" id="pwNew" placeholder="Min 6 characters">
972
+ </div>
973
+ <div class="auth-field">
974
+ <label>Confirm New Password</label>
975
+ <input type="password" id="pwConfirm" placeholder="Repeat new password">
976
+ </div>
977
+ <button class="auth-btn" onclick="submitChangePassword()">Update Password</button>
978
+ <button class="changepw-cancel" onclick="hideChangePassword()">Cancel</button>
979
+ </div>
980
+ </div>
981
  </body>
982
  </html>