From a7f5c1eb050a809c40238112d06b73235826c9e5 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Tue, 20 Aug 2024 16:36:34 +0200 Subject: [PATCH] MDL-82838 tool_mfa: Prevent accidental resubmission of token --- .../tool/mfa/amd/build/autosubmit_verification_code.min.js | 2 +- .../mfa/amd/build/autosubmit_verification_code.min.js.map | 2 +- admin/tool/mfa/amd/src/autosubmit_verification_code.js | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js b/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js index a52bce52c29..578bec532ee 100644 --- a/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js +++ b/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js @@ -1,3 +1,3 @@ -define("tool_mfa/autosubmit_verification_code",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=()=>{const codeInput=document.querySelector("#id_verificationcode"),codeForm=codeInput.closest("form"),submitButton=codeForm.querySelector("#id_submitbutton");codeInput.addEventListener("keyup",(function(){this.value.length>=6&&codeForm.submit()})),codeInput.disabled&&(submitButton.disabled=!0)}})); +define("tool_mfa/autosubmit_verification_code",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=()=>{const codeInput=document.querySelector("#id_verificationcode"),codeForm=codeInput.closest("form"),submitButton=codeForm.querySelector("#id_submitbutton");codeInput.addEventListener("input",(function(){this.value.length>=6&&(codeForm.submit(),codeInput.readOnly=!0,submitButton.disabled=!0)})),codeInput.disabled&&(submitButton.disabled=!0)}})); //# sourceMappingURL=autosubmit_verification_code.min.js.map \ No newline at end of file diff --git a/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js.map b/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js.map index 6e69dcc6318..720e359f6ab 100644 --- a/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js.map +++ b/admin/tool/mfa/amd/build/autosubmit_verification_code.min.js.map @@ -1 +1 @@ -{"version":3,"file":"autosubmit_verification_code.min.js","sources":["../src/autosubmit_verification_code.js"],"sourcesContent":["\n// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to autosubmit the verification code element when it reaches 6 characters.\n *\n * @module tool_mfa/autosubmit_verification_code\n * @copyright 2020 Peter Burnett \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = () => {\n const codeInput = document.querySelector(\"#id_verificationcode\");\n const codeForm = codeInput.closest(\"form\");\n const submitButton = codeForm.querySelector(\"#id_submitbutton\");\n\n // Event listener for code input field.\n codeInput.addEventListener('keyup', function() {\n if (this.value.length >= 6) {\n // Submits the closes form (parent).\n codeForm.submit();\n }\n });\n\n // Disable the submit button if the input field is disabled.\n // This occurs if there are no more attempts left for the factor.\n if (codeInput.disabled) {\n submitButton.disabled = true;\n }\n};\n"],"names":["codeInput","document","querySelector","codeForm","closest","submitButton","addEventListener","this","value","length","submit","disabled"],"mappings":"0KAwBoB,WACVA,UAAYC,SAASC,cAAc,wBACnCC,SAAWH,UAAUI,QAAQ,QAC7BC,aAAeF,SAASD,cAAc,oBAG5CF,UAAUM,iBAAiB,SAAS,WAC5BC,KAAKC,MAAMC,QAAU,GAErBN,SAASO,YAMbV,UAAUW,WACVN,aAAaM,UAAW"} \ No newline at end of file +{"version":3,"file":"autosubmit_verification_code.min.js","sources":["../src/autosubmit_verification_code.js"],"sourcesContent":["\n// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to autosubmit the verification code element when it reaches 6 characters.\n *\n * @module tool_mfa/autosubmit_verification_code\n * @copyright 2020 Peter Burnett \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = () => {\n const codeInput = document.querySelector(\"#id_verificationcode\");\n const codeForm = codeInput.closest(\"form\");\n const submitButton = codeForm.querySelector(\"#id_submitbutton\");\n\n // Event listener for code input field.\n codeInput.addEventListener('input', function() {\n if (this.value.length >= 6) {\n // Submits the closest form (parent) and prevents accidental resubmission.\n codeForm.submit();\n codeInput.readOnly = true;\n submitButton.disabled = true;\n }\n });\n\n // Disable the submit button if the input field is disabled.\n // This occurs if there are no more attempts left for the factor.\n if (codeInput.disabled) {\n submitButton.disabled = true;\n }\n};\n"],"names":["codeInput","document","querySelector","codeForm","closest","submitButton","addEventListener","this","value","length","submit","readOnly","disabled"],"mappings":"0KAwBoB,WACVA,UAAYC,SAASC,cAAc,wBACnCC,SAAWH,UAAUI,QAAQ,QAC7BC,aAAeF,SAASD,cAAc,oBAG5CF,UAAUM,iBAAiB,SAAS,WAC5BC,KAAKC,MAAMC,QAAU,IAErBN,SAASO,SACTV,UAAUW,UAAW,EACrBN,aAAaO,UAAW,MAM5BZ,UAAUY,WACVP,aAAaO,UAAW"} \ No newline at end of file diff --git a/admin/tool/mfa/amd/src/autosubmit_verification_code.js b/admin/tool/mfa/amd/src/autosubmit_verification_code.js index 6b29304976c..c0577406751 100644 --- a/admin/tool/mfa/amd/src/autosubmit_verification_code.js +++ b/admin/tool/mfa/amd/src/autosubmit_verification_code.js @@ -28,10 +28,12 @@ export const init = () => { const submitButton = codeForm.querySelector("#id_submitbutton"); // Event listener for code input field. - codeInput.addEventListener('keyup', function() { + codeInput.addEventListener('input', function() { if (this.value.length >= 6) { - // Submits the closes form (parent). + // Submits the closest form (parent) and prevents accidental resubmission. codeForm.submit(); + codeInput.readOnly = true; + submitButton.disabled = true; } });