@prosopo/client-bundle-example 2.11.3 → 2.11.5
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 +3 -6
- package/.turbo/turbo-build$colon$tsc.log +11 -14
- package/.turbo/turbo-build.log +4 -10
- package/CHANGELOG.md +32 -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 +53 -53
- package/vite.config.ts +52 -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
package/src/pow-implicit.html
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Proof of Work, implicit rendering</title>
|
|
6
|
-
<script type="module">
|
|
7
|
-
|
|
8
|
-
window.addEventListener('load', () => {
|
|
9
|
-
|
|
10
|
-
window.setIsError = (isError) => {
|
|
11
|
-
const messageContainer = document.getElementById('messageContainer');
|
|
12
|
-
messageContainer.style.color = isError ? 'red' : 'black';
|
|
13
|
-
messageContainer.style.display = 'block';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
window.setMessage = (message) => {
|
|
17
|
-
document.getElementById('message').innerText = message;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
window.onLoggedIn = (token) => {
|
|
21
|
-
updateCaptchaStatus('Logged in, fetching private resource', 'info');
|
|
22
|
-
const url = new URL("/private", config.serverUrl).href;
|
|
23
|
-
console.log("getting private resource with token ", token, "at", url);
|
|
24
|
-
fetch(url, {
|
|
25
|
-
method: "GET",
|
|
26
|
-
headers: {
|
|
27
|
-
Origin: "http://localhost:9232", // TODO: change this to env var
|
|
28
|
-
"Content-Type": "application/json",
|
|
29
|
-
Authorization: `Bearer ${token}`,
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
.then(async (res) => {
|
|
33
|
-
try {
|
|
34
|
-
const jsonRes = await res.json();
|
|
35
|
-
if (res.status === 200) {
|
|
36
|
-
updateCaptchaStatus(`Successfully accessed private resource`, 'success');
|
|
37
|
-
setMessage(jsonRes.message);
|
|
38
|
-
} else {
|
|
39
|
-
updateCaptchaStatus(`Failed to access private resource: ${res.status}`, 'error');
|
|
40
|
-
}
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.log(err);
|
|
43
|
-
updateCaptchaStatus(`Error parsing response: ${err}`, 'error');
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.catch((err) => {
|
|
47
|
-
console.log(err);
|
|
48
|
-
updateCaptchaStatus(`Fetch error: ${err}`, 'error');
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
window.onActionHandler = () => {
|
|
53
|
-
updateCaptchaStatus('Form submission initiated', 'info');
|
|
54
|
-
|
|
55
|
-
const procaptchaElements = document.getElementsByName('procaptcha-response');
|
|
56
|
-
|
|
57
|
-
if (!procaptchaElements.length) {
|
|
58
|
-
updateCaptchaStatus('Error: No CAPTCHA response found', 'error');
|
|
59
|
-
alert("Must complete captcha");
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const procaptchaToken = procaptchaElements[0].value;
|
|
64
|
-
updateCaptchaStatus(`Token received: ${procaptchaToken.substring(0, 15)}...`, 'success');
|
|
65
|
-
|
|
66
|
-
const payload = {
|
|
67
|
-
email: document.getElementById('email').value,
|
|
68
|
-
name: document.getElementById('name').value,
|
|
69
|
-
password: document.getElementById('password').value,
|
|
70
|
-
siteKey: import.meta.env.PROSOPO_SITE_KEY_POW,
|
|
71
|
-
"procaptcha-response": procaptchaToken,
|
|
72
|
-
};
|
|
73
|
-
const url = new URL('signup', import.meta.env.PROSOPO_SERVER_URL).href;
|
|
74
|
-
console.log("posting to", url, "with payload", payload);
|
|
75
|
-
fetch(url, {
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: {
|
|
78
|
-
"Content-Type": "application/json",
|
|
79
|
-
},
|
|
80
|
-
body: JSON.stringify(payload),
|
|
81
|
-
contentType: "application/json",
|
|
82
|
-
}).then((response) => {
|
|
83
|
-
return new Promise((resolve) => response.json()
|
|
84
|
-
.then((json) => resolve({
|
|
85
|
-
status: response.status,
|
|
86
|
-
ok: response.ok,
|
|
87
|
-
json,
|
|
88
|
-
})))
|
|
89
|
-
})
|
|
90
|
-
.then(async ({status, json, ok}) => {
|
|
91
|
-
console.log("status", status, "json", json.message, "ok", ok);
|
|
92
|
-
console.log("json", json)
|
|
93
|
-
try {
|
|
94
|
-
if (status !== 200) {
|
|
95
|
-
updateCaptchaStatus(`API Error: ${json.message}`, 'error');
|
|
96
|
-
setIsError(true);
|
|
97
|
-
setMessage(json.message);
|
|
98
|
-
} else {
|
|
99
|
-
updateCaptchaStatus(`API Success: ${json.message}`, 'success');
|
|
100
|
-
setIsError(false);
|
|
101
|
-
setMessage(json.message);
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
console.log(err);
|
|
105
|
-
updateCaptchaStatus(`Error processing response: ${err}`, 'error');
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
.catch((err) => {
|
|
109
|
-
console.log(err);
|
|
110
|
-
updateCaptchaStatus(`Fetch error: ${err}`, 'error');
|
|
111
|
-
setIsError(true);
|
|
112
|
-
setMessage("Error: " + err);
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
updateCaptchaStatus('Page loaded - Initializing CAPTCHA system', 'info');
|
|
117
|
-
|
|
118
|
-
// Monitor DOM for CAPTCHA initialization
|
|
119
|
-
const observer = new MutationObserver((mutations) => {
|
|
120
|
-
mutations.forEach((mutation) => {
|
|
121
|
-
if (mutation.addedNodes.length) {
|
|
122
|
-
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
123
|
-
const node = mutation.addedNodes[i];
|
|
124
|
-
if (node.classList && (node.classList.contains('procaptcha') ||
|
|
125
|
-
node.querySelector && node.querySelector('.procaptcha'))) {
|
|
126
|
-
updateCaptchaStatus('CAPTCHA DOM elements initialized', 'info');
|
|
127
|
-
observer.disconnect();
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
window.onCaptchaFailed = function () {
|
|
139
|
-
console.log('Challenge failed');
|
|
140
|
-
updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
window.onCaptchaVerified = (output) => {
|
|
144
|
-
console.log('Challenge passed');
|
|
145
|
-
updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
146
|
-
updateCaptchaStatus(`Token generated: ${output.substring(0, 15)}...`, 'success');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Add custom event listener for CAPTCHA verification stages
|
|
150
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
151
|
-
setTimeout(() => {
|
|
152
|
-
updateCaptchaStatus('CAPTCHA script loaded and initialized', 'info');
|
|
153
|
-
updateCaptchaStatus('Waiting for user interaction...', 'info');
|
|
154
|
-
}, 500);
|
|
155
|
-
});
|
|
156
|
-
</script>
|
|
157
|
-
<script id="procaptchaScript" type="module" src="%VITE_BUNDLE_URL%" async defer></script>
|
|
158
|
-
</head>
|
|
159
|
-
<body>
|
|
160
|
-
|
|
161
|
-
<div class="demo-card">
|
|
162
|
-
|
|
163
|
-
<form action="%PROSOPO_SERVER_URL%/signup" method="POST" class="demo-form">
|
|
164
|
-
<h2>Create an account</h2>
|
|
165
|
-
<div class="demo-field">
|
|
166
|
-
<label for="name">Name</label>
|
|
167
|
-
<input id="name" type="text" name="name" required/>
|
|
168
|
-
</div>
|
|
169
|
-
<div class="demo-field">
|
|
170
|
-
<label for="email">Email Address</label>
|
|
171
|
-
<input id="email" type="email" name="email" required/>
|
|
172
|
-
</div>
|
|
173
|
-
<div class="demo-field">
|
|
174
|
-
<label for="password">Password</label>
|
|
175
|
-
<input id="password" type="password" name="password" required/>
|
|
176
|
-
</div>
|
|
177
|
-
<div class="demo-field">
|
|
178
|
-
<div
|
|
179
|
-
class="procaptcha"
|
|
180
|
-
data-theme="light"
|
|
181
|
-
data-sitekey="%PROSOPO_SITE_KEY_POW%"
|
|
182
|
-
data-failed-callback="onCaptchaFailed"
|
|
183
|
-
data-callback="onCaptchaVerified"
|
|
184
|
-
></div>
|
|
185
|
-
</div>
|
|
186
|
-
<div id="messageContainer" style="display: none; color: black;"><span id="message"></span></div>
|
|
187
|
-
<button type="button" class="demo-button" onclick="onActionHandler()" data-cy="submit-button">Submit</button>
|
|
188
|
-
</form>
|
|
189
|
-
|
|
190
|
-
</div>
|
|
191
|
-
</body>
|
|
192
|
-
</html>
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Puzzle, bound button</title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<div class="demo-card">
|
|
9
|
-
|
|
10
|
-
<form id="demo-form" class="demo-form">
|
|
11
|
-
<h2>Create an account</h2>
|
|
12
|
-
<p class="demo-note">The widget is bound to the submit button, so pressing it opens the challenge.</p>
|
|
13
|
-
|
|
14
|
-
<div class="demo-field">
|
|
15
|
-
<label for="name">Name</label>
|
|
16
|
-
<input type="text" id="name" name="name" required />
|
|
17
|
-
</div>
|
|
18
|
-
|
|
19
|
-
<div class="demo-field">
|
|
20
|
-
<label for="email">Email</label>
|
|
21
|
-
<input type="email" id="email" name="email" required />
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
<div id="procaptcha-container"></div>
|
|
25
|
-
|
|
26
|
-
<button type="submit" id="verify-btn" class="demo-button">Verify & submit</button>
|
|
27
|
-
|
|
28
|
-
<div id="error"></div>
|
|
29
|
-
</form>
|
|
30
|
-
|
|
31
|
-
<div id="result" class="demo-result" style="display: none;"></div>
|
|
32
|
-
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<script type="module">
|
|
36
|
-
import { render } from "%VITE_BUNDLE_URL%"
|
|
37
|
-
|
|
38
|
-
function handleCaptchaResponse(token) {
|
|
39
|
-
window.updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
40
|
-
window.updateCaptchaStatus(`Token generated: ${token.substring(0, 15)}...`, 'success');
|
|
41
|
-
|
|
42
|
-
const resultElement = document.getElementById('result');
|
|
43
|
-
resultElement.replaceChildren();
|
|
44
|
-
const heading = document.createElement('strong');
|
|
45
|
-
heading.textContent = 'Form submitted with:';
|
|
46
|
-
resultElement.append(heading);
|
|
47
|
-
for (const line of [
|
|
48
|
-
`- Name: ${document.getElementById('name').value}`,
|
|
49
|
-
`- Email: ${document.getElementById('email').value}`,
|
|
50
|
-
'- Procaptcha verified: Yes',
|
|
51
|
-
]) {
|
|
52
|
-
resultElement.append(document.createElement('br'), document.createTextNode(line));
|
|
53
|
-
}
|
|
54
|
-
resultElement.style.display = 'block';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function handleCaptchaFailed() {
|
|
58
|
-
window.updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
59
|
-
document.getElementById('error').textContent = 'CAPTCHA verification failed. Please try again.';
|
|
60
|
-
document.getElementById('error').style.display = 'block';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
document.addEventListener('DOMContentLoaded', async function() {
|
|
64
|
-
// ?placement=float anchors the challenge to the widget; the default is popup.
|
|
65
|
-
const placement =
|
|
66
|
-
new URLSearchParams(window.location.search).get("placement") === "float"
|
|
67
|
-
? "float"
|
|
68
|
-
: "popup";
|
|
69
|
-
window.updateCaptchaStatus('Challenge placement: ' + placement, 'info');
|
|
70
|
-
|
|
71
|
-
const widgetId = await render(document.getElementById('procaptcha-container'), {
|
|
72
|
-
siteKey: import.meta.env.PROSOPO_SITE_KEY_PUZZLE,
|
|
73
|
-
placement,
|
|
74
|
-
bind: "#verify-btn",
|
|
75
|
-
callback: handleCaptchaResponse,
|
|
76
|
-
"failed-callback": handleCaptchaFailed
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
window.updateCaptchaStatus('Widget ' + widgetId + ' bound to #verify-btn', 'info');
|
|
80
|
-
});
|
|
81
|
-
</script>
|
|
82
|
-
</body>
|
|
83
|
-
</html>
|
package/src/puzzle-explicit.html
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Puzzle, 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_PUZZLE,
|
|
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>
|
package/src/puzzle-implicit.html
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Procaptcha demo: Puzzle, implicit rendering</title>
|
|
6
|
-
<script type="module">
|
|
7
|
-
|
|
8
|
-
window.addEventListener('load', () => {
|
|
9
|
-
|
|
10
|
-
window.setIsError = (isError) => {
|
|
11
|
-
const messageContainer = document.getElementById('messageContainer');
|
|
12
|
-
messageContainer.style.color = isError ? 'red' : 'black';
|
|
13
|
-
messageContainer.style.display = 'block';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
window.setMessage = (message) => {
|
|
17
|
-
document.getElementById('message').innerText = message;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
window.onLoggedIn = (token) => {
|
|
21
|
-
updateCaptchaStatus('Logged in, fetching private resource', 'info');
|
|
22
|
-
const url = new URL("/private", config.serverUrl).href;
|
|
23
|
-
console.log("getting private resource with token ", token, "at", url);
|
|
24
|
-
fetch(url, {
|
|
25
|
-
method: "GET",
|
|
26
|
-
headers: {
|
|
27
|
-
Origin: "http://localhost:9232", // TODO: change this to env var
|
|
28
|
-
"Content-Type": "application/json",
|
|
29
|
-
Authorization: `Bearer ${token}`,
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
.then(async (res) => {
|
|
33
|
-
try {
|
|
34
|
-
const jsonRes = await res.json();
|
|
35
|
-
if (res.status === 200) {
|
|
36
|
-
updateCaptchaStatus(`Successfully accessed private resource`, 'success');
|
|
37
|
-
setMessage(jsonRes.message);
|
|
38
|
-
} else {
|
|
39
|
-
updateCaptchaStatus(`Failed to access private resource: ${res.status}`, 'error');
|
|
40
|
-
}
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.log(err);
|
|
43
|
-
updateCaptchaStatus(`Error parsing response: ${err}`, 'error');
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.catch((err) => {
|
|
47
|
-
console.log(err);
|
|
48
|
-
updateCaptchaStatus(`Fetch error: ${err}`, 'error');
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
window.onActionHandler = () => {
|
|
53
|
-
updateCaptchaStatus('Form submission initiated', 'info');
|
|
54
|
-
|
|
55
|
-
const procaptchaElements = document.getElementsByName('procaptcha-response');
|
|
56
|
-
|
|
57
|
-
if (!procaptchaElements.length) {
|
|
58
|
-
updateCaptchaStatus('Error: No CAPTCHA response found', 'error');
|
|
59
|
-
alert("Must complete captcha");
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const procaptchaToken = procaptchaElements[0].value;
|
|
64
|
-
updateCaptchaStatus(`Token received: ${procaptchaToken.substring(0, 15)}...`, 'success');
|
|
65
|
-
|
|
66
|
-
const payload = {
|
|
67
|
-
email: document.getElementById('email').value,
|
|
68
|
-
name: document.getElementById('name').value,
|
|
69
|
-
password: document.getElementById('password').value,
|
|
70
|
-
siteKey: import.meta.env.PROSOPO_SITE_KEY_PUZZLE,
|
|
71
|
-
"procaptcha-response": procaptchaToken,
|
|
72
|
-
};
|
|
73
|
-
const url = new URL('signup', import.meta.env.PROSOPO_SERVER_URL).href;
|
|
74
|
-
console.log("posting to", url, "with payload", payload);
|
|
75
|
-
fetch(url, {
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: {
|
|
78
|
-
"Content-Type": "application/json",
|
|
79
|
-
},
|
|
80
|
-
body: JSON.stringify(payload),
|
|
81
|
-
contentType: "application/json",
|
|
82
|
-
}).then((response) => {
|
|
83
|
-
return new Promise((resolve) => response.json()
|
|
84
|
-
.then((json) => resolve({
|
|
85
|
-
status: response.status,
|
|
86
|
-
ok: response.ok,
|
|
87
|
-
json,
|
|
88
|
-
})))
|
|
89
|
-
})
|
|
90
|
-
.then(async ({status, json, ok}) => {
|
|
91
|
-
console.log("status", status, "json", json.message, "ok", ok);
|
|
92
|
-
console.log("json", json)
|
|
93
|
-
try {
|
|
94
|
-
if (status !== 200) {
|
|
95
|
-
updateCaptchaStatus(`API Error: ${json.message}`, 'error');
|
|
96
|
-
setIsError(true);
|
|
97
|
-
setMessage(json.message);
|
|
98
|
-
} else {
|
|
99
|
-
updateCaptchaStatus(`API Success: ${json.message}`, 'success');
|
|
100
|
-
setIsError(false);
|
|
101
|
-
setMessage(json.message);
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
console.log(err);
|
|
105
|
-
updateCaptchaStatus(`Error processing response: ${err}`, 'error');
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
.catch((err) => {
|
|
109
|
-
console.log(err);
|
|
110
|
-
updateCaptchaStatus(`Fetch error: ${err}`, 'error');
|
|
111
|
-
setIsError(true);
|
|
112
|
-
setMessage("Error: " + err);
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
updateCaptchaStatus('Page loaded - Initializing CAPTCHA system', 'info');
|
|
117
|
-
|
|
118
|
-
// Monitor DOM for CAPTCHA initialization
|
|
119
|
-
const observer = new MutationObserver((mutations) => {
|
|
120
|
-
mutations.forEach((mutation) => {
|
|
121
|
-
if (mutation.addedNodes.length) {
|
|
122
|
-
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
123
|
-
const node = mutation.addedNodes[i];
|
|
124
|
-
if (node.classList && (node.classList.contains('procaptcha') ||
|
|
125
|
-
node.querySelector && node.querySelector('.procaptcha'))) {
|
|
126
|
-
updateCaptchaStatus('CAPTCHA DOM elements initialized', 'info');
|
|
127
|
-
observer.disconnect();
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
observer.observe(document.body, { childList: true, subtree: true });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
window.onCaptchaFailed = function () {
|
|
139
|
-
console.log('Challenge failed');
|
|
140
|
-
updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
window.onCaptchaVerified = (output) => {
|
|
144
|
-
console.log('Challenge passed');
|
|
145
|
-
updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
146
|
-
updateCaptchaStatus(`Token generated: ${output.substring(0, 15)}...`, 'success');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Add custom event listener for CAPTCHA verification stages
|
|
150
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
151
|
-
setTimeout(() => {
|
|
152
|
-
updateCaptchaStatus('CAPTCHA script loaded and initialized', 'info');
|
|
153
|
-
updateCaptchaStatus('Waiting for user interaction...', 'info');
|
|
154
|
-
}, 500);
|
|
155
|
-
});
|
|
156
|
-
</script>
|
|
157
|
-
<script id="procaptchaScript" type="module" src="%VITE_BUNDLE_URL%" async defer></script>
|
|
158
|
-
</head>
|
|
159
|
-
<body>
|
|
160
|
-
|
|
161
|
-
<div class="demo-card">
|
|
162
|
-
|
|
163
|
-
<form action="%PROSOPO_SERVER_URL%/signup" method="POST" class="demo-form">
|
|
164
|
-
<h2>Create an account</h2>
|
|
165
|
-
<div class="demo-field">
|
|
166
|
-
<label for="name">Name</label>
|
|
167
|
-
<input id="name" type="text" name="name" required/>
|
|
168
|
-
</div>
|
|
169
|
-
<div class="demo-field">
|
|
170
|
-
<label for="email">Email Address</label>
|
|
171
|
-
<input id="email" type="email" name="email" required/>
|
|
172
|
-
</div>
|
|
173
|
-
<div class="demo-field">
|
|
174
|
-
<label for="password">Password</label>
|
|
175
|
-
<input id="password" type="password" name="password" required/>
|
|
176
|
-
</div>
|
|
177
|
-
<div class="demo-field">
|
|
178
|
-
<div
|
|
179
|
-
class="procaptcha"
|
|
180
|
-
data-theme="light"
|
|
181
|
-
data-sitekey="%PROSOPO_SITE_KEY_PUZZLE%"
|
|
182
|
-
data-failed-callback="onCaptchaFailed"
|
|
183
|
-
data-callback="onCaptchaVerified"
|
|
184
|
-
></div>
|
|
185
|
-
</div>
|
|
186
|
-
<div id="messageContainer" style="display: none; color: black;"><span id="message"></span></div>
|
|
187
|
-
<button type="button" class="demo-button" onclick="onActionHandler()" data-cy="submit-button">Submit</button>
|
|
188
|
-
</form>
|
|
189
|
-
|
|
190
|
-
</div>
|
|
191
|
-
</body>
|
|
192
|
-
</html>
|