@prosopo/client-bundle-example 2.10.12 → 2.10.18
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 +6 -6
- package/.turbo/turbo-build$colon$tsc.log +14 -14
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +46 -0
- package/README.md +3 -1
- package/env.development +7 -0
- package/env.production +6 -0
- package/env.staging +2 -2
- package/package.json +10 -5
- package/src/assets/dummy.txt +0 -0
- package/src/frictionless-explicit-web3.html +249 -0
- package/src/frictionless-explicit.html +208 -0
- package/src/frictionless-implicit.html +218 -0
- package/src/image-explicit-web3.html +198 -0
- package/src/image-explicit.html +158 -0
- package/src/index.html +207 -0
- package/src/index.ts +76 -0
- package/src/invisible-frictionless-explicit.html +132 -0
- package/src/invisible-frictionless-implicit.html +204 -0
- package/src/invisible-image-explicit.html +161 -0
- package/src/invisible-image-implicit.html +203 -0
- package/src/invisible-pow-explicit.html +161 -0
- package/src/invisible-pow-implicit.html +106 -0
- package/src/invisible-puzzle-explicit.html +160 -0
- package/src/invisible-puzzle-implicit.html +106 -0
- package/src/plugins/explanation-injector.ts +294 -0
- package/src/plugins/form-filler-injector.ts +233 -0
- package/src/plugins/navigation-injector.ts +602 -0
- package/src/plugins/status-log-injector.ts +199 -0
- package/src/pow-explicit-web3.html +195 -0
- package/src/pow-explicit.html +158 -0
- package/src/pow-implicit.html +207 -0
- package/src/puzzle-explicit.html +158 -0
- package/src/puzzle-implicit.html +207 -0
- package/src/styles/captcha.css +78 -0
- package/src/styles/field.css +12 -0
- package/tsconfig.cjs.json +25 -0
- package/tsconfig.json +31 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +9 -0
- package/vite.cjs.config.ts +1 -1
- package/vite.config.ts +37 -4
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<link href="https://cdn.muicss.com/mui-0.10.3/css/mui.min.css" rel="stylesheet" type="text/css"/>
|
|
5
|
+
<link href="styles/field.css" rel="stylesheet" type="text/css"/>
|
|
6
|
+
|
|
7
|
+
<script src="index.js"></script>
|
|
8
|
+
<title>Procaptcha demo: PoW - Implicit Rendering</title>
|
|
9
|
+
<link href="styles/captcha.css" rel="stylesheet" type="text/css"/>
|
|
10
|
+
<script type="module">
|
|
11
|
+
// Function to update CAPTCHA status display is now provided by status-log-injector
|
|
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_POW,
|
|
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
|
+
|
|
144
|
+
window.onCaptchaFailed = function () {
|
|
145
|
+
console.log('Challenge failed');
|
|
146
|
+
updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
window.onCaptchaVerified = (output) => {
|
|
150
|
+
console.log('Challenge passed');
|
|
151
|
+
updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
152
|
+
updateCaptchaStatus(`Token generated: ${output.substring(0, 15)}...`, 'success');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Add custom event listener for CAPTCHA verification stages
|
|
156
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
157
|
+
setTimeout(() => {
|
|
158
|
+
updateCaptchaStatus('CAPTCHA script loaded and initialized', 'info');
|
|
159
|
+
updateCaptchaStatus('Waiting for user interaction...', 'info');
|
|
160
|
+
}, 500);
|
|
161
|
+
});
|
|
162
|
+
</script>
|
|
163
|
+
<script id="procaptchaScript" type="module" src="%VITE_BUNDLE_URL%" async defer></script>
|
|
164
|
+
</head>
|
|
165
|
+
<body>
|
|
166
|
+
|
|
167
|
+
<div class="mui-container">
|
|
168
|
+
<h1>Proof of Work CAPTCHA - Implicit Rendering</h1>
|
|
169
|
+
<p>This example demonstrates how to use Procaptcha in Proof of Work mode with implicit rendering.</p>
|
|
170
|
+
|
|
171
|
+
<!-- CAPTCHA Status Display will be injected by the status-log-injector plugin -->
|
|
172
|
+
|
|
173
|
+
<form action="%PROSOPO_SERVER_URL%/signup" method="POST" class="mui-form">
|
|
174
|
+
<h2>Example Login Form</h2>
|
|
175
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
176
|
+
<label for="name">Name</label>
|
|
177
|
+
<input id="name" type="text" name="name" required/>
|
|
178
|
+
</div>
|
|
179
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
180
|
+
<label for="email">Email Address</label>
|
|
181
|
+
<input id="email" type="email" name="email" required/>
|
|
182
|
+
</div>
|
|
183
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
184
|
+
<label for="password">Password</label>
|
|
185
|
+
<input id="password" type="password" name="password" required/>
|
|
186
|
+
</div>
|
|
187
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
188
|
+
<!-- Dev sitekey -->
|
|
189
|
+
<div
|
|
190
|
+
class="procaptcha"
|
|
191
|
+
data-theme="light"
|
|
192
|
+
data-sitekey="%PROSOPO_SITE_KEY_POW%"
|
|
193
|
+
data-failed-callback="onCaptchaFailed"
|
|
194
|
+
data-callback="onCaptchaVerified"
|
|
195
|
+
></div>
|
|
196
|
+
</div>
|
|
197
|
+
<div id="messageContainer" style="display: none; color: black;"><span id="message"></span></div>
|
|
198
|
+
<button type="button" class="mui-btn mui-btn--raised" onclick="onActionHandler()" data-cy="submit-button">Submit</button>
|
|
199
|
+
</form>
|
|
200
|
+
|
|
201
|
+
<!-- Console output display area -->
|
|
202
|
+
<div id="console-output" class="console-output" style="display: none;"></div>
|
|
203
|
+
|
|
204
|
+
<!-- Explanation will be injected by the explanation-injector plugin -->
|
|
205
|
+
</div>
|
|
206
|
+
</body>
|
|
207
|
+
</html>
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<link href="https://cdn.muicss.com/mui-0.10.3/css/mui.min.css" rel="stylesheet" type="text/css"/>
|
|
5
|
+
<link href="styles/field.css" rel="stylesheet" type="text/css"/>
|
|
6
|
+
|
|
7
|
+
<script src="index.js"></script>
|
|
8
|
+
<title>Procaptcha Puzzle Mode - Explicit Rendering</title>
|
|
9
|
+
<link href="styles/captcha.css" rel="stylesheet" type="text/css"/>
|
|
10
|
+
<script type="module">
|
|
11
|
+
// Function to update CAPTCHA status display is now provided by status-log-injector
|
|
12
|
+
|
|
13
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
14
|
+
updateCaptchaStatus('Page loaded - Initializing CAPTCHA system', 'info');
|
|
15
|
+
|
|
16
|
+
// Monitor DOM for CAPTCHA initialization
|
|
17
|
+
const observer = new MutationObserver((mutations) => {
|
|
18
|
+
mutations.forEach((mutation) => {
|
|
19
|
+
if (mutation.addedNodes.length) {
|
|
20
|
+
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
|
21
|
+
const node = mutation.addedNodes[i];
|
|
22
|
+
if (node.classList && (node.classList.contains('procaptcha') ||
|
|
23
|
+
node.querySelector && node.querySelector('.procaptcha'))) {
|
|
24
|
+
updateCaptchaStatus('CAPTCHA DOM elements initialized', 'info');
|
|
25
|
+
observer.disconnect();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// updateCaptchaStatus is now provided by status-log-injector
|
|
37
|
+
</script>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
<div class="mui-container">
|
|
41
|
+
<h1>Procaptcha Puzzle Mode - Explicit Rendering</h1>
|
|
42
|
+
<p>This example demonstrates how to use Procaptcha in Puzzle mode with explicit rendering.</p>
|
|
43
|
+
|
|
44
|
+
<!-- CAPTCHA Status Display will be injected by the status-log-injector plugin -->
|
|
45
|
+
|
|
46
|
+
<form id="demo-form" class="mui-form">
|
|
47
|
+
<h2>Example Form</h2>
|
|
48
|
+
|
|
49
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
50
|
+
<label for="name">Name</label>
|
|
51
|
+
<input type="text" id="name" name="name" required />
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
55
|
+
<label for="email">Email</label>
|
|
56
|
+
<input type="email" id="email" name="email" required />
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<!-- The container for the CAPTCHA -->
|
|
60
|
+
<div id="procaptcha-container"></div>
|
|
61
|
+
|
|
62
|
+
<button type="submit" class="mui-btn mui-btn--raised">Submit</button>
|
|
63
|
+
|
|
64
|
+
<div id="error"></div>
|
|
65
|
+
</form>
|
|
66
|
+
|
|
67
|
+
<div id="result" class="info-box" style="display: none;"></div>
|
|
68
|
+
|
|
69
|
+
<!-- Console output display area -->
|
|
70
|
+
<div id="console-output" class="console-output" style="display: none;"></div>
|
|
71
|
+
|
|
72
|
+
<!-- Explanation will be injected by the explanation-injector plugin -->
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<script type="module">
|
|
76
|
+
import { render } from "%VITE_BUNDLE_URL%"
|
|
77
|
+
|
|
78
|
+
// Form validation function
|
|
79
|
+
function validateForm() {
|
|
80
|
+
const nameInput = document.getElementById('name');
|
|
81
|
+
const emailInput = document.getElementById('email');
|
|
82
|
+
const errorDisplay = document.getElementById('error');
|
|
83
|
+
|
|
84
|
+
if (!nameInput.value || !emailInput.value) {
|
|
85
|
+
errorDisplay.textContent = 'Please fill out all fields';
|
|
86
|
+
errorDisplay.style.display = 'block';
|
|
87
|
+
window.updateCaptchaStatus('Form validation failed: Empty fields', 'error');
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Basic email validation
|
|
92
|
+
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
93
|
+
if (!emailPattern.test(emailInput.value)) {
|
|
94
|
+
errorDisplay.textContent = 'Please enter a valid email address';
|
|
95
|
+
errorDisplay.style.display = 'block';
|
|
96
|
+
window.updateCaptchaStatus('Form validation failed: Invalid email format', 'error');
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
errorDisplay.style.display = 'none';
|
|
101
|
+
window.updateCaptchaStatus('Form validation passed', 'info');
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Callback for successful CAPTCHA verification
|
|
106
|
+
function handleCaptchaResponse(token) {
|
|
107
|
+
console.log('Procaptcha verified, token:', token);
|
|
108
|
+
window.updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
109
|
+
window.updateCaptchaStatus(`Token generated: ${token.substring(0, 15)}...`, 'success');
|
|
110
|
+
|
|
111
|
+
const name = document.getElementById('name').value;
|
|
112
|
+
const email = document.getElementById('email').value;
|
|
113
|
+
|
|
114
|
+
// Display result
|
|
115
|
+
const resultElement = document.getElementById('result');
|
|
116
|
+
resultElement.innerHTML = `<strong>Form submitted with:</strong><br>
|
|
117
|
+
- Name: ${name}<br>
|
|
118
|
+
- Email: ${email}<br>
|
|
119
|
+
- Procaptcha verified: Yes`;
|
|
120
|
+
resultElement.style.display = 'block';
|
|
121
|
+
|
|
122
|
+
window.updateCaptchaStatus('Form submission completed', 'success');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Callback for failed CAPTCHA verification
|
|
126
|
+
function handleCaptchaFailed() {
|
|
127
|
+
console.log('Captcha verification failed');
|
|
128
|
+
window.updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
129
|
+
document.getElementById('error').textContent = 'CAPTCHA verification failed. Please try again.';
|
|
130
|
+
document.getElementById('error').style.display = 'block';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Wait for DOM content to be loaded
|
|
134
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
135
|
+
window.updateCaptchaStatus('Initializing CAPTCHA with explicit render call', 'info');
|
|
136
|
+
|
|
137
|
+
// Render the CAPTCHA
|
|
138
|
+
const widgetId = render(document.getElementById('procaptcha-container'), {
|
|
139
|
+
siteKey: import.meta.env.PROSOPO_SITE_KEY_PUZZLE,
|
|
140
|
+
callback: handleCaptchaResponse,
|
|
141
|
+
"failed-callback": handleCaptchaFailed
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
window.updateCaptchaStatus('CAPTCHA render function called with widget ID: ' + widgetId, 'info');
|
|
145
|
+
|
|
146
|
+
// Add form submit handler
|
|
147
|
+
document.getElementById('demo-form').addEventListener('submit', function(e) {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
window.updateCaptchaStatus('Form submission attempted', 'info');
|
|
150
|
+
if (validateForm()) {
|
|
151
|
+
// Form is valid, CAPTCHA verification will be handled by the callback
|
|
152
|
+
window.updateCaptchaStatus('Waiting for CAPTCHA verification', 'info');
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
</script>
|
|
157
|
+
</body>
|
|
158
|
+
</html>
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<link href="https://cdn.muicss.com/mui-0.10.3/css/mui.min.css" rel="stylesheet" type="text/css"/>
|
|
5
|
+
<link href="styles/field.css" rel="stylesheet" type="text/css"/>
|
|
6
|
+
|
|
7
|
+
<script src="index.js"></script>
|
|
8
|
+
<title>Procaptcha demo: Puzzle - Implicit Rendering</title>
|
|
9
|
+
<link href="styles/captcha.css" rel="stylesheet" type="text/css"/>
|
|
10
|
+
<script type="module">
|
|
11
|
+
// Function to update CAPTCHA status display is now provided by status-log-injector
|
|
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_PUZZLE,
|
|
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
|
+
|
|
144
|
+
window.onCaptchaFailed = function () {
|
|
145
|
+
console.log('Challenge failed');
|
|
146
|
+
updateCaptchaStatus('Challenge failed - CAPTCHA verification could not be completed', 'error');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
window.onCaptchaVerified = (output) => {
|
|
150
|
+
console.log('Challenge passed');
|
|
151
|
+
updateCaptchaStatus('Challenge passed successfully!', 'success');
|
|
152
|
+
updateCaptchaStatus(`Token generated: ${output.substring(0, 15)}...`, 'success');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Add custom event listener for CAPTCHA verification stages
|
|
156
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
157
|
+
setTimeout(() => {
|
|
158
|
+
updateCaptchaStatus('CAPTCHA script loaded and initialized', 'info');
|
|
159
|
+
updateCaptchaStatus('Waiting for user interaction...', 'info');
|
|
160
|
+
}, 500);
|
|
161
|
+
});
|
|
162
|
+
</script>
|
|
163
|
+
<script id="procaptchaScript" type="module" src="%VITE_BUNDLE_URL%" async defer></script>
|
|
164
|
+
</head>
|
|
165
|
+
<body>
|
|
166
|
+
|
|
167
|
+
<div class="mui-container">
|
|
168
|
+
<h1>Puzzle CAPTCHA - Implicit Rendering</h1>
|
|
169
|
+
<p>This example demonstrates how to use Procaptcha in Puzzle mode with implicit rendering.</p>
|
|
170
|
+
|
|
171
|
+
<!-- CAPTCHA Status Display will be injected by the status-log-injector plugin -->
|
|
172
|
+
|
|
173
|
+
<form action="%PROSOPO_SERVER_URL%/signup" method="POST" class="mui-form">
|
|
174
|
+
<h2>Example Login Form</h2>
|
|
175
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
176
|
+
<label for="name">Name</label>
|
|
177
|
+
<input id="name" type="text" name="name" required/>
|
|
178
|
+
</div>
|
|
179
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
180
|
+
<label for="email">Email Address</label>
|
|
181
|
+
<input id="email" type="email" name="email" required/>
|
|
182
|
+
</div>
|
|
183
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
184
|
+
<label for="password">Password</label>
|
|
185
|
+
<input id="password" type="password" name="password" required/>
|
|
186
|
+
</div>
|
|
187
|
+
<div class="mui-textfield mui-textfield--float-label">
|
|
188
|
+
<!-- Dev sitekey -->
|
|
189
|
+
<div
|
|
190
|
+
class="procaptcha"
|
|
191
|
+
data-theme="light"
|
|
192
|
+
data-sitekey="%PROSOPO_SITE_KEY_PUZZLE%"
|
|
193
|
+
data-failed-callback="onCaptchaFailed"
|
|
194
|
+
data-callback="onCaptchaVerified"
|
|
195
|
+
></div>
|
|
196
|
+
</div>
|
|
197
|
+
<div id="messageContainer" style="display: none; color: black;"><span id="message"></span></div>
|
|
198
|
+
<button type="button" class="mui-btn mui-btn--raised" onclick="onActionHandler()" data-cy="submit-button">Submit</button>
|
|
199
|
+
</form>
|
|
200
|
+
|
|
201
|
+
<!-- Console output display area -->
|
|
202
|
+
<div id="console-output" class="console-output" style="display: none;"></div>
|
|
203
|
+
|
|
204
|
+
<!-- Explanation will be injected by the explanation-injector plugin -->
|
|
205
|
+
</div>
|
|
206
|
+
</body>
|
|
207
|
+
</html>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
.console-output {
|
|
2
|
+
margin-top: 20px;
|
|
3
|
+
padding: 10px;
|
|
4
|
+
background-color: #f5f5f5;
|
|
5
|
+
border: 1px solid #ddd;
|
|
6
|
+
border-radius: 4px;
|
|
7
|
+
font-family: monospace;
|
|
8
|
+
white-space: pre-wrap;
|
|
9
|
+
max-height: 200px;
|
|
10
|
+
overflow-y: auto;
|
|
11
|
+
}
|
|
12
|
+
.info-box {
|
|
13
|
+
background-color: #e7f3fe;
|
|
14
|
+
border-left: 4px solid #2196f3;
|
|
15
|
+
padding: 15px;
|
|
16
|
+
margin: 20px 0;
|
|
17
|
+
}
|
|
18
|
+
.explanation {
|
|
19
|
+
margin: 20px 0;
|
|
20
|
+
padding: 20px;
|
|
21
|
+
background-color: #f9f9f9;
|
|
22
|
+
border-radius: 5px;
|
|
23
|
+
border: 1px solid #ddd;
|
|
24
|
+
}
|
|
25
|
+
code {
|
|
26
|
+
background-color: #f0f0f0;
|
|
27
|
+
padding: 2px 4px;
|
|
28
|
+
border-radius: 3px;
|
|
29
|
+
font-family: monospace;
|
|
30
|
+
}
|
|
31
|
+
pre {
|
|
32
|
+
background-color: #f5f5f5;
|
|
33
|
+
padding: 10px;
|
|
34
|
+
border-radius: 5px;
|
|
35
|
+
overflow-x: auto;
|
|
36
|
+
border: 1px solid #ddd;
|
|
37
|
+
}
|
|
38
|
+
.captcha-status {
|
|
39
|
+
margin-top: 20px;
|
|
40
|
+
padding: 15px;
|
|
41
|
+
background-color: #f0f8ff;
|
|
42
|
+
border: 2px solid #2196f3;
|
|
43
|
+
border-radius: 5px;
|
|
44
|
+
font-family: monospace;
|
|
45
|
+
font-size: 14px;
|
|
46
|
+
}
|
|
47
|
+
.status-item {
|
|
48
|
+
margin: 5px 0;
|
|
49
|
+
padding: 5px;
|
|
50
|
+
}
|
|
51
|
+
.status-success {
|
|
52
|
+
color: #4caf50;
|
|
53
|
+
font-weight: bold;
|
|
54
|
+
}
|
|
55
|
+
.status-error {
|
|
56
|
+
color: #f44336;
|
|
57
|
+
font-weight: bold;
|
|
58
|
+
}
|
|
59
|
+
.status-info {
|
|
60
|
+
color: #2196f3;
|
|
61
|
+
}
|
|
62
|
+
.status-warning {
|
|
63
|
+
color: #ff9800;
|
|
64
|
+
}
|
|
65
|
+
.status-title {
|
|
66
|
+
font-weight: bold;
|
|
67
|
+
margin-bottom: 10px;
|
|
68
|
+
border-bottom: 1px solid #2196f3;
|
|
69
|
+
padding-bottom: 5px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.account-select {
|
|
73
|
+
margin: 10px 0;
|
|
74
|
+
padding: 10px;
|
|
75
|
+
background-color: #f9f9f9;
|
|
76
|
+
border-radius: 5px;
|
|
77
|
+
border: 1px solid #ddd;
|
|
78
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* smooth transition by default */
|
|
2
|
+
.mui-textfield--float-label label {
|
|
3
|
+
transition: opacity .15s ease, transform .15s ease;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/* when wrapper gets .label-hidden, hide the label visually (keeps it in DOM) */
|
|
7
|
+
.mui-textfield--float-label.label-hidden > label {
|
|
8
|
+
opacity: 0 !important;
|
|
9
|
+
visibility: hidden !important;
|
|
10
|
+
pointer-events: none !important;
|
|
11
|
+
transform: translateY(-6px) !important;
|
|
12
|
+
}
|