Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,50 @@ <h3 class="text-lg font-extrabold text-slate-900 mb-1">Phase 2 Authentication</h
let identifier, password;
if (activeRole === 'patient') {
identifier = document.getElementById('patientIdentifier').value.trim();
password = document.getElementById('patientPassword').value.trim();
if (!identifier || !password) { showToast('Please fill in all fields.', 'error'); return; }

/* Demo: check against localStorage registered user */
const regEmail = localStorage.getItem('registeredEmail');
const regPwd = localStorage.getItem('registeredPassword');
if (regEmail && regPwd) {
if (identifier !== regEmail || password !== regPwd) {
showToast('Invalid credentials. Please try again.', 'error'); return;
}
password = document.getElementById('patientPassword').value.trim();

if (!identifier || !password) {
showToast('Invalid Credentials. Please try again.', 'error');
return;
}

const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: identifier,
password
})
});
const data = await response.json();


if (!response.ok) {
showToast('Invalid credentials', 'error');
return;
}

const btn = form.querySelector('button[type="submit"]');
const btnText = btn?.querySelector('.btn-text');
const btnIcon = btn?.querySelector('.btn-icon');
const btnSpinner = btn?.querySelector('.btn-spinner');
const originalText = btnText ? btnText.textContent : 'Authenticate';

if (btn) {
if (btnText) btnText.textContent = 'Requesting Auth...';
if (btnIcon) btnIcon.classList.add('hidden');
if (btnSpinner) btnSpinner.classList.remove('hidden');
btn.disabled = true;
btn.classList.add('opacity-80', 'cursor-wait');
}

try {
const otp = await showOtpModal();
if (!otp) throw new Error('OTP Canceled');
if (otp !== '123456') throw new Error('Invalid OTP — use demo code: 123456');

sessionStorage.setItem('userRole', 'patient');
sessionStorage.setItem('abhaId', localStorage.getItem('patientABHA') || identifier);
sessionStorage.setItem('userName', localStorage.getItem('patientName') || identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h4 class="text-sm font-extrabold text-slate-900 tracking-tight mb-1">Pledge Org
if (fname) localStorage.setItem('patientName', fname);
if (abha) localStorage.setItem('patientABHA', abha);
if (email) localStorage.setItem('registeredEmail', email);
if (pwd) localStorage.setItem('registeredPassword', pwd);


// Show green toast success event
showToast('Account Created!', 'Redirecting to Login...', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,37 +257,14 @@ <h3 class="text-lg font-extrabold text-slate-900 mb-1">Phase 2 Authentication</h
}

// Hackathon Link intercept
const registeredEmail = localStorage.getItem('registeredEmail');
const registeredPassword = localStorage.getItem('registeredPassword');

// If the user registered recently via the UI demo, strictly check against those credentials
if (registeredEmail && registeredPassword) {
if (identifier !== registeredEmail || password !== registeredPassword) {
if (activeRole === 'patient') {
identifier = document.getElementById('patientIdentifier').value.trim();
password = document.getElementById('patientPassword').value.trim();

if (!identifier || !password) {
showToast('Invalid Credentials. Please try again.', 'error');
return;
}

// Match found! Fast track to dashboard
sessionStorage.setItem('userRole', 'patient');
sessionStorage.setItem('abhaId', localStorage.getItem('patientABHA') || identifier);
sessionStorage.setItem('userName', localStorage.getItem('patientName') || identifier);

const btn = form.querySelector('button[type="submit"]');
if (btn) {
const btnText = btn.querySelector('.btn-text');
const btnIcon = btn.querySelector('.btn-icon');
const btnSpinner = btn.querySelector('.btn-spinner');

if (btnText) btnText.textContent = 'Requesting Auth...';
if (btnIcon) btnIcon.classList.add('hidden');
if (btnSpinner) btnSpinner.classList.remove('hidden');
btn.disabled = true;
btn.classList.add('opacity-80', 'cursor-wait');
}

showToast('Authentication Successful! Redirecting...', 'success');
setTimeout(() => { window.location.href = 'dashboard.html'; }, 1500);
return;
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ <h4 class="text-sm font-extrabold text-slate-900 tracking-tight mb-1">Pledge Org
if (fname) localStorage.setItem('patientName', fname);
if (abha) localStorage.setItem('patientABHA', abha);
if (email) localStorage.setItem('registeredEmail', email);
if (pwd) localStorage.setItem('registeredPassword', pwd);


// Show green toast success event
showToast('Account Created!', 'Redirecting to Login...', true);
Expand Down