lokesh341 commited on
Commit
f71b1b4
·
verified ·
1 Parent(s): c44c503

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +84 -1
templates/index.html CHANGED
@@ -275,10 +275,93 @@
275
  });
276
  }
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  window.onload = function () {
279
  askLoginOrRegister();
280
  };
281
  </script>
282
  </body>
283
  </html>
284
-
 
275
  });
276
  }
277
 
278
+ function captureLoginDetails() {
279
+ speak("Please say your email for login.", function () {
280
+ recognition.start();
281
+ recognition.onresult = function (event) {
282
+ let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
283
+ document.getElementById('loginEmail').value = emailCaptured;
284
+ recognition.stop();
285
+ speak("You said " + emailCaptured + ". Is it correct?", function () {
286
+ confirmLoginEmail(emailCaptured);
287
+ });
288
+ };
289
+ });
290
+ }
291
+
292
+ function confirmLoginEmail(emailCaptured) {
293
+ recognition.start();
294
+ recognition.onresult = function (event) {
295
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
296
+ recognition.stop();
297
+ if (isConfirmation(confirmation)) {
298
+ captureLoginMobile();
299
+ } else {
300
+ captureLoginDetails();
301
+ }
302
+ };
303
+ }
304
+
305
+ function captureLoginMobile() {
306
+ speak("Now, say your mobile number.", function () {
307
+ recognition.start();
308
+ recognition.onresult = function (event) {
309
+ let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
310
+ document.getElementById('loginMobile').value = mobileCaptured;
311
+ recognition.stop();
312
+ speak("You said " + mobileCaptured + ". Is it correct?", function () {
313
+ confirmLoginMobile(mobileCaptured);
314
+ });
315
+ };
316
+ });
317
+ }
318
+
319
+ function confirmLoginMobile(mobileCaptured) {
320
+ recognition.start();
321
+ recognition.onresult = function (event) {
322
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
323
+ recognition.stop();
324
+ if (isConfirmation(confirmation)) {
325
+ submitLogin();
326
+ } else {
327
+ captureLoginMobile();
328
+ }
329
+ };
330
+ }
331
+
332
+ function submitLogin() {
333
+ const loginEmail = document.getElementById('loginEmail').value;
334
+ const loginMobile = document.getElementById('loginMobile').value;
335
+ // Simulate login check by querying Salesforce
336
+ if (loginEmail && loginMobile) {
337
+ fetch('/validate-login', {
338
+ method: 'POST',
339
+ headers: { 'Content-Type': 'application/json' },
340
+ body: JSON.stringify({ email: loginEmail, mobile: loginMobile })
341
+ })
342
+ .then(response => response.json())
343
+ .then(data => {
344
+ if (data.success) {
345
+ const userName = data.name; // Retrieve the name from the response
346
+ speak(`Welcome, ${userName}!`); // Speak the welcome message with the user's name
347
+ window.location.href = '/menu'; // Redirect to menu after successful login
348
+ } else {
349
+ // alert("Invalid login details. Please try again.");
350
+ speak("Invalid login details. Please try again.");
351
+ }
352
+ })
353
+ .catch(error => {
354
+ console.error('Login validation failed:', error);
355
+ alert("An error occurred. Please try again.");
356
+ });
357
+ } else {
358
+ alert("Please provide both email and mobile number.");
359
+ }
360
+ }
361
+
362
  window.onload = function () {
363
  askLoginOrRegister();
364
  };
365
  </script>
366
  </body>
367
  </html>