lokesh341 commited on
Commit
92254d2
·
verified ·
1 Parent(s): 6fd742a

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +56 -10
templates/index.html CHANGED
@@ -244,23 +244,69 @@
244
  };
245
  }
246
 
247
- // Submit registration to backend
248
- function submitRegistration() {
249
- let name = document.getElementById('name').value;
250
- let email = document.getElementById('email').value;
251
- let mobile = document.getElementById('mobile').value;
252
- fetch('/submit_registration', {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  method: 'POST',
254
  headers: { 'Content-Type': 'application/json' },
255
- body: JSON.stringify({ name: name, email: email, mobile: mobile })
256
  })
257
  .then(response => response.json())
258
  .then(data => {
259
- speak("Registration successful. Thank you!");
260
- // Redirect or do further actions
261
  })
262
  .catch(error => {
263
- speak("There was an error with your registration. Please try again.");
264
  });
265
  }
266
 
 
244
  };
245
  }
246
 
247
+ // Start login process (similar to registration process but only email and phone)
248
+ function startListeningForLoginEmail() {
249
+ recognition.start();
250
+ recognition.onresult = function(event) {
251
+ emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
252
+ document.getElementById('loginEmail').value = emailCaptured;
253
+ recognition.stop();
254
+ speak("You said " + emailCaptured + ". Is it correct?", confirmLoginEmail);
255
+ };
256
+ }
257
+
258
+ function confirmLoginEmail() {
259
+ recognition.start();
260
+ recognition.onresult = function(event) {
261
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
262
+ recognition.stop();
263
+ if (confirmation.includes("ok")) {
264
+ speak("Great! Now, tell me your mobile number.", startListeningForLoginMobile);
265
+ } else {
266
+ speak("Let's try again. Tell me your email.", startListeningForLoginEmail);
267
+ }
268
+ };
269
+ }
270
+
271
+ function startListeningForLoginMobile() {
272
+ recognition.start();
273
+ recognition.onresult = function(event) {
274
+ mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
275
+ document.getElementById('loginMobile').value = mobileCaptured;
276
+ recognition.stop();
277
+ speak("You said " + mobileCaptured + ". Is it correct?", confirmLoginMobile);
278
+ };
279
+ }
280
+
281
+ function confirmLoginMobile() {
282
+ recognition.start();
283
+ recognition.onresult = function(event) {
284
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
285
+ recognition.stop();
286
+ if (confirmation.includes("ok")) {
287
+ submitLogin();
288
+ } else {
289
+ speak("Let's try again. Tell me your mobile number.", startListeningForLoginMobile);
290
+ }
291
+ };
292
+ }
293
+
294
+ // Submit login details to backend
295
+ function submitLogin() {
296
+ let email = document.getElementById('loginEmail').value;
297
+ let mobile = document.getElementById('loginMobile').value;
298
+ fetch('/submit_login', {
299
  method: 'POST',
300
  headers: { 'Content-Type': 'application/json' },
301
+ body: JSON.stringify({ email: email, mobile: mobile })
302
  })
303
  .then(response => response.json())
304
  .then(data => {
305
+ speak("Login successful. Welcome back!");
306
+ // Redirect or perform other actions
307
  })
308
  .catch(error => {
309
+ speak("There was an error with your login. Please try again.");
310
  });
311
  }
312