Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +21 -150
templates/index.html
CHANGED
@@ -49,20 +49,8 @@
|
|
49 |
</head>
|
50 |
<body>
|
51 |
|
52 |
-
<div class="container">
|
53 |
-
<h1>Welcome to the Biryani Hub</h1>
|
54 |
-
<p>Are you ready to explore our delicious menu?</p>
|
55 |
-
<div class="category-buttons">
|
56 |
-
<button onclick="window.location.href='/menu_page'">Go to Menu</button>
|
57 |
-
</div>
|
58 |
-
</div>
|
59 |
-
|
60 |
-
</body>
|
61 |
-
</html>
|
62 |
-
|
63 |
-
<!-- Welcome Page -->
|
64 |
<div class="container" id="welcomePage">
|
65 |
-
<h1>Welcome to
|
66 |
<h2 class="info" id="infoMessage">Welcome! Are you a new customer or an existing one?</h2>
|
67 |
<p class="status" id="status">🔊 Please say 'new' to register or 'existing' to login.</p>
|
68 |
</div>
|
@@ -94,54 +82,24 @@
|
|
94 |
<p class="status" id="loginStatus">Listening... 🗣</p>
|
95 |
</div>
|
96 |
|
97 |
-
<!-- Confirmation Page -->
|
98 |
-
<div class="container" id="confirmationPage" style="display: none;">
|
99 |
-
<h2>Confirm Your Details</h2>
|
100 |
-
<div class="confirm-details">
|
101 |
-
<p class="details"><strong>Name:</strong> <span id="confirmName"></span></p>
|
102 |
-
<p class="details"><strong>Email:</strong> <span id="confirmEmail"></span></p>
|
103 |
-
<p class="details"><strong>Phone:</strong> <span id="confirmPhone"></span></p>
|
104 |
-
</div>
|
105 |
-
</div>
|
106 |
-
|
107 |
-
<div id="statusMessage" style="display: none;">
|
108 |
-
<h2 id="statusText"></h2>
|
109 |
-
</div>
|
110 |
-
|
111 |
<script>
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
}
|
121 |
-
|
122 |
-
function speak(text, callback) {
|
123 |
-
const speech = new SpeechSynthesisUtterance(text);
|
124 |
-
speech.onend = callback;
|
125 |
-
window.speechSynthesis.speak(speech);
|
126 |
-
}
|
127 |
-
|
128 |
-
function askLoginOrRegister() {
|
129 |
-
speak("Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
|
130 |
-
recognition.start();
|
131 |
-
recognition.onresult = function (event) {
|
132 |
-
let response = event.results[0][0].transcript.trim().toLowerCase();
|
133 |
-
recognition.stop();
|
134 |
-
if (response.includes("new")) {
|
135 |
-
showRegistrationForm();
|
136 |
-
captureName();
|
137 |
-
} else if (response.includes("existing")) {
|
138 |
-
showLoginForm();
|
139 |
-
captureLoginDetails();
|
140 |
} else {
|
141 |
-
speak("
|
|
|
|
|
142 |
}
|
143 |
-
}
|
144 |
-
|
|
|
|
|
145 |
}
|
146 |
|
147 |
function captureEmail() {
|
@@ -149,47 +107,28 @@
|
|
149 |
recognition.start();
|
150 |
recognition.onresult = function (event) {
|
151 |
let emailCaptured = event.results[0][0].transcript.trim();
|
152 |
-
document.getElementById('email').value = emailCaptured;
|
153 |
recognition.stop();
|
154 |
-
// Validate the email format
|
155 |
if (!isValidEmail(emailCaptured)) {
|
156 |
speak("The email address is invalid. Please provide a valid email like [email protected].", captureEmail);
|
157 |
} else {
|
158 |
-
|
159 |
-
confirmEmail(emailCaptured);
|
160 |
-
});
|
161 |
}
|
162 |
};
|
163 |
});
|
164 |
}
|
165 |
|
166 |
-
function
|
167 |
-
|
168 |
-
return /\S+@\S+\.\S+/.test(email);
|
169 |
-
}
|
170 |
-
|
171 |
-
function confirmEmail(emailCaptured) {
|
172 |
-
recognition.start();
|
173 |
-
recognition.onresult = function (event) {
|
174 |
-
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
175 |
-
recognition.stop();
|
176 |
-
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
177 |
-
captureMobile();
|
178 |
-
} else {
|
179 |
-
captureEmail();
|
180 |
-
}
|
181 |
-
};
|
182 |
}
|
183 |
|
184 |
function captureMobile() {
|
185 |
-
speak("Please say your mobile number.", function () {
|
186 |
recognition.start();
|
187 |
recognition.onresult = function (event) {
|
188 |
let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
|
189 |
-
document.getElementById('mobile').value = mobileCaptured;
|
190 |
recognition.stop();
|
191 |
if (!isValidPhone(mobileCaptured)) {
|
192 |
-
speak("The mobile number is invalid. Please provide
|
193 |
} else {
|
194 |
speak("You said " + mobileCaptured + ". Is it correct?", function () {
|
195 |
confirmMobile(mobileCaptured);
|
@@ -198,74 +137,6 @@
|
|
198 |
};
|
199 |
});
|
200 |
}
|
201 |
-
|
202 |
-
function isValidPhone(phone) {
|
203 |
-
// Check if phone number contains only digits and is 15 characters long
|
204 |
-
const phonePattern = /^\d{10,15}$/;
|
205 |
-
return phonePattern.test(phone);
|
206 |
-
}
|
207 |
-
|
208 |
-
function confirmMobile(mobileCaptured) {
|
209 |
-
recognition.start();
|
210 |
-
recognition.onresult = function (event) {
|
211 |
-
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
212 |
-
recognition.stop();
|
213 |
-
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
214 |
-
// Show confirmation page with details
|
215 |
-
showConfirmationPage();
|
216 |
-
} else {
|
217 |
-
captureMobile();
|
218 |
-
}
|
219 |
-
};
|
220 |
-
}
|
221 |
-
|
222 |
-
function showConfirmationPage() {
|
223 |
-
const name = document.getElementById('name').value;
|
224 |
-
const email = document.getElementById('email').value;
|
225 |
-
const phone = document.getElementById('mobile').value;
|
226 |
-
document.getElementById('confirmName').textContent = name;
|
227 |
-
document.getElementById('confirmEmail').textContent = email;
|
228 |
-
document.getElementById('confirmPhone').textContent = phone;
|
229 |
-
// Automatically submit the details after a delay
|
230 |
-
setTimeout(submitRegistration, 6000); // 6 seconds delay
|
231 |
-
}
|
232 |
-
|
233 |
-
function submitRegistration() {
|
234 |
-
const name = document.getElementById('name').value;
|
235 |
-
const email = document.getElementById('email').value;
|
236 |
-
const phone = document.getElementById('mobile').value;
|
237 |
-
// Simulate submission to Salesforce
|
238 |
-
fetch('/submit', {
|
239 |
-
method: 'POST',
|
240 |
-
headers: { 'Content-Type': 'application/json' },
|
241 |
-
body: JSON.stringify({ name, email, phone })
|
242 |
-
})
|
243 |
-
.then(response => response.json())
|
244 |
-
.then(data => {
|
245 |
-
if (data.success) {
|
246 |
-
document.getElementById('statusText').textContent = `Thank you for registering, ${name}!`;
|
247 |
-
document.getElementById('statusMessage').style.display = 'block';
|
248 |
-
// Show 'Submitted Successfully' after 6 seconds, then refresh the page after 5 seconds
|
249 |
-
setTimeout(() => {
|
250 |
-
document.getElementById('statusText').textContent = 'Submitted Successfully!';
|
251 |
-
setTimeout(() => {
|
252 |
-
window.location.reload(); // Refresh after 5 seconds
|
253 |
-
}, 5000);
|
254 |
-
}, 6000);
|
255 |
-
} else {
|
256 |
-
document.getElementById('statusText').textContent = 'There was an error submitting your details. Please try again.';
|
257 |
-
document.getElementById('statusMessage').style.display = 'block';
|
258 |
-
}
|
259 |
-
})
|
260 |
-
.catch(error => {
|
261 |
-
document.getElementById('statusText').textContent = 'An error occurred. Please try again.';
|
262 |
-
document.getElementById('statusMessage').style.display = 'block';
|
263 |
-
});
|
264 |
-
}
|
265 |
-
|
266 |
-
window.onload = function () {
|
267 |
-
askLoginOrRegister();
|
268 |
-
};
|
269 |
</script>
|
270 |
</body>
|
271 |
</html>
|
|
|
49 |
</head>
|
50 |
<body>
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
<div class="container" id="welcomePage">
|
53 |
+
<h1>Welcome to Biryani Hub 🍽</h1>
|
54 |
<h2 class="info" id="infoMessage">Welcome! Are you a new customer or an existing one?</h2>
|
55 |
<p class="status" id="status">🔊 Please say 'new' to register or 'existing' to login.</p>
|
56 |
</div>
|
|
|
82 |
<p class="status" id="loginStatus">Listening... 🗣</p>
|
83 |
</div>
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
<script>
|
86 |
+
function checkEmailExists(email) {
|
87 |
+
fetch(`/check_email?email=${encodeURIComponent(email)}`)
|
88 |
+
.then(response => response.json())
|
89 |
+
.then(data => {
|
90 |
+
if (data.exists) {
|
91 |
+
speak("Welcome back! You are logged in.");
|
92 |
+
document.getElementById('loginForm').style.display = 'block';
|
93 |
+
document.getElementById('registrationForm').style.display = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
} else {
|
95 |
+
speak("You are a new customer. Please proceed with registration.");
|
96 |
+
document.getElementById('registrationForm').style.display = 'block';
|
97 |
+
document.getElementById('loginForm').style.display = 'none';
|
98 |
}
|
99 |
+
})
|
100 |
+
.catch(() => {
|
101 |
+
speak("Error checking email. Please try again.");
|
102 |
+
});
|
103 |
}
|
104 |
|
105 |
function captureEmail() {
|
|
|
107 |
recognition.start();
|
108 |
recognition.onresult = function (event) {
|
109 |
let emailCaptured = event.results[0][0].transcript.trim();
|
|
|
110 |
recognition.stop();
|
|
|
111 |
if (!isValidEmail(emailCaptured)) {
|
112 |
speak("The email address is invalid. Please provide a valid email like [email protected].", captureEmail);
|
113 |
} else {
|
114 |
+
checkEmailExists(emailCaptured);
|
|
|
|
|
115 |
}
|
116 |
};
|
117 |
});
|
118 |
}
|
119 |
|
120 |
+
function isValidPhone(phone) {
|
121 |
+
return /^\d{12}$/.test(phone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
|
124 |
function captureMobile() {
|
125 |
+
speak("Please say your 12-digit mobile number.", function () {
|
126 |
recognition.start();
|
127 |
recognition.onresult = function (event) {
|
128 |
let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
|
|
|
129 |
recognition.stop();
|
130 |
if (!isValidPhone(mobileCaptured)) {
|
131 |
+
speak("The mobile number is invalid. Please provide exactly 12 digits.", captureMobile);
|
132 |
} else {
|
133 |
speak("You said " + mobileCaptured + ". Is it correct?", function () {
|
134 |
confirmMobile(mobileCaptured);
|
|
|
137 |
};
|
138 |
});
|
139 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
</script>
|
141 |
</body>
|
142 |
</html>
|