|
1209 | 1209 | ? this.email_address || '' |
1210 | 1210 | : this.username || ''; |
1211 | 1211 |
|
1212 | | - // Include captcha tokens if present on the page. |
1213 | | - const login_data = { |
1214 | | - username_or_email, |
1215 | | - password: this.inline_login_password, |
1216 | | - _wpnonce: jQuery('[name="_wpnonce"]').val() |
1217 | | - }; |
1218 | | - |
1219 | | - const recaptcha_token = jQuery('input[name="g-recaptcha-response"]').filter(function() { |
1220 | | - return this.value; |
1221 | | - }).first().val(); |
1222 | | - const hcaptcha_token = jQuery('input[name="h-captcha-response"]').filter(function() { |
1223 | | - return this.value; |
1224 | | - }).first().val(); |
1225 | | - const cap_token = jQuery('input[name="cap-token"]').filter(function() { |
1226 | | - return this.value; |
1227 | | - }).first().val(); |
1228 | | - |
1229 | | - if (recaptcha_token) { |
1230 | | - login_data[ 'g-recaptcha-response' ] = recaptcha_token; |
1231 | | - } |
| 1212 | + // Include captcha tokens scoped to the inline login prompt container. |
| 1213 | + // Using scoped selectors avoids picking up the checkout form's captcha token. |
| 1214 | + const promptContainer = jQuery('#wu-inline-login-prompt-' + this.login_prompt_field); |
| 1215 | + const login_data = { |
| 1216 | + username_or_email, |
| 1217 | + password: this.inline_login_password, |
| 1218 | + _wpnonce: jQuery('[name="_wpnonce"]').val() |
| 1219 | + }; |
1232 | 1220 |
|
1233 | | - if (hcaptcha_token) { |
1234 | | - login_data[ 'h-captcha-response' ] = hcaptcha_token; |
1235 | | - } |
| 1221 | + const recaptcha_token = promptContainer.find('input[name="g-recaptcha-response"]').filter(function() { |
| 1222 | + return this.value; |
| 1223 | + }).first().val(); |
| 1224 | + const hcaptcha_token = promptContainer.find('input[name="h-captcha-response"]').filter(function() { |
| 1225 | + return this.value; |
| 1226 | + }).first().val(); |
| 1227 | + const cap_token = promptContainer.find('input[name="cap-token"]').filter(function() { |
| 1228 | + return this.value; |
| 1229 | + }).first().val(); |
1236 | 1230 |
|
1237 | | - if (cap_token) { |
1238 | | - login_data[ 'cap-token' ] = cap_token; |
1239 | | - } |
| 1231 | + if (recaptcha_token) { |
| 1232 | + login_data[ 'g-recaptcha-response' ] = recaptcha_token; |
| 1233 | + } |
1240 | 1234 |
|
1241 | | - this.request('wu_inline_login', login_data, function(results) { |
| 1235 | + if (hcaptcha_token) { |
| 1236 | + login_data[ 'h-captcha-response' ] = hcaptcha_token; |
| 1237 | + } |
1242 | 1238 |
|
1243 | | - that.logging_in = false; |
| 1239 | + if (cap_token) { |
| 1240 | + login_data[ 'cap-token' ] = cap_token; |
| 1241 | + } |
1244 | 1242 |
|
1245 | | - if (results.success) { |
| 1243 | + this.request('wu_inline_login', login_data, function(results) { |
1246 | 1244 |
|
1247 | | - // Login successful - reload page to show logged-in state |
1248 | | - window.location.reload(); |
| 1245 | + that.logging_in = false; |
1249 | 1246 |
|
1250 | | - } |
| 1247 | + if (results.success) { |
1251 | 1248 |
|
1252 | | - }, function(error) { |
| 1249 | + // Login successful - reload page to show logged-in state |
| 1250 | + window.location.reload(); |
1253 | 1251 |
|
1254 | | - that.logging_in = false; |
| 1252 | + } |
1255 | 1253 |
|
1256 | | - if (error.responseJSON && error.responseJSON.data && error.responseJSON.data.message) { |
| 1254 | + }, function(error) { |
1257 | 1255 |
|
1258 | | - that.login_error = error.responseJSON.data.message; |
| 1256 | + that.logging_in = false; |
1259 | 1257 |
|
1260 | | - } else { |
| 1258 | + if (error.responseJSON && error.responseJSON.data && error.responseJSON.data.message) { |
1261 | 1259 |
|
1262 | | - that.login_error = wu_checkout.i18n.login_failed || 'Login failed. Please try again.'; |
| 1260 | + that.login_error = error.responseJSON.data.message; |
1263 | 1261 |
|
1264 | | - } |
| 1262 | + } else { |
1265 | 1263 |
|
1266 | | - }); |
| 1264 | + that.login_error = wu_checkout.i18n.login_failed || 'Login failed. Please try again.'; |
| 1265 | + |
| 1266 | + } |
| 1267 | + |
| 1268 | + // Reset inline login captcha widgets so the user can re-verify. |
| 1269 | + if (typeof window.wuCaptchaResetInlineLogin === 'function') { |
| 1270 | + window.wuCaptchaResetInlineLogin(); |
| 1271 | + } |
| 1272 | + |
| 1273 | + }); |
1267 | 1274 |
|
1268 | 1275 | return false; |
1269 | 1276 |
|
|
1336 | 1343 |
|
1337 | 1344 | } |
1338 | 1345 |
|
1339 | | - function handleError(error) { |
| 1346 | + function handleError(error) { |
1340 | 1347 |
|
1341 | | - submitButton.disabled = false; |
1342 | | - submitButton.textContent = wu_checkout.i18n.sign_in || 'Sign in'; |
| 1348 | + submitButton.disabled = false; |
| 1349 | + submitButton.textContent = wu_checkout.i18n.sign_in || 'Sign in'; |
1343 | 1350 |
|
1344 | | - if (error.data && error.data.message) { |
| 1351 | + if (error.data && error.data.message) { |
1345 | 1352 |
|
1346 | | - showError(error.data.message); |
| 1353 | + showError(error.data.message); |
1347 | 1354 |
|
1348 | | - } else { |
| 1355 | + } else { |
1349 | 1356 |
|
1350 | | - showError(wu_checkout.i18n.login_failed || 'Login failed. Please try again.'); |
| 1357 | + showError(wu_checkout.i18n.login_failed || 'Login failed. Please try again.'); |
1351 | 1358 |
|
1352 | | - } |
| 1359 | + } |
1353 | 1360 |
|
1354 | | - } |
| 1361 | + // Reset inline login captcha widgets so the user can re-verify. |
| 1362 | + if (typeof window.wuCaptchaResetInlineLogin === 'function') { |
| 1363 | + window.wuCaptchaResetInlineLogin(); |
| 1364 | + } |
| 1365 | + |
| 1366 | + } |
1355 | 1367 |
|
1356 | 1368 | function handleLogin(e) { |
1357 | 1369 |
|
|
1375 | 1387 |
|
1376 | 1388 | const username_or_email = fieldType === 'email' ? that.email_address : that.username; |
1377 | 1389 |
|
1378 | | - // Include captcha tokens if present on the page. |
1379 | | - const inline_login_data = { |
1380 | | - username_or_email, |
1381 | | - password, |
1382 | | - _wpnonce: jQuery('[name="_wpnonce"]').val() |
1383 | | - }; |
1384 | | - |
1385 | | - const recaptcha_val = jQuery('input[name="g-recaptcha-response"]').filter(function() { |
1386 | | - return this.value; |
1387 | | - }).first().val(); |
1388 | | - const hcaptcha_val = jQuery('input[name="h-captcha-response"]').filter(function() { |
1389 | | - return this.value; |
1390 | | - }).first().val(); |
1391 | | - const cap_val = jQuery('input[name="cap-token"]').filter(function() { |
1392 | | - return this.value; |
1393 | | - }).first().val(); |
1394 | | - |
1395 | | - if (recaptcha_val) { |
1396 | | - inline_login_data[ 'g-recaptcha-response' ] = recaptcha_val; |
1397 | | - } |
1398 | | - |
1399 | | - if (hcaptcha_val) { |
1400 | | - inline_login_data[ 'h-captcha-response' ] = hcaptcha_val; |
1401 | | - } |
1402 | | - |
1403 | | - if (cap_val) { |
1404 | | - inline_login_data[ 'cap-token' ] = cap_val; |
1405 | | - } |
1406 | | - |
1407 | | - jQuery.ajax({ |
1408 | | - method: 'POST', |
1409 | | - url: wu_checkout.late_ajaxurl + '&action=wu_inline_login', |
1410 | | - data: inline_login_data, |
1411 | | - success(results) { |
1412 | | - |
1413 | | - if (results.success) { |
1414 | | - |
1415 | | - window.location.reload(); |
| 1390 | + // Include captcha tokens scoped to the inline login prompt container. |
| 1391 | + // Using scoped selectors avoids picking up the checkout form's captcha token. |
| 1392 | + const promptContainer = jQuery('#wu-inline-login-prompt-' + fieldType); |
| 1393 | + const inline_login_data = { |
| 1394 | + username_or_email, |
| 1395 | + password, |
| 1396 | + _wpnonce: jQuery('[name="_wpnonce"]').val() |
| 1397 | + }; |
| 1398 | + |
| 1399 | + const recaptcha_val = promptContainer.find('input[name="g-recaptcha-response"]').filter(function() { |
| 1400 | + return this.value; |
| 1401 | + }).first().val(); |
| 1402 | + const hcaptcha_val = promptContainer.find('input[name="h-captcha-response"]').filter(function() { |
| 1403 | + return this.value; |
| 1404 | + }).first().val(); |
| 1405 | + const cap_val = promptContainer.find('input[name="cap-token"]').filter(function() { |
| 1406 | + return this.value; |
| 1407 | + }).first().val(); |
| 1408 | + |
| 1409 | + if (recaptcha_val) { |
| 1410 | + inline_login_data[ 'g-recaptcha-response' ] = recaptcha_val; |
| 1411 | + } |
| 1412 | + |
| 1413 | + if (hcaptcha_val) { |
| 1414 | + inline_login_data[ 'h-captcha-response' ] = hcaptcha_val; |
| 1415 | + } |
| 1416 | + |
| 1417 | + if (cap_val) { |
| 1418 | + inline_login_data[ 'cap-token' ] = cap_val; |
| 1419 | + } |
| 1420 | + |
| 1421 | + jQuery.ajax({ |
| 1422 | + method: 'POST', |
| 1423 | + url: wu_checkout.late_ajaxurl + '&action=wu_inline_login', |
| 1424 | + data: inline_login_data, |
| 1425 | + success(results) { |
| 1426 | + |
| 1427 | + if (results.success) { |
| 1428 | + |
| 1429 | + window.location.reload(); |
| 1430 | + |
| 1431 | + } else { |
| 1432 | + handleError(results); |
| 1433 | + } |
1416 | 1434 |
|
1417 | | - } else { |
1418 | | - handleError(results); |
1419 | | - } |
| 1435 | + }, |
| 1436 | + error(xhr) { |
| 1437 | + handleError(xhr.responseJSON || {}); |
1420 | 1438 |
|
1421 | | - }, |
1422 | | - error: handleError |
1423 | | - }); |
| 1439 | + // Reset inline login captcha widgets so the user can re-verify. |
| 1440 | + if (typeof window.wuCaptchaResetInlineLogin === 'function') { |
| 1441 | + window.wuCaptchaResetInlineLogin(); |
| 1442 | + } |
| 1443 | + } |
| 1444 | + }); |
1424 | 1445 |
|
1425 | 1446 | return false; |
1426 | 1447 |
|
|
0 commit comments