Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +135 -129
templates/index.html
CHANGED
@@ -60,7 +60,8 @@
|
|
60 |
color: gray;
|
61 |
margin-top: 10px;
|
62 |
}
|
63 |
-
.confirm-button,
|
|
|
64 |
padding: 10px 20px;
|
65 |
background-color: #ff6a00;
|
66 |
color: white;
|
@@ -69,57 +70,76 @@
|
|
69 |
cursor: pointer;
|
70 |
margin-top: 10px;
|
71 |
}
|
72 |
-
.confirm-button:hover,
|
|
|
73 |
background-color: #e65e00;
|
74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
</style>
|
76 |
</head>
|
77 |
<body>
|
78 |
<div class="container">
|
79 |
<h1>Welcome to Biryani Hub 🍽</h1>
|
80 |
-
<h2 class="info" id="infoMessage">Listening... 🗣🎙</h2>
|
81 |
-
<p class="status" id="status">🔊 Speak Now...</p>
|
82 |
|
83 |
<!-- Registration Form -->
|
84 |
-
<div id="registrationForm">
|
85 |
<h2>Register</h2>
|
86 |
<label for="name">Your Name</label>
|
87 |
-
<input type="text" id="name" placeholder="
|
88 |
|
89 |
<label for="email">Your Email</label>
|
90 |
-
<input type="
|
91 |
|
92 |
<label for="mobile">Your Mobile Number</label>
|
93 |
-
<input type="text" id="mobile" placeholder="
|
94 |
|
95 |
-
<button class="confirm-button" onclick="
|
96 |
<button class="switch-button" onclick="showLoginForm()">Switch to Login</button>
|
97 |
</div>
|
98 |
|
99 |
<!-- Login Form -->
|
100 |
-
<div
|
101 |
<h2>Login</h2>
|
102 |
<label for="loginEmail">Your Email</label>
|
103 |
-
<input type="
|
104 |
|
105 |
<label for="loginMobile">Your Mobile Number</label>
|
106 |
<input type="text" id="loginMobile" placeholder="Listening for mobile number..." readonly>
|
107 |
|
108 |
-
<button class="confirm-button" onclick="
|
109 |
<button class="switch-button" onclick="showRegistrationForm()">Switch to Register</button>
|
110 |
</div>
|
111 |
|
112 |
<!-- Confirmation Details -->
|
113 |
-
<div id="confirmationForm"
|
114 |
<h2>Confirm Your Details</h2>
|
115 |
-
<
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
119 |
</div>
|
120 |
|
121 |
-
<div id="statusMessage" style="display:
|
122 |
-
<
|
123 |
</div>
|
124 |
</div>
|
125 |
|
@@ -134,175 +154,161 @@
|
|
134 |
alert("Speech Recognition API is not supported in this browser.");
|
135 |
}
|
136 |
|
|
|
137 |
function speak(text, callback) {
|
138 |
const speech = new SpeechSynthesisUtterance(text);
|
139 |
speech.onend = callback;
|
140 |
window.speechSynthesis.speak(speech);
|
141 |
}
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
showLoginForm();
|
154 |
-
|
155 |
-
}
|
156 |
-
|
157 |
-
|
158 |
-
}
|
|
|
|
|
|
|
159 |
});
|
160 |
}
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
document.getElementById('
|
165 |
-
document.getElementById('
|
166 |
-
document.getElementById('statusMessage').style.display = 'none';
|
167 |
}
|
168 |
|
|
|
169 |
function showLoginForm() {
|
170 |
-
document.getElementById('loginForm').
|
171 |
-
document.getElementById('registrationForm').
|
172 |
-
document.getElementById('confirmationForm').
|
173 |
-
document.getElementById('statusMessage').style.display = 'none';
|
174 |
-
}
|
175 |
-
|
176 |
-
function captureName() {
|
177 |
-
speak("Please say your name.", function () {
|
178 |
-
recognition.start();
|
179 |
-
recognition.onresult = function (event) {
|
180 |
-
let nameCaptured = event.results[0][0].transcript.trim();
|
181 |
-
document.getElementById('name').value = nameCaptured;
|
182 |
-
recognition.stop();
|
183 |
-
speak("You said " + nameCaptured + ". Is it correct?", function () {
|
184 |
-
confirmName(nameCaptured);
|
185 |
-
});
|
186 |
-
};
|
187 |
-
});
|
188 |
}
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
recognition.stop();
|
195 |
-
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
196 |
-
captureEmail();
|
197 |
-
} else {
|
198 |
-
captureName();
|
199 |
-
}
|
200 |
-
};
|
201 |
-
}
|
202 |
|
203 |
-
|
204 |
-
speak("Now, say your email.", function () {
|
205 |
recognition.start();
|
206 |
recognition.onresult = function (event) {
|
207 |
-
|
208 |
-
|
209 |
recognition.stop();
|
|
|
210 |
speak("You said " + emailCaptured + ". Is it correct?", function () {
|
211 |
-
|
212 |
});
|
213 |
};
|
214 |
});
|
215 |
}
|
216 |
|
217 |
-
|
|
|
218 |
recognition.start();
|
219 |
recognition.onresult = function (event) {
|
220 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
221 |
recognition.stop();
|
222 |
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
223 |
-
|
224 |
} else {
|
225 |
-
|
226 |
}
|
227 |
};
|
228 |
}
|
229 |
|
230 |
-
|
231 |
-
|
|
|
|
|
232 |
recognition.start();
|
233 |
recognition.onresult = function (event) {
|
234 |
-
|
235 |
-
|
236 |
recognition.stop();
|
|
|
237 |
speak("You said " + mobileCaptured + ". Is it correct?", function () {
|
238 |
-
|
239 |
});
|
240 |
};
|
241 |
});
|
242 |
}
|
243 |
|
244 |
-
|
|
|
245 |
recognition.start();
|
246 |
recognition.onresult = function (event) {
|
247 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
248 |
recognition.stop();
|
249 |
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
250 |
-
|
251 |
-
confirmDetailsAndShow();
|
252 |
} else {
|
253 |
-
|
254 |
}
|
255 |
};
|
256 |
}
|
257 |
|
258 |
-
//
|
259 |
-
function
|
260 |
-
const
|
261 |
-
const
|
262 |
-
const phone = document.getElementById('mobile').value;
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
// Show confirmation form and hide registration form
|
269 |
-
document.getElementById('registrationForm').style.display = 'none';
|
270 |
-
document.getElementById('confirmationForm').style.display = 'block';
|
271 |
-
}
|
272 |
-
|
273 |
-
// Submit details to the backend (Salesforce)
|
274 |
-
function submitDetails() {
|
275 |
-
const name = document.getElementById('name').value;
|
276 |
-
const email = document.getElementById('email').value;
|
277 |
-
const phone = document.getElementById('mobile').value;
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
body: JSON.stringify({ name, email, phone })
|
284 |
-
})
|
285 |
-
.then(response => response.json())
|
286 |
-
.then(data => {
|
287 |
-
if (data.success) {
|
288 |
-
document.getElementById('statusText').textContent = 'Your details have been successfully submitted!';
|
289 |
-
document.getElementById('statusMessage').style.display = 'block';
|
290 |
-
setTimeout(() => {
|
291 |
-
window.location.href = '/login'; // Redirect to login page
|
292 |
-
}, 3000);
|
293 |
-
} else {
|
294 |
-
document.getElementById('statusText').textContent = 'There was an error submitting your details. Please try again.';
|
295 |
-
document.getElementById('statusMessage').style.display = 'block';
|
296 |
-
}
|
297 |
-
})
|
298 |
-
.catch(error => {
|
299 |
-
document.getElementById('statusText').textContent = 'An error occurred. Please try again.';
|
300 |
-
document.getElementById('statusMessage').style.display = 'block';
|
301 |
-
});
|
302 |
}
|
303 |
|
304 |
window.onload = function () {
|
305 |
-
|
306 |
};
|
307 |
</script>
|
308 |
</body>
|
|
|
60 |
color: gray;
|
61 |
margin-top: 10px;
|
62 |
}
|
63 |
+
.confirm-button,
|
64 |
+
.switch-button {
|
65 |
padding: 10px 20px;
|
66 |
background-color: #ff6a00;
|
67 |
color: white;
|
|
|
70 |
cursor: pointer;
|
71 |
margin-top: 10px;
|
72 |
}
|
73 |
+
.confirm-button:hover,
|
74 |
+
.switch-button:hover {
|
75 |
background-color: #e65e00;
|
76 |
}
|
77 |
+
|
78 |
+
.form-container {
|
79 |
+
display: none;
|
80 |
+
}
|
81 |
+
|
82 |
+
.form-container.active {
|
83 |
+
display: block;
|
84 |
+
}
|
85 |
+
|
86 |
+
.confirmation-details {
|
87 |
+
margin-top: 20px;
|
88 |
+
font-size: 18px;
|
89 |
+
color: #333;
|
90 |
+
}
|
91 |
+
|
92 |
+
.confirmation-details span {
|
93 |
+
font-weight: bold;
|
94 |
+
}
|
95 |
</style>
|
96 |
</head>
|
97 |
<body>
|
98 |
<div class="container">
|
99 |
<h1>Welcome to Biryani Hub 🍽</h1>
|
|
|
|
|
100 |
|
101 |
<!-- Registration Form -->
|
102 |
+
<div class="form-container" id="registrationForm">
|
103 |
<h2>Register</h2>
|
104 |
<label for="name">Your Name</label>
|
105 |
+
<input type="text" id="name" placeholder="Enter your name" readonly>
|
106 |
|
107 |
<label for="email">Your Email</label>
|
108 |
+
<input type="email" id="email" placeholder="Enter your email" readonly>
|
109 |
|
110 |
<label for="mobile">Your Mobile Number</label>
|
111 |
+
<input type="text" id="mobile" placeholder="Enter your mobile number" readonly>
|
112 |
|
113 |
+
<button class="confirm-button" onclick="confirmRegistration()">Confirm Registration</button>
|
114 |
<button class="switch-button" onclick="showLoginForm()">Switch to Login</button>
|
115 |
</div>
|
116 |
|
117 |
<!-- Login Form -->
|
118 |
+
<div class="form-container" id="loginForm">
|
119 |
<h2>Login</h2>
|
120 |
<label for="loginEmail">Your Email</label>
|
121 |
+
<input type="email" id="loginEmail" placeholder="Listening for email..." readonly>
|
122 |
|
123 |
<label for="loginMobile">Your Mobile Number</label>
|
124 |
<input type="text" id="loginMobile" placeholder="Listening for mobile number..." readonly>
|
125 |
|
126 |
+
<button class="confirm-button" onclick="captureLoginDetails()">Start Voice Input</button>
|
127 |
<button class="switch-button" onclick="showRegistrationForm()">Switch to Register</button>
|
128 |
</div>
|
129 |
|
130 |
<!-- Confirmation Details -->
|
131 |
+
<div id="confirmationForm" class="form-container">
|
132 |
<h2>Confirm Your Details</h2>
|
133 |
+
<div class="confirmation-details">
|
134 |
+
<p><span>Name:</span> <span id="confirmName"></span></p>
|
135 |
+
<p><span>Email:</span> <span id="confirmEmail"></span></p>
|
136 |
+
<p><span>Phone:</span> <span id="confirmPhone"></span></p>
|
137 |
+
</div>
|
138 |
+
<button class="confirm-button" onclick="submitRegistration()">Submit</button>
|
139 |
</div>
|
140 |
|
141 |
+
<div id="statusMessage" class="status" style="display:none;">
|
142 |
+
<p id="statusText"></p>
|
143 |
</div>
|
144 |
</div>
|
145 |
|
|
|
154 |
alert("Speech Recognition API is not supported in this browser.");
|
155 |
}
|
156 |
|
157 |
+
// Function to speak a message
|
158 |
function speak(text, callback) {
|
159 |
const speech = new SpeechSynthesisUtterance(text);
|
160 |
speech.onend = callback;
|
161 |
window.speechSynthesis.speak(speech);
|
162 |
}
|
163 |
|
164 |
+
// Registration flow confirmation
|
165 |
+
function confirmRegistration() {
|
166 |
+
const name = document.getElementById('name').value;
|
167 |
+
const email = document.getElementById('email').value;
|
168 |
+
const mobile = document.getElementById('mobile').value;
|
169 |
+
|
170 |
+
if (!name || !email || !mobile) {
|
171 |
+
alert("Please fill out all fields!");
|
172 |
+
return;
|
173 |
+
}
|
174 |
+
|
175 |
+
// Display confirmation details
|
176 |
+
document.getElementById('confirmName').textContent = name;
|
177 |
+
document.getElementById('confirmEmail').textContent = email;
|
178 |
+
document.getElementById('confirmPhone').textContent = mobile;
|
179 |
+
|
180 |
+
// Show confirmation form and hide registration form
|
181 |
+
document.getElementById('registrationForm').classList.remove('active');
|
182 |
+
document.getElementById('confirmationForm').classList.add('active');
|
183 |
+
}
|
184 |
+
|
185 |
+
// Submit registration details to backend
|
186 |
+
function submitRegistration() {
|
187 |
+
const name = document.getElementById('name').value;
|
188 |
+
const email = document.getElementById('email').value;
|
189 |
+
const mobile = document.getElementById('mobile').value;
|
190 |
+
|
191 |
+
fetch('/submit', {
|
192 |
+
method: 'POST',
|
193 |
+
headers: { 'Content-Type': 'application/json' },
|
194 |
+
body: JSON.stringify({
|
195 |
+
name: name,
|
196 |
+
email: email,
|
197 |
+
phone: mobile
|
198 |
+
})
|
199 |
+
})
|
200 |
+
.then(response => response.json())
|
201 |
+
.then(data => {
|
202 |
+
if (data.success) {
|
203 |
+
showStatusMessage("Registration successful! Redirecting to login...");
|
204 |
+
setTimeout(() => {
|
205 |
showLoginForm();
|
206 |
+
document.getElementById('statusMessage').style.display = 'none';
|
207 |
+
}, 2000);
|
208 |
+
} else {
|
209 |
+
showStatusMessage("Error submitting details, please try again.");
|
210 |
+
}
|
211 |
+
})
|
212 |
+
.catch(error => {
|
213 |
+
showStatusMessage("An error occurred, please try again.");
|
214 |
});
|
215 |
}
|
216 |
|
217 |
+
// Show status message after submission
|
218 |
+
function showStatusMessage(message) {
|
219 |
+
document.getElementById('statusText').textContent = message;
|
220 |
+
document.getElementById('statusMessage').style.display = 'block';
|
|
|
221 |
}
|
222 |
|
223 |
+
// Switch to login form
|
224 |
function showLoginForm() {
|
225 |
+
document.getElementById('loginForm').classList.add('active');
|
226 |
+
document.getElementById('registrationForm').classList.remove('active');
|
227 |
+
document.getElementById('confirmationForm').classList.remove('active');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
}
|
229 |
|
230 |
+
// Capture login details (email and mobile)
|
231 |
+
function captureLoginDetails() {
|
232 |
+
const loginEmail = document.getElementById('loginEmail');
|
233 |
+
const loginMobile = document.getElementById('loginMobile');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
|
235 |
+
speak("Please say your email for login.", function () {
|
|
|
236 |
recognition.start();
|
237 |
recognition.onresult = function (event) {
|
238 |
+
const emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
|
239 |
+
loginEmail.value = emailCaptured;
|
240 |
recognition.stop();
|
241 |
+
|
242 |
speak("You said " + emailCaptured + ". Is it correct?", function () {
|
243 |
+
confirmLoginEmail(emailCaptured);
|
244 |
});
|
245 |
};
|
246 |
});
|
247 |
}
|
248 |
|
249 |
+
// Confirm login email and capture mobile number
|
250 |
+
function confirmLoginEmail(emailCaptured) {
|
251 |
recognition.start();
|
252 |
recognition.onresult = function (event) {
|
253 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
254 |
recognition.stop();
|
255 |
if (confirmation.includes("yes") || confirmation.includes("ok")) {
|
256 |
+
captureLoginMobile();
|
257 |
} else {
|
258 |
+
captureLoginDetails();
|
259 |
}
|
260 |
};
|
261 |
}
|
262 |
|
263 |
+
// Capture login mobile number
|
264 |
+
function captureLoginMobile() {
|
265 |
+
const loginMobile = document.getElementById('loginMobile');
|
266 |
+
speak("Now, say your mobile number for login.", function () {
|
267 |
recognition.start();
|
268 |
recognition.onresult = function (event) {
|
269 |
+
const mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
|
270 |
+
loginMobile.value = mobileCaptured;
|
271 |
recognition.stop();
|
272 |
+
|
273 |
speak("You said " + mobileCaptured + ". Is it correct?", function () {
|
274 |
+
confirmLoginMobile(mobileCaptured);
|
275 |
});
|
276 |
};
|
277 |
});
|
278 |
}
|
279 |
|
280 |
+
// Confirm login mobile number and submit
|
281 |
+
function confirmLoginMobile(mobileCaptured) {
|
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("yes") || confirmation.includes("ok")) {
|
287 |
+
submitLoginDetails();
|
|
|
288 |
} else {
|
289 |
+
captureLoginMobile();
|
290 |
}
|
291 |
};
|
292 |
}
|
293 |
|
294 |
+
// Simulate login submission
|
295 |
+
function submitLoginDetails() {
|
296 |
+
const loginEmail = document.getElementById('loginEmail').value;
|
297 |
+
const loginMobile = document.getElementById('loginMobile').value;
|
|
|
298 |
|
299 |
+
if (!loginEmail || !loginMobile) {
|
300 |
+
alert("Please fill out both fields!");
|
301 |
+
return;
|
302 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
+
speak("Login successful!");
|
305 |
+
setTimeout(() => {
|
306 |
+
window.location.href = "/dashboard"; // Redirect to the dashboard or main page after login
|
307 |
+
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
}
|
309 |
|
310 |
window.onload = function () {
|
311 |
+
showLoginForm(); // Show login form by default
|
312 |
};
|
313 |
</script>
|
314 |
</body>
|