From eb0d2b14218809d653b31e63f2f192d877a726da Mon Sep 17 00:00:00 2001 From: Nicklas Mantek Date: Tue, 4 Oct 2022 10:27:49 +0200 Subject: [PATCH] set action and renew --- .../TypeScript/definitions/turnstile.ts | 1 + .../TypeScript/modules/TurnstileForm.ts | 21 ++- Resources/Public/JavaScript/ReCaptcha.js | 127 +----------------- Resources/Public/JavaScript/Turnstile.js | 97 +------------ 4 files changed, 18 insertions(+), 228 deletions(-) diff --git a/Resources/Private/TypeScript/definitions/turnstile.ts b/Resources/Private/TypeScript/definitions/turnstile.ts index ab544201..599cfccb 100644 --- a/Resources/Private/TypeScript/definitions/turnstile.ts +++ b/Resources/Private/TypeScript/definitions/turnstile.ts @@ -2,6 +2,7 @@ declare interface RenderParameters { sitekey: string; callback?: (token: string) => void; theme?: string; + action?: string; } declare class turnstile { static render: ( diff --git a/Resources/Private/TypeScript/modules/TurnstileForm.ts b/Resources/Private/TypeScript/modules/TurnstileForm.ts index 36392535..46a02456 100644 --- a/Resources/Private/TypeScript/modules/TurnstileForm.ts +++ b/Resources/Private/TypeScript/modules/TurnstileForm.ts @@ -1,6 +1,6 @@ export class TurnstileForm { - constructor(container: NodeListOf) { - container.forEach((container) => { + constructor(containerList: NodeListOf) { + containerList.forEach((container) => { const captchaDiv = container.querySelector( '#turnstileDiv' ) as HTMLDivElement; @@ -10,18 +10,27 @@ export class TurnstileForm { return; } - this.initCaptcha(captchaDiv, sitekey); + const formId = container.getAttribute('id') ?? 'default'; + + this.initCaptcha(captchaDiv, sitekey, formId); }); } - private initCaptcha(captchaDiv: HTMLElement, sitekey: string) { - turnstile.render(captchaDiv, { + private initCaptcha( + captchaDiv: HTMLElement, + sitekey: string, + formId: string + ) { + const widgetId = turnstile.render(captchaDiv, { sitekey: sitekey, - callback: function () { + action: formId, + callback: () => { const captchaInput = captchaDiv.querySelector( 'input' ) as HTMLInputElement; captchaInput.setAttribute('name', 'formhandler[Turnstile]'); + + setTimeout(() => turnstile.reset(widgetId), 300000); }, theme: 'light', }); diff --git a/Resources/Public/JavaScript/ReCaptcha.js b/Resources/Public/JavaScript/ReCaptcha.js index b20e0005..341890ee 100644 --- a/Resources/Public/JavaScript/ReCaptcha.js +++ b/Resources/Public/JavaScript/ReCaptcha.js @@ -1,126 +1 @@ -/* - * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). - * This devtool is neither made for production nor for readable output files. - * It uses "eval()" calls to create a separate source file in the browser devtools. - * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) - * or disable the default devtool with "devtool: false". - * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). - */ -/******/ (() => { // webpackBootstrap -/******/ "use strict"; -/******/ var __webpack_modules__ = ({ - -/***/ "./node_modules/recaptcha-v3/dist/ReCaptcha.js": -/*!*****************************************************!*\ - !*** ./node_modules/recaptcha-v3/dist/ReCaptcha.js ***! - \*****************************************************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - -eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ReCaptchaInstance = exports.getInstance = exports.load = void 0;\nvar ReCaptchaLoader_1 = __webpack_require__(/*! ./ReCaptchaLoader */ \"./node_modules/recaptcha-v3/dist/ReCaptchaLoader.js\");\nObject.defineProperty(exports, \"load\", ({ enumerable: true, get: function () { return ReCaptchaLoader_1.load; } }));\nObject.defineProperty(exports, \"getInstance\", ({ enumerable: true, get: function () { return ReCaptchaLoader_1.getInstance; } }));\nvar ReCaptchaInstance_1 = __webpack_require__(/*! ./ReCaptchaInstance */ \"./node_modules/recaptcha-v3/dist/ReCaptchaInstance.js\");\nObject.defineProperty(exports, \"ReCaptchaInstance\", ({ enumerable: true, get: function () { return ReCaptchaInstance_1.ReCaptchaInstance; } }));\n\n\n//# sourceURL=webpack://formhandler/./node_modules/recaptcha-v3/dist/ReCaptcha.js?"); - -/***/ }), - -/***/ "./node_modules/recaptcha-v3/dist/ReCaptchaInstance.js": -/*!*************************************************************!*\ - !*** ./node_modules/recaptcha-v3/dist/ReCaptchaInstance.js ***! - \*************************************************************/ -/***/ (function(__unused_webpack_module, exports) { - -eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ReCaptchaInstance = void 0;\nvar ReCaptchaInstance = (function () {\n function ReCaptchaInstance(siteKey, recaptchaID, recaptcha) {\n this.siteKey = siteKey;\n this.recaptchaID = recaptchaID;\n this.recaptcha = recaptcha;\n this.styleContainer = null;\n }\n ReCaptchaInstance.prototype.execute = function (action) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2, this.recaptcha.enterprise ? this.recaptcha.enterprise.execute(this.recaptchaID, { action: action }) : this.recaptcha.execute(this.recaptchaID, { action: action })];\n });\n });\n };\n ReCaptchaInstance.prototype.getSiteKey = function () {\n return this.siteKey;\n };\n ReCaptchaInstance.prototype.hideBadge = function () {\n if (this.styleContainer !== null) {\n return;\n }\n this.styleContainer = document.createElement('style');\n this.styleContainer.innerHTML = '.grecaptcha-badge{visibility:hidden !important;}';\n document.head.appendChild(this.styleContainer);\n };\n ReCaptchaInstance.prototype.showBadge = function () {\n if (this.styleContainer === null) {\n return;\n }\n document.head.removeChild(this.styleContainer);\n this.styleContainer = null;\n };\n return ReCaptchaInstance;\n}());\nexports.ReCaptchaInstance = ReCaptchaInstance;\n\n\n//# sourceURL=webpack://formhandler/./node_modules/recaptcha-v3/dist/ReCaptchaInstance.js?"); - -/***/ }), - -/***/ "./node_modules/recaptcha-v3/dist/ReCaptchaLoader.js": -/*!***********************************************************!*\ - !*** ./node_modules/recaptcha-v3/dist/ReCaptchaLoader.js ***! - \***********************************************************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - -eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.getInstance = exports.load = void 0;\nvar ReCaptchaInstance_1 = __webpack_require__(/*! ./ReCaptchaInstance */ \"./node_modules/recaptcha-v3/dist/ReCaptchaInstance.js\");\nvar ELoadingState;\n(function (ELoadingState) {\n ELoadingState[ELoadingState[\"NOT_LOADED\"] = 0] = \"NOT_LOADED\";\n ELoadingState[ELoadingState[\"LOADING\"] = 1] = \"LOADING\";\n ELoadingState[ELoadingState[\"LOADED\"] = 2] = \"LOADED\";\n})(ELoadingState || (ELoadingState = {}));\nvar ReCaptchaLoader = (function () {\n function ReCaptchaLoader() {\n }\n ReCaptchaLoader.load = function (siteKey, options) {\n if (options === void 0) { options = {}; }\n if (typeof document === 'undefined') {\n return Promise.reject(new Error('This is a library for the browser!'));\n }\n if (ReCaptchaLoader.getLoadingState() === ELoadingState.LOADED) {\n if (ReCaptchaLoader.instance.getSiteKey() === siteKey) {\n return Promise.resolve(ReCaptchaLoader.instance);\n }\n else {\n return Promise.reject(new Error('reCAPTCHA already loaded with different site key!'));\n }\n }\n if (ReCaptchaLoader.getLoadingState() === ELoadingState.LOADING) {\n if (siteKey !== ReCaptchaLoader.instanceSiteKey) {\n return Promise.reject(new Error('reCAPTCHA already loaded with different site key!'));\n }\n return new Promise(function (resolve, reject) {\n ReCaptchaLoader.successfulLoadingConsumers.push(function (instance) { return resolve(instance); });\n ReCaptchaLoader.errorLoadingRunnable.push(function (reason) { return reject(reason); });\n });\n }\n ReCaptchaLoader.instanceSiteKey = siteKey;\n ReCaptchaLoader.setLoadingState(ELoadingState.LOADING);\n var loader = new ReCaptchaLoader();\n return new Promise(function (resolve, reject) {\n loader.loadScript(siteKey, options.useRecaptchaNet || false, options.useEnterprise || false, options.renderParameters ? options.renderParameters : {}, options.customUrl).then(function () {\n ReCaptchaLoader.setLoadingState(ELoadingState.LOADED);\n var widgetID = loader.doExplicitRender(grecaptcha, siteKey, options.explicitRenderParameters ? options.explicitRenderParameters : {}, options.useEnterprise || false);\n var instance = new ReCaptchaInstance_1.ReCaptchaInstance(siteKey, widgetID, grecaptcha);\n ReCaptchaLoader.successfulLoadingConsumers.forEach(function (v) { return v(instance); });\n ReCaptchaLoader.successfulLoadingConsumers = [];\n if (options.autoHideBadge) {\n instance.hideBadge();\n }\n ReCaptchaLoader.instance = instance;\n resolve(instance);\n }).catch(function (error) {\n ReCaptchaLoader.errorLoadingRunnable.forEach(function (v) { return v(error); });\n ReCaptchaLoader.errorLoadingRunnable = [];\n reject(error);\n });\n });\n };\n ReCaptchaLoader.getInstance = function () {\n return ReCaptchaLoader.instance;\n };\n ReCaptchaLoader.setLoadingState = function (state) {\n ReCaptchaLoader.loadingState = state;\n };\n ReCaptchaLoader.getLoadingState = function () {\n if (ReCaptchaLoader.loadingState === null) {\n return ELoadingState.NOT_LOADED;\n }\n else {\n return ReCaptchaLoader.loadingState;\n }\n };\n ReCaptchaLoader.prototype.loadScript = function (siteKey, useRecaptchaNet, useEnterprise, renderParameters, customUrl) {\n var _this = this;\n if (useRecaptchaNet === void 0) { useRecaptchaNet = false; }\n if (useEnterprise === void 0) { useEnterprise = false; }\n if (renderParameters === void 0) { renderParameters = {}; }\n if (customUrl === void 0) { customUrl = ''; }\n var scriptElement = document.createElement('script');\n scriptElement.setAttribute('recaptcha-v3-script', '');\n var scriptBase = 'https://www.google.com/recaptcha/api.js';\n if (useRecaptchaNet) {\n if (useEnterprise) {\n scriptBase = 'https://recaptcha.net/recaptcha/enterprise.js';\n }\n else {\n scriptBase = 'https://recaptcha.net/recaptcha/api.js';\n }\n }\n if (useEnterprise) {\n scriptBase = 'https://www.google.com/recaptcha/enterprise.js';\n }\n if (customUrl) {\n scriptBase = customUrl;\n }\n if (renderParameters.render) {\n renderParameters.render = undefined;\n }\n var parametersQuery = this.buildQueryString(renderParameters);\n scriptElement.src = scriptBase + '?render=explicit' + parametersQuery;\n return new Promise(function (resolve, reject) {\n scriptElement.addEventListener('load', _this.waitForScriptToLoad(function () {\n resolve(scriptElement);\n }, useEnterprise), false);\n scriptElement.onerror = function (error) {\n ReCaptchaLoader.setLoadingState(ELoadingState.NOT_LOADED);\n reject(error);\n };\n document.head.appendChild(scriptElement);\n });\n };\n ReCaptchaLoader.prototype.buildQueryString = function (parameters) {\n var parameterKeys = Object.keys(parameters);\n if (parameterKeys.length < 1) {\n return '';\n }\n return '&' + Object.keys(parameters)\n .filter(function (parameterKey) {\n return !!parameters[parameterKey];\n })\n .map(function (parameterKey) {\n return parameterKey + '=' + parameters[parameterKey];\n }).join('&');\n };\n ReCaptchaLoader.prototype.waitForScriptToLoad = function (callback, useEnterprise) {\n var _this = this;\n return function () {\n if (window.grecaptcha === undefined) {\n setTimeout(function () {\n _this.waitForScriptToLoad(callback, useEnterprise);\n }, ReCaptchaLoader.SCRIPT_LOAD_DELAY);\n }\n else {\n if (useEnterprise) {\n window.grecaptcha.enterprise.ready(function () {\n callback();\n });\n }\n else {\n window.grecaptcha.ready(function () {\n callback();\n });\n }\n }\n };\n };\n ReCaptchaLoader.prototype.doExplicitRender = function (grecaptcha, siteKey, parameters, isEnterprise) {\n var augmentedParameters = {\n sitekey: siteKey,\n badge: parameters.badge,\n size: parameters.size,\n tabindex: parameters.tabindex\n };\n if (parameters.container) {\n if (isEnterprise) {\n return grecaptcha.enterprise.render(parameters.container, augmentedParameters);\n }\n else {\n return grecaptcha.render(parameters.container, augmentedParameters);\n }\n }\n else {\n if (isEnterprise) {\n return grecaptcha.enterprise.render(augmentedParameters);\n }\n else {\n return grecaptcha.render(augmentedParameters);\n }\n }\n };\n ReCaptchaLoader.loadingState = null;\n ReCaptchaLoader.instance = null;\n ReCaptchaLoader.instanceSiteKey = null;\n ReCaptchaLoader.successfulLoadingConsumers = [];\n ReCaptchaLoader.errorLoadingRunnable = [];\n ReCaptchaLoader.SCRIPT_LOAD_DELAY = 25;\n return ReCaptchaLoader;\n}());\nexports.load = ReCaptchaLoader.load;\nexports.getInstance = ReCaptchaLoader.getInstance;\n\n\n//# sourceURL=webpack://formhandler/./node_modules/recaptcha-v3/dist/ReCaptchaLoader.js?"); - -/***/ }), - -/***/ "./Resources/Private/TypeScript/ReCaptcha.ts": -/*!***************************************************!*\ - !*** ./Resources/Private/TypeScript/ReCaptcha.ts ***! - \***************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_ReCaptchaSubmit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/ReCaptchaSubmit */ \"./Resources/Private/TypeScript/modules/ReCaptchaSubmit.ts\");\n\ndocument.addEventListener('DOMContentLoaded', function () {\n var recaptchaForm = document.querySelectorAll('form');\n if (null !== recaptchaForm) {\n new _modules_ReCaptchaSubmit__WEBPACK_IMPORTED_MODULE_0__.ReCaptchaSubmit(recaptchaForm);\n }\n});\n\n\n//# sourceURL=webpack://formhandler/./Resources/Private/TypeScript/ReCaptcha.ts?"); - -/***/ }), - -/***/ "./Resources/Private/TypeScript/modules/ReCaptchaSubmit.ts": -/*!*****************************************************************!*\ - !*** ./Resources/Private/TypeScript/modules/ReCaptchaSubmit.ts ***! - \*****************************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"ReCaptchaSubmit\": () => (/* binding */ ReCaptchaSubmit)\n/* harmony export */ });\n/* harmony import */ var recaptcha_v3__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! recaptcha-v3 */ \"./node_modules/recaptcha-v3/dist/ReCaptcha.js\");\n\nvar ReCaptchaSubmit = /** @class */ (function () {\n function ReCaptchaSubmit(container) {\n var _this = this;\n this.containerList = container;\n this.containerList.forEach(function (container) {\n var _a;\n var sitekey = String((_a = container.querySelector('#ReCaptchaField')) === null || _a === void 0 ? void 0 : _a.dataset.sitekey);\n var submitButton = document.querySelector(\"[type='submit']\");\n if (!sitekey) {\n return;\n }\n submitButton.addEventListener('click', function (ev) {\n return _this.handler(ev, container, sitekey);\n });\n });\n }\n ReCaptchaSubmit.prototype.handler = function (event, container, sitekey) {\n event.preventDefault();\n var captchaField = container.querySelector('#ReCaptchaField');\n (0,recaptcha_v3__WEBPACK_IMPORTED_MODULE_0__.load)(sitekey).then(function (recaptcha) {\n recaptcha.execute('submit').then(function (token) {\n captchaField.value = token;\n container.submit();\n });\n });\n };\n return ReCaptchaSubmit;\n}());\n\n\n\n//# sourceURL=webpack://formhandler/./Resources/Private/TypeScript/modules/ReCaptchaSubmit.ts?"); - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __webpack_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ -/************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module can't be inlined because the eval devtool is used. -/******/ var __webpack_exports__ = __webpack_require__("./Resources/Private/TypeScript/ReCaptcha.ts"); -/******/ -/******/ })() -; \ No newline at end of file +(()=>{"use strict";var e,t,n={90:(e,t,n)=>{t.zD=void 0;var r=n(845);Object.defineProperty(t,"zD",{enumerable:!0,get:function(){return r.load}});n(551)},551:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function c(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.getInstance=t.load=void 0;var r,i=n(551);!function(e){e[e.NOT_LOADED=0]="NOT_LOADED",e[e.LOADING=1]="LOADING",e[e.LOADED=2]="LOADED"}(r||(r={}));var o=function(){function e(){}return e.load=function(t,n){if(void 0===n&&(n={}),"undefined"==typeof document)return Promise.reject(new Error("This is a library for the browser!"));if(e.getLoadingState()===r.LOADED)return e.instance.getSiteKey()===t?Promise.resolve(e.instance):Promise.reject(new Error("reCAPTCHA already loaded with different site key!"));if(e.getLoadingState()===r.LOADING)return t!==e.instanceSiteKey?Promise.reject(new Error("reCAPTCHA already loaded with different site key!")):new Promise((function(t,n){e.successfulLoadingConsumers.push((function(e){return t(e)})),e.errorLoadingRunnable.push((function(e){return n(e)}))}));e.instanceSiteKey=t,e.setLoadingState(r.LOADING);var o=new e;return new Promise((function(a,c){o.loadScript(t,n.useRecaptchaNet||!1,n.useEnterprise||!1,n.renderParameters?n.renderParameters:{},n.customUrl).then((function(){e.setLoadingState(r.LOADED);var c=o.doExplicitRender(grecaptcha,t,n.explicitRenderParameters?n.explicitRenderParameters:{},n.useEnterprise||!1),u=new i.ReCaptchaInstance(t,c,grecaptcha);e.successfulLoadingConsumers.forEach((function(e){return e(u)})),e.successfulLoadingConsumers=[],n.autoHideBadge&&u.hideBadge(),e.instance=u,a(u)})).catch((function(t){e.errorLoadingRunnable.forEach((function(e){return e(t)})),e.errorLoadingRunnable=[],c(t)}))}))},e.getInstance=function(){return e.instance},e.setLoadingState=function(t){e.loadingState=t},e.getLoadingState=function(){return null===e.loadingState?r.NOT_LOADED:e.loadingState},e.prototype.loadScript=function(t,n,i,o,a){var c=this;void 0===n&&(n=!1),void 0===i&&(i=!1),void 0===o&&(o={}),void 0===a&&(a="");var u=document.createElement("script");u.setAttribute("recaptcha-v3-script","");var s="https://www.google.com/recaptcha/api.js";n&&(s=i?"https://recaptcha.net/recaptcha/enterprise.js":"https://recaptcha.net/recaptcha/api.js"),i&&(s="https://www.google.com/recaptcha/enterprise.js"),a&&(s=a),o.render&&(o.render=void 0);var d=this.buildQueryString(o);return u.src=s+"?render=explicit"+d,new Promise((function(t,n){u.addEventListener("load",c.waitForScriptToLoad((function(){t(u)}),i),!1),u.onerror=function(t){e.setLoadingState(r.NOT_LOADED),n(t)},document.head.appendChild(u)}))},e.prototype.buildQueryString=function(e){return Object.keys(e).length<1?"":"&"+Object.keys(e).filter((function(t){return!!e[t]})).map((function(t){return t+"="+e[t]})).join("&")},e.prototype.waitForScriptToLoad=function(t,n){var r=this;return function(){void 0===window.grecaptcha?setTimeout((function(){r.waitForScriptToLoad(t,n)}),e.SCRIPT_LOAD_DELAY):n?window.grecaptcha.enterprise.ready((function(){t()})):window.grecaptcha.ready((function(){t()}))}},e.prototype.doExplicitRender=function(e,t,n,r){var i={sitekey:t,badge:n.badge,size:n.size,tabindex:n.tabindex};return n.container?r?e.enterprise.render(n.container,i):e.render(n.container,i):r?e.enterprise.render(i):e.render(i)},e.loadingState=null,e.instance=null,e.instanceSiteKey=null,e.successfulLoadingConsumers=[],e.errorLoadingRunnable=[],e.SCRIPT_LOAD_DELAY=25,e}();t.load=o.load,t.getInstance=o.getInstance}},r={};e=function e(t){var i=r[t];if(void 0!==i)return i.exports;var o=r[t]={exports:{}};return n[t].call(o.exports,o,o.exports,e),o.exports}(90),t=function(){function t(e){var t=this;this.containerList=e,this.containerList.forEach((function(e){var n,r=String(null===(n=e.querySelector("#ReCaptchaField"))||void 0===n?void 0:n.dataset.sitekey),i=document.querySelector("[type='submit']");r&&i.addEventListener("click",(function(n){return t.handler(n,e,r)}))}))}return t.prototype.handler=function(t,n,r){t.preventDefault();var i=n.querySelector("#ReCaptchaField");(0,e.zD)(r).then((function(e){e.execute("submit").then((function(e){i.value=e,n.submit()}))}))},t}(),document.addEventListener("DOMContentLoaded",(function(){var e=document.querySelectorAll("form");null!==e&&new t(e)}))})(); \ No newline at end of file diff --git a/Resources/Public/JavaScript/Turnstile.js b/Resources/Public/JavaScript/Turnstile.js index 5fbc6405..68120b07 100644 --- a/Resources/Public/JavaScript/Turnstile.js +++ b/Resources/Public/JavaScript/Turnstile.js @@ -1,96 +1 @@ -/* - * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). - * This devtool is neither made for production nor for readable output files. - * It uses "eval()" calls to create a separate source file in the browser devtools. - * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) - * or disable the default devtool with "devtool: false". - * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). - */ -/******/ (() => { // webpackBootstrap -/******/ "use strict"; -/******/ var __webpack_modules__ = ({ - -/***/ "./Resources/Private/TypeScript/Turnstile.ts": -/*!***************************************************!*\ - !*** ./Resources/Private/TypeScript/Turnstile.ts ***! - \***************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_TurnstileForm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/TurnstileForm */ \"./Resources/Private/TypeScript/modules/TurnstileForm.ts\");\n\ndocument.addEventListener('DOMContentLoaded', function () {\n var _a;\n if (typeof turnstile === 'undefined') {\n (_a = document.querySelector('#turnstilScript')) === null || _a === void 0 ? void 0 : _a.addEventListener('load', function () {\n runInit();\n });\n }\n else {\n // fallback if user returns to page\n runInit();\n }\n function runInit() {\n var forms = document.querySelectorAll('form');\n if (forms !== null) {\n new _modules_TurnstileForm__WEBPACK_IMPORTED_MODULE_0__.TurnstileForm(forms);\n }\n }\n});\n\n\n//# sourceURL=webpack://formhandler/./Resources/Private/TypeScript/Turnstile.ts?"); - -/***/ }), - -/***/ "./Resources/Private/TypeScript/modules/TurnstileForm.ts": -/*!***************************************************************!*\ - !*** ./Resources/Private/TypeScript/modules/TurnstileForm.ts ***! - \***************************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"TurnstileForm\": () => (/* binding */ TurnstileForm)\n/* harmony export */ });\nvar TurnstileForm = /** @class */ (function () {\n function TurnstileForm(container) {\n var _this = this;\n container.forEach(function (container) {\n var captchaDiv = container.querySelector('#turnstileDiv');\n var sitekey = String(captchaDiv === null || captchaDiv === void 0 ? void 0 : captchaDiv.dataset.sitekey);\n if (!captchaDiv || !sitekey) {\n return;\n }\n _this.initCaptcha(captchaDiv, sitekey);\n });\n }\n TurnstileForm.prototype.initCaptcha = function (captchaDiv, sitekey) {\n turnstile.render(captchaDiv, {\n sitekey: sitekey,\n callback: function () {\n var captchaInput = captchaDiv.querySelector('input');\n captchaInput.setAttribute('name', 'formhandler[Turnstile]');\n },\n theme: 'light',\n });\n };\n return TurnstileForm;\n}());\n\n\n\n//# sourceURL=webpack://formhandler/./Resources/Private/TypeScript/modules/TurnstileForm.ts?"); - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __webpack_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ -/************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module can't be inlined because the eval devtool is used. -/******/ var __webpack_exports__ = __webpack_require__("./Resources/Private/TypeScript/Turnstile.ts"); -/******/ -/******/ })() -; \ No newline at end of file +(()=>{"use strict";var t=function(){function t(t){var e=this;t.forEach((function(t){var n,i=t.querySelector("#turnstileDiv"),r=String(null==i?void 0:i.dataset.sitekey);if(i&&r){var u=null!==(n=t.getAttribute("id"))&&void 0!==n?n:"default";e.initCaptcha(i,r,u)}}))}return t.prototype.initCaptcha=function(t,e,n){var i=turnstile.render(t,{sitekey:e,action:n,callback:function(){t.querySelector("input").setAttribute("name","formhandler[Turnstile]"),setTimeout((function(){return turnstile.reset(i)}),3e5)},theme:"light"})},t}();document.addEventListener("DOMContentLoaded",(function(){var e;function n(){var e=document.querySelectorAll("form");null!==e&&new t(e)}"undefined"==typeof turnstile?null===(e=document.querySelector("#turnstilScript"))||void 0===e||e.addEventListener("load",(function(){n()})):n()}))})(); \ No newline at end of file