@prosopo/client-bundle-example 2.11.3 → 2.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$cjs.log +4 -7
- package/.turbo/turbo-build$colon$tsc.log +11 -14
- package/.turbo/turbo-build.log +4 -10
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +6 -6
- package/dist/cjs/plugins/pages.cjs +7 -0
- package/dist/plugins/pages.js +7 -0
- package/env.staging +5 -4
- package/package.json +52 -53
- package/vite.config.ts +50 -1
- package/env.development +0 -7
- package/env.production +0 -6
- package/src/assets/dummy.txt +0 -0
- package/src/frictionless-explicit-web3.html +0 -237
- package/src/frictionless-explicit.html +0 -205
- package/src/frictionless-implicit.html +0 -192
- package/src/frictionless-manual-start.html +0 -204
- package/src/image-explicit-web3.html +0 -182
- package/src/image-explicit.html +0 -151
- package/src/image-implicit.html +0 -192
- package/src/index.html +0 -192
- package/src/index.ts +0 -15
- package/src/invisible-frictionless-explicit.html +0 -123
- package/src/invisible-frictionless-implicit.html +0 -187
- package/src/invisible-image-explicit.html +0 -146
- package/src/invisible-image-implicit.html +0 -187
- package/src/invisible-pow-explicit.html +0 -146
- package/src/invisible-pow-implicit.html +0 -94
- package/src/invisible-puzzle-explicit.html +0 -145
- package/src/invisible-puzzle-implicit.html +0 -94
- package/src/plugins/code-snippet-injector.ts +0 -179
- package/src/plugins/form-filler-injector.ts +0 -148
- package/src/plugins/layout-injector.ts +0 -256
- package/src/plugins/logo.ts +0 -15
- package/src/plugins/pages.ts +0 -219
- package/src/plugins/placement-injector.ts +0 -114
- package/src/plugins/slots.ts +0 -32
- package/src/plugins/status-log-injector.ts +0 -143
- package/src/pow-explicit-web3.html +0 -179
- package/src/pow-explicit.html +0 -143
- package/src/pow-implicit-sessionid.html +0 -209
- package/src/pow-implicit.html +0 -192
- package/src/puzzle-bind-explicit.html +0 -83
- package/src/puzzle-explicit.html +0 -151
- package/src/puzzle-implicit.html +0 -192
- package/src/styles/demo.css +0 -803
- package/src/tests/explicitRender.unit.test.ts +0 -49
- package/src/tests/plugins.unit.test.ts +0 -490
- package/tsconfig.cjs.json +0 -25
- package/tsconfig.json +0 -31
- package/tsconfig.tsbuildinfo +0 -1
- package/tsconfig.types.json +0 -9
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Frictionless, manual start</title>
|
|
6
|
-
<script type="module">
|
|
7
|
-
|
|
8
|
-
window.onStartCaptcha = () => {
|
|
9
|
-
updateCaptchaStatus('window.procaptcha.start() called - frictionless flow starting', 'info');
|
|
10
|
-
window.procaptcha.start();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
window.addEventListener('load', () => {
|
|
14
|
-
|
|
15
|
-
window.setIsError = (isError) => {
|
|
16
|
-
const messageContainer = document.getElementById('messageContainer');
|
|
17
|
-
messageContainer.style.color = isError ? 'red' : 'black';
|
|
18
|
-
messageContainer.style.display = 'block';
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
window.setMessage = (message) => {
|
|
22
|
-
document.getElementById('message').innerText = message;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
window.onLoggedIn = (token) => {
|
|
26
|
-
updateCaptchaStatus('Logged in, fetching private resource', 'info');
|
|
27
|
-
const url = new URL("/private", config.serverUrl).href;
|
|
28
|
-
console.log("getting private resource with token ", token, "at", url);
|
|
29
|
-
fetch(url, {
|
|
30
|
-
method: "GET",
|
|
31
|
-
headers: {
|
|
32
|
-
Origin: "http://localhost:9232", // TODO: change this to env var
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
Authorization: `Bearer ${token}`,
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
.then(async (res) => {
|
|
38
|
-
try {
|
|
39
|
-
const jsonRes = await res.json();
|
|
40
|
-
if (res.status === 200) {
|
|
41
|
-
updateCaptchaStatus(`Successfully accessed private resource`, 'success');
|
|
42
|
-
setMessage(jsonRes.message);
|
|
43
|
-
} else {
|
|
44
|
-
updateCaptchaStatus(`Failed to access private resource: ${res.status}`, 'error');
|
|
45
|
-
}
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.log(err);
|
|
48
|
-
updateCaptchaStatus(`Error parsing response: ${err}`, 'error');
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
.catch((err) => {
|
|
52
|
-
console.log(err);
|
|
53
|
-
updateCaptchaStatus(`Fetch error: ${err}`, 'error');
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
window.onActionHandler = () => {
|
|
58
|
-
updateCaptchaStatus('Form submission initiated', 'info');
|
|
59
|
-
|
|
60
|
-
const procaptchaElements = document.getElementsByName('procaptcha-response');
|
|
61
|
-
|
|
62
|
-
if (!procaptchaElements.length) {
|
|
63
|
-
updateCaptchaStatus('Error: No CAPTCHA response found', 'error');
|
|
64
|
-
alert("Must complete captcha");
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const procaptchaToken = procaptchaElements[0].value;
|
|
69
|
-
updateCaptchaStatus(`Token received: ${procaptchaToken.substring(0, 15)}...`, 'success');
|
|
70
|
-
|
|
71
|
-
const payload = {
|
|
72
|
-
email: document.getElementById('email').value,
|
|
73
|
-
name: document.getElementById('name').value,
|
|
74
|
-
password: document.getElementById('password').value,
|
|
75
|
-
siteKey: import.meta.env.PROSOPO_SITE_KEY_FRICTIONLESS,
|
|
76
|
-
"procaptcha-response": procaptchaToken,
|
|
77
|
-
};
|
|
78
|
-
const url = new URL('signup', import.meta.env.PROSOPO_SERVER_URL).href;
|
|
79
|
-
console.log("posting to", url, "with payload", payload);
|
|
80
|
-
fetch(url, {
|
|
81
|
-
method: "POST",
|
|
82
|
-
headers: {
|
|
83
|
-
"Content-Type": "application/json",
|
|
84
|
-
},
|
|
85
|
-
body: JSON.stringify(payload),
|
|
86
|
-
contentType: "application/json",
|
|
87
|
-
}).then((response) => {
|
|
88
|
-
return new Promise((resolve) => response.json()
|
|
89
|
-
.then((json) => resolve({
|
|
90
|
-
status: response.status,
|
|
91
|
-
ok: response.ok,
|
|
92
|
-
json,
|
|
93
|
-
})))
|
|
94
|
-
})
|
|
95
|
-
.then(async ({status, json, ok}) => {
|
|
96
|
-
console.log("status", status, "json", json.message, "ok", ok);
|
|
97
|
-
console.log("json", json)
|
|
98
|
-
try {
|
|
99
|
-
if (status !== 200) {
|
|
100
|
-
updateCaptchaStatus(`API Error: ${json.message}`, 'error');
|
|
101
|
-
setIsError(true);
|
|
102
|
-
setMessage(json.message);
|
|
103
|
-
} else {
|
|
104
|
-
updateCaptchaStatus(`API Success: ${json.message}`, 'success');
|
|
105
|
-
setIsError(false);
|
|
106
|
-
setMessage(json.message);
|
|
107
|
-
}
|
|
108
|
-
} catch (err) {
|
|
109
|
-
console.log(err);
|
|
110
|
-
updateCaptchaStatus(`Error processing response: ${err}`, 'error');
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
.catch((err) => {
|
|
114
|
-
console.log(err);
|
|
115
|
-
updateCaptchaStatus(`Fetch error: ${err}`, 'error');
|
|
116
|
-
setIsError(true);
|
|
117
|
-
setMessage("Error: " + err);
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
updateCaptchaStatus('Page loaded - Initializing CAPTCHA system', 'info');
|
|
122
|
-
|
|
123
|
-
// Monitor DOM for CAPTCHA initialization
|
|
124
|
-
const observer = new MutationObserver((mutations) => {
|
|
125
|
-
mutations.forEach((mutation) => {
|
|
126
|
-
if (mutation.addedNodes.length) {
|
|
127
|
-
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
128
|
-
const node = mutation.addedNodes[i];
|
|
129
|
-
if (node.classList && (node.classList.contains('procaptcha') ||
|
|
130
|
-
node.querySelector && node.querySelector('.procaptcha'))) {
|
|
131
|
-
updateCaptchaStatus('CAPTCHA DOM elements initialized', 'info');
|
|
132
|
-
observer.disconnect();
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
window.onCaptchaFailed = function () {
|
|
144
|
-
console.log('Challenge failed');
|
|
145
|
-
updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
window.onCaptchaVerified = (output) => {
|
|
149
|
-
console.log('Challenge passed');
|
|
150
|
-
updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
151
|
-
updateCaptchaStatus(`Token generated: ${output.substring(0, 15)}...`, 'success');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Add custom event listener for CAPTCHA verification stages
|
|
155
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
156
|
-
setTimeout(() => {
|
|
157
|
-
updateCaptchaStatus('CAPTCHA script loaded and initialized', 'info');
|
|
158
|
-
updateCaptchaStatus('Waiting for user interaction...', 'info');
|
|
159
|
-
}, 500);
|
|
160
|
-
});
|
|
161
|
-
</script>
|
|
162
|
-
<script id="procaptchaScript" type="module" src="%VITE_BUNDLE_URL%" async defer></script>
|
|
163
|
-
</head>
|
|
164
|
-
<body>
|
|
165
|
-
|
|
166
|
-
<div class="demo-card">
|
|
167
|
-
|
|
168
|
-
<form action="%PROSOPO_SERVER_URL%/signup" method="POST" class="demo-form">
|
|
169
|
-
<h2>Create an account</h2>
|
|
170
|
-
<p class="demo-note">Nothing runs until you tick the box or press <strong>Start CAPTCHA now</strong>, which calls <code>window.procaptcha.start()</code>.</p>
|
|
171
|
-
<div class="demo-field">
|
|
172
|
-
<label for="name">Name</label>
|
|
173
|
-
<input id="name" type="text" name="name" required/>
|
|
174
|
-
</div>
|
|
175
|
-
<div class="demo-field">
|
|
176
|
-
<label for="email">Email Address</label>
|
|
177
|
-
<input id="email" type="email" name="email" required/>
|
|
178
|
-
</div>
|
|
179
|
-
<div class="demo-field">
|
|
180
|
-
<label for="password">Password</label>
|
|
181
|
-
<input id="password" type="password" name="password" required/>
|
|
182
|
-
</div>
|
|
183
|
-
<div class="demo-field">
|
|
184
|
-
<div
|
|
185
|
-
class="procaptcha"
|
|
186
|
-
data-theme="light"
|
|
187
|
-
data-sitekey="%PROSOPO_SITE_KEY_FRICTIONLESS%"
|
|
188
|
-
data-start-mode="manual"
|
|
189
|
-
data-failed-callback="onCaptchaFailed"
|
|
190
|
-
data-callback="onCaptchaVerified"
|
|
191
|
-
></div>
|
|
192
|
-
</div>
|
|
193
|
-
<div class="demo-field">
|
|
194
|
-
<button type="button" class="demo-button demo-button--secondary" onclick="onStartCaptcha()" data-cy="start-captcha-button">
|
|
195
|
-
Start CAPTCHA now
|
|
196
|
-
</button>
|
|
197
|
-
</div>
|
|
198
|
-
<div id="messageContainer" style="display: none; color: black;"><span id="message"></span></div>
|
|
199
|
-
<button type="button" class="demo-button" onclick="onActionHandler()" data-cy="submit-button">Submit</button>
|
|
200
|
-
</form>
|
|
201
|
-
|
|
202
|
-
</div>
|
|
203
|
-
</body>
|
|
204
|
-
</html>
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Image, explicit rendering, web3</title>
|
|
6
|
-
<script type="module">
|
|
7
|
-
|
|
8
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
9
|
-
updateCaptchaStatus('Page loaded - Initializing CAPTCHA system', 'info');
|
|
10
|
-
|
|
11
|
-
// Monitor DOM for CAPTCHA initialization
|
|
12
|
-
const observer = new MutationObserver((mutations) => {
|
|
13
|
-
mutations.forEach((mutation) => {
|
|
14
|
-
if (mutation.addedNodes.length) {
|
|
15
|
-
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
16
|
-
const node = mutation.addedNodes[i];
|
|
17
|
-
if (node.classList && (node.classList.contains('procaptcha') ||
|
|
18
|
-
node.querySelector && node.querySelector('.procaptcha'))) {
|
|
19
|
-
updateCaptchaStatus('CAPTCHA DOM elements initialized', 'info');
|
|
20
|
-
observer.disconnect();
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
</script>
|
|
32
|
-
</head>
|
|
33
|
-
<body>
|
|
34
|
-
<div class="demo-card">
|
|
35
|
-
|
|
36
|
-
<form id="demo-form" class="demo-form">
|
|
37
|
-
<h2>Create an account</h2>
|
|
38
|
-
|
|
39
|
-
<div class="demo-field">
|
|
40
|
-
<label for="name">Name</label>
|
|
41
|
-
<input type="text" id="name" name="name" required />
|
|
42
|
-
</div>
|
|
43
|
-
|
|
44
|
-
<div class="demo-field">
|
|
45
|
-
<label for="email">Email</label>
|
|
46
|
-
<input type="email" id="email" name="email" required />
|
|
47
|
-
</div>
|
|
48
|
-
|
|
49
|
-
<div id="procaptcha-container"></div>
|
|
50
|
-
|
|
51
|
-
<button type="submit" class="demo-button">Submit</button>
|
|
52
|
-
|
|
53
|
-
<div id="error"></div>
|
|
54
|
-
</form>
|
|
55
|
-
|
|
56
|
-
<div id="result" class="demo-result" style="display: none;"></div>
|
|
57
|
-
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<script type="module">
|
|
61
|
-
import { render } from "%VITE_BUNDLE_URL%"
|
|
62
|
-
import { web3AccountsSubscribe, web3Enable } from "@polkadot/extension-dapp";
|
|
63
|
-
|
|
64
|
-
// Form validation function
|
|
65
|
-
function validateForm() {
|
|
66
|
-
const nameInput = document.getElementById('name');
|
|
67
|
-
const emailInput = document.getElementById('email');
|
|
68
|
-
const errorDisplay = document.getElementById('error');
|
|
69
|
-
|
|
70
|
-
if (!nameInput.value || !emailInput.value) {
|
|
71
|
-
errorDisplay.textContent = 'Please fill out all fields';
|
|
72
|
-
errorDisplay.style.display = 'block';
|
|
73
|
-
window.updateCaptchaStatus('Form validation failed: Empty fields', 'error');
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Basic email validation
|
|
78
|
-
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
79
|
-
if (!emailPattern.test(emailInput.value)) {
|
|
80
|
-
errorDisplay.textContent = 'Please enter a valid email address';
|
|
81
|
-
errorDisplay.style.display = 'block';
|
|
82
|
-
window.updateCaptchaStatus('Form validation failed: Invalid email format', 'error');
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
errorDisplay.style.display = 'none';
|
|
87
|
-
window.updateCaptchaStatus('Form validation passed', 'info');
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Callback for successful CAPTCHA verification
|
|
92
|
-
function handleCaptchaResponse(token) {
|
|
93
|
-
console.log('Procaptcha verified, token:', token);
|
|
94
|
-
window.updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
95
|
-
window.updateCaptchaStatus(`Token generated: ${token.substring(0, 15)}...`, 'success');
|
|
96
|
-
|
|
97
|
-
const name = document.getElementById('name').value;
|
|
98
|
-
const email = document.getElementById('email').value;
|
|
99
|
-
|
|
100
|
-
// Display result
|
|
101
|
-
const resultElement = document.getElementById('result');
|
|
102
|
-
resultElement.innerHTML = `<strong>Form submitted with:</strong><br>
|
|
103
|
-
- Name: ${name}<br>
|
|
104
|
-
- Email: ${email}<br>
|
|
105
|
-
- Procaptcha verified: Yes`;
|
|
106
|
-
resultElement.style.display = 'block';
|
|
107
|
-
|
|
108
|
-
window.updateCaptchaStatus('Form submission completed', 'success');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Callback for failed CAPTCHA verification
|
|
112
|
-
function handleCaptchaFailed() {
|
|
113
|
-
console.log('Captcha verification failed');
|
|
114
|
-
window.updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
115
|
-
document.getElementById('error').textContent = 'CAPTCHA verification failed. Please try again.';
|
|
116
|
-
document.getElementById('error').style.display = 'block';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Get web3 accounts and create select element
|
|
120
|
-
async function getWeb3Accounts() {
|
|
121
|
-
return new Promise((resolve) =>{ web3AccountsSubscribe((accounts) => {
|
|
122
|
-
if (accounts.length === 0) {
|
|
123
|
-
window.updateCaptchaStatus('No accounts found. Please connect your wallet.', 'error');
|
|
124
|
-
} else {
|
|
125
|
-
window.updateCaptchaStatus(`Connected to ${accounts.length} account(s).`, 'info');
|
|
126
|
-
// render a modal and get the user to select 1 account
|
|
127
|
-
const accountSelect = document.createElement('select');
|
|
128
|
-
accountSelect.id = 'account-select';
|
|
129
|
-
accountSelect.classList.add('account-select');
|
|
130
|
-
accounts.forEach((account) => {
|
|
131
|
-
const option = document.createElement('option');
|
|
132
|
-
option.value = account.address;
|
|
133
|
-
option.textContent = `${account.meta.name} (${account.address})`;
|
|
134
|
-
accountSelect.appendChild(option);
|
|
135
|
-
});
|
|
136
|
-
const accountContainer = document.createElement('div');
|
|
137
|
-
accountContainer.innerHTML = '<label for="account-select"><h2>Select Account:</h2></label>';
|
|
138
|
-
accountContainer.appendChild(accountSelect);
|
|
139
|
-
document.getElementById('demo-form').prepend(accountContainer);
|
|
140
|
-
window.updateCaptchaStatus('Accounts loaded successfully', 'info');
|
|
141
|
-
}
|
|
142
|
-
resolve(accounts);
|
|
143
|
-
})});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Wait for DOM content to be loaded
|
|
147
|
-
document.addEventListener('DOMContentLoaded', async function() {
|
|
148
|
-
window.updateCaptchaStatus('Initializing CAPTCHA with explicit render call', 'info');
|
|
149
|
-
|
|
150
|
-
await web3Enable("Procaptcha Demo");
|
|
151
|
-
|
|
152
|
-
await getWeb3Accounts();
|
|
153
|
-
|
|
154
|
-
// Get the selected account from the dropdown
|
|
155
|
-
const account = document.getElementById('account-select') ? document.getElementById('account-select').value : null;
|
|
156
|
-
window.updateCaptchaStatus(`Rendering the CAPTCHA for account ${account}`, 'info'); window.updateCaptchaStatus(`Rendering the CAPTCHA for account ${account}`, 'info');
|
|
157
|
-
|
|
158
|
-
// Render the CAPTCHA
|
|
159
|
-
|
|
160
|
-
const widgetId = await render(document.getElementById('procaptcha-container'), {
|
|
161
|
-
siteKey: import.meta.env.PROSOPO_SITE_KEY_IMAGE,
|
|
162
|
-
callback: handleCaptchaResponse,
|
|
163
|
-
"failed-callback": handleCaptchaFailed,
|
|
164
|
-
web3:true,
|
|
165
|
-
userAccountAddress: account
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
window.updateCaptchaStatus('CAPTCHA render function called with widget ID: ' + widgetId, 'info');
|
|
169
|
-
|
|
170
|
-
// Add form submit handler
|
|
171
|
-
document.getElementById('demo-form').addEventListener('submit', function(e) {
|
|
172
|
-
e.preventDefault();
|
|
173
|
-
window.updateCaptchaStatus('Form submission attempted', 'info');
|
|
174
|
-
if (validateForm()) {
|
|
175
|
-
// Form is valid, CAPTCHA verification will be handled by the callback
|
|
176
|
-
window.updateCaptchaStatus('Waiting for CAPTCHA verification', 'info');
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
</script>
|
|
181
|
-
</body>
|
|
182
|
-
</html>
|
package/src/image-explicit.html
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Image, explicit rendering</title>
|
|
6
|
-
<script type="module">
|
|
7
|
-
|
|
8
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
9
|
-
updateCaptchaStatus('Page loaded - Initializing CAPTCHA system', 'info');
|
|
10
|
-
|
|
11
|
-
// Monitor DOM for CAPTCHA initialization
|
|
12
|
-
const observer = new MutationObserver((mutations) => {
|
|
13
|
-
mutations.forEach((mutation) => {
|
|
14
|
-
if (mutation.addedNodes.length) {
|
|
15
|
-
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
16
|
-
const node = mutation.addedNodes[i];
|
|
17
|
-
if (node.classList && (node.classList.contains('procaptcha') ||
|
|
18
|
-
node.querySelector && node.querySelector('.procaptcha'))) {
|
|
19
|
-
updateCaptchaStatus('CAPTCHA DOM elements initialized', 'info');
|
|
20
|
-
observer.disconnect();
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
</script>
|
|
32
|
-
</head>
|
|
33
|
-
<body>
|
|
34
|
-
<div class="demo-card">
|
|
35
|
-
|
|
36
|
-
<form id="demo-form" class="demo-form">
|
|
37
|
-
<h2>Create an account</h2>
|
|
38
|
-
|
|
39
|
-
<div class="demo-field">
|
|
40
|
-
<label for="name">Name</label>
|
|
41
|
-
<input type="text" id="name" name="name" required />
|
|
42
|
-
</div>
|
|
43
|
-
|
|
44
|
-
<div class="demo-field">
|
|
45
|
-
<label for="email">Email</label>
|
|
46
|
-
<input type="email" id="email" name="email" required />
|
|
47
|
-
</div>
|
|
48
|
-
|
|
49
|
-
<div id="procaptcha-container"></div>
|
|
50
|
-
|
|
51
|
-
<button type="submit" class="demo-button">Submit</button>
|
|
52
|
-
|
|
53
|
-
<div id="error"></div>
|
|
54
|
-
</form>
|
|
55
|
-
|
|
56
|
-
<div id="result" class="demo-result" style="display: none;"></div>
|
|
57
|
-
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<script type="module">
|
|
61
|
-
import { render } from "%VITE_BUNDLE_URL%"
|
|
62
|
-
|
|
63
|
-
// Form validation function
|
|
64
|
-
function validateForm() {
|
|
65
|
-
const nameInput = document.getElementById('name');
|
|
66
|
-
const emailInput = document.getElementById('email');
|
|
67
|
-
const errorDisplay = document.getElementById('error');
|
|
68
|
-
|
|
69
|
-
if (!nameInput.value || !emailInput.value) {
|
|
70
|
-
errorDisplay.textContent = 'Please fill out all fields';
|
|
71
|
-
errorDisplay.style.display = 'block';
|
|
72
|
-
window.updateCaptchaStatus('Form validation failed: Empty fields', 'error');
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Basic email validation
|
|
77
|
-
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
78
|
-
if (!emailPattern.test(emailInput.value)) {
|
|
79
|
-
errorDisplay.textContent = 'Please enter a valid email address';
|
|
80
|
-
errorDisplay.style.display = 'block';
|
|
81
|
-
window.updateCaptchaStatus('Form validation failed: Invalid email format', 'error');
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
errorDisplay.style.display = 'none';
|
|
86
|
-
window.updateCaptchaStatus('Form validation passed', 'info');
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Callback for successful CAPTCHA verification
|
|
91
|
-
function handleCaptchaResponse(token) {
|
|
92
|
-
console.log('Procaptcha verified, token:', token);
|
|
93
|
-
window.updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
94
|
-
window.updateCaptchaStatus(`Token generated: ${token.substring(0, 15)}...`, 'success');
|
|
95
|
-
|
|
96
|
-
const name = document.getElementById('name').value;
|
|
97
|
-
const email = document.getElementById('email').value;
|
|
98
|
-
|
|
99
|
-
// Display result
|
|
100
|
-
const resultElement = document.getElementById('result');
|
|
101
|
-
resultElement.innerHTML = `<strong>Form submitted with:</strong><br>
|
|
102
|
-
- Name: ${name}<br>
|
|
103
|
-
- Email: ${email}<br>
|
|
104
|
-
- Procaptcha verified: Yes`;
|
|
105
|
-
resultElement.style.display = 'block';
|
|
106
|
-
|
|
107
|
-
window.updateCaptchaStatus('Form submission completed', 'success');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Callback for failed CAPTCHA verification
|
|
111
|
-
function handleCaptchaFailed() {
|
|
112
|
-
console.log('Captcha verification failed');
|
|
113
|
-
window.updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
114
|
-
document.getElementById('error').textContent = 'CAPTCHA verification failed. Please try again.';
|
|
115
|
-
document.getElementById('error').style.display = 'block';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Wait for DOM content to be loaded
|
|
119
|
-
document.addEventListener('DOMContentLoaded', async function() {
|
|
120
|
-
window.updateCaptchaStatus('Initializing CAPTCHA with explicit render call', 'info');
|
|
121
|
-
|
|
122
|
-
// Render the CAPTCHA
|
|
123
|
-
// ?placement=float anchors the challenge to the widget; the default is popup.
|
|
124
|
-
const placement =
|
|
125
|
-
new URLSearchParams(window.location.search).get("placement") === "float"
|
|
126
|
-
? "float"
|
|
127
|
-
: "popup";
|
|
128
|
-
window.updateCaptchaStatus('Challenge placement: ' + placement, 'info');
|
|
129
|
-
|
|
130
|
-
const widgetId = await render(document.getElementById('procaptcha-container'), {
|
|
131
|
-
siteKey: import.meta.env.PROSOPO_SITE_KEY_IMAGE,
|
|
132
|
-
placement,
|
|
133
|
-
callback: handleCaptchaResponse,
|
|
134
|
-
"failed-callback": handleCaptchaFailed
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
window.updateCaptchaStatus('CAPTCHA render function called with widget ID: ' + widgetId, 'info');
|
|
138
|
-
|
|
139
|
-
// Add form submit handler
|
|
140
|
-
document.getElementById('demo-form').addEventListener('submit', function(e) {
|
|
141
|
-
e.preventDefault();
|
|
142
|
-
window.updateCaptchaStatus('Form submission attempted', 'info');
|
|
143
|
-
if (validateForm()) {
|
|
144
|
-
// Form is valid, CAPTCHA verification will be handled by the callback
|
|
145
|
-
window.updateCaptchaStatus('Waiting for CAPTCHA verification', 'info');
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
</script>
|
|
150
|
-
</body>
|
|
151
|
-
</html>
|