changed layout of captcha plugin
All checks were successful
Build and Deploy Hugo Site / buildAndDeploy (push) Successful in 51s
All checks were successful
Build and Deploy Hugo Site / buildAndDeploy (push) Successful in 51s
This commit is contained in:
parent
97f1f7c62d
commit
0917adccba
2 changed files with 115 additions and 116 deletions
89
assets/vendor/captcha-system/js/main.js
vendored
89
assets/vendor/captcha-system/js/main.js
vendored
|
|
@ -3,65 +3,70 @@
|
||||||
* Date: 2021-11-26
|
* Date: 2021-11-26
|
||||||
* Description: This is the main Javascript file for Captcha.
|
* Description: This is the main Javascript file for Captcha.
|
||||||
*/
|
*/
|
||||||
document.onload = getCaptcha();
|
document.onload = getCaptcha()
|
||||||
|
|
||||||
|
|
||||||
function getCaptcha() {
|
function getCaptcha() {
|
||||||
var form = document.getElementsByClassName("captcha-container");
|
var form = document.getElementsByClassName('captcha-container')
|
||||||
var captcha = document.createElement("div");
|
var captcha = document.createElement('div')
|
||||||
captcha.className = "captcha";
|
captcha.className = 'captcha'
|
||||||
var captchaTxt = generateCaptcha();
|
var captchaTxt = generateCaptcha()
|
||||||
captcha.innerHTML = "<div class='captcha-image-container'><div class='captcha-image' data-captcha = '"+captchaTxt+"'>"+captchaTxt+"</div></div><br><input type='text' class='captcha-input' placeholder='Enter Captcha Shown' required/><button type='button' class='captcha-refresh' onclick='generateCaptcha2()'>⟳</button><br /><button type='button' class='captcha-verify' onclick='captchaValidate();'>✔</button><br /><h4 id='captcha-response'></h4>";
|
captcha.innerHTML =
|
||||||
form[0].appendChild(captcha);
|
"<div class='captcha-image-container'><div class='captcha-image' data-captcha = '" +
|
||||||
var submit = document.getElementsByClassName('submit-after-valid-captcha');
|
captchaTxt +
|
||||||
submit[0].disabled = true;
|
"'>" +
|
||||||
|
captchaTxt +
|
||||||
|
"</div></div><input type='text' class='captcha-input' placeholder='Enter Captcha Shown' required/><div class='captcha-buttons'><button type='button' class='captcha-refresh' onclick='generateCaptcha2()'>⟳</button> <button type='button' class='captcha-verify' onclick='captchaValidate();'></button></div><h4 id='captcha-response'></h4>"
|
||||||
|
form[0].appendChild(captcha)
|
||||||
|
var submit = document.getElementsByClassName('submit-after-valid-captcha')
|
||||||
|
submit[0].disabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function captchaValidate() {
|
function captchaValidate() {
|
||||||
var captcha = document.getElementsByClassName("captcha-input");
|
var captcha = document.getElementsByClassName('captcha-input')
|
||||||
var captchaText = captcha[0].value;
|
var captchaText = captcha[0].value
|
||||||
var originalCaptchaImg = document.getElementsByClassName("captcha-image");
|
var originalCaptchaImg = document.getElementsByClassName('captcha-image')
|
||||||
originalCaptcha = originalCaptchaImg[0].getAttribute("data-captcha");
|
originalCaptcha = originalCaptchaImg[0].getAttribute('data-captcha')
|
||||||
|
|
||||||
if (captchaText == originalCaptcha) {
|
if (captchaText == originalCaptcha) {
|
||||||
console.log("Captcha Matched");
|
console.log('Captcha Matched')
|
||||||
var submit = document.getElementsByClassName('submit-after-valid-captcha');
|
var submit = document.getElementsByClassName('submit-after-valid-captcha')
|
||||||
submit[0].disabled = false;
|
submit[0].disabled = false
|
||||||
var verify = document.getElementsByClassName('captcha-verify');
|
var verify = document.getElementsByClassName('captcha-verify')
|
||||||
verify[0].disabled = true;
|
verify[0].disabled = true
|
||||||
verify[0].style.cursor = "not-allowed";
|
verify[0].style.cursor = 'not-allowed'
|
||||||
var captchaResponse = document.getElementById('captcha-response');
|
var captchaResponse = document.getElementById('captcha-response')
|
||||||
captchaResponse.innerHTML = "<p style='color: green; text-align: center;'>✔</p>";
|
captchaResponse.innerHTML = "<p style='color: green; text-align: center;'>✔</p>"
|
||||||
} else {
|
} else {
|
||||||
var submit = document.getElementsByClassName('submit-after-valid-captcha');
|
var submit = document.getElementsByClassName('submit-after-valid-captcha')
|
||||||
submit[0].disabled = true;
|
submit[0].disabled = true
|
||||||
var verify = document.getElementsByClassName('captcha-verify');
|
var verify = document.getElementsByClassName('captcha-verify')
|
||||||
verify[0].disabled = false;
|
verify[0].disabled = false
|
||||||
var captchaResponse = document.getElementById('captcha-response');
|
var captchaResponse = document.getElementById('captcha-response')
|
||||||
captchaResponse.innerHTML = "<p style='color: red; text-align: center;'>X</p>";
|
captchaResponse.innerHTML = "<p style='color: red; text-align: center;'>X</p>"
|
||||||
generateCaptcha2();
|
generateCaptcha2()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to generate captcha without changing the data and content of the captcha-image div
|
// Function to generate captcha without changing the data and content of the captcha-image div
|
||||||
// For 1st time generation of captcha
|
// For 1st time generation of captcha
|
||||||
function generateCaptcha() {
|
function generateCaptcha() {
|
||||||
var text = "";
|
var text = ''
|
||||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||||
for( var i=0; i < 5; i++ )
|
for (var i = 0; i < 5; i++) {
|
||||||
{ text += possible.charAt(Math.floor(Math.random() * possible.length));}
|
text += possible.charAt(Math.floor(Math.random() * possible.length))
|
||||||
return text;
|
}
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to generate captcha without changing the data and content of the captcha-image div
|
// Function to generate captcha without changing the data and content of the captcha-image div
|
||||||
// For rest of the time generation of captcha
|
// For rest of the time generation of captcha
|
||||||
function generateCaptcha2() {
|
function generateCaptcha2() {
|
||||||
var text = "";
|
var text = ''
|
||||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||||
for( var i=0; i < 5; i++ )
|
for (var i = 0; i < 5; i++) {
|
||||||
{ text += possible.charAt(Math.floor(Math.random() * possible.length));}
|
text += possible.charAt(Math.floor(Math.random() * possible.length))
|
||||||
var captcha = document.getElementsByClassName("captcha-image");
|
}
|
||||||
captcha[0].innerHTML = text;
|
var captcha = document.getElementsByClassName('captcha-image')
|
||||||
captcha[0].setAttribute("data-captcha", text);
|
captcha[0].innerHTML = text
|
||||||
|
captcha[0].setAttribute('data-captcha', text)
|
||||||
}
|
}
|
||||||
|
|
@ -1,125 +1,119 @@
|
||||||
const fs = require("fs");
|
const fs = require('fs')
|
||||||
const path = require("path");
|
const path = require('path')
|
||||||
|
|
||||||
const toggleComment = ({ filepath, regex }) => {
|
const toggleComment = ({ filepath, regex }) => {
|
||||||
let updatedContent = fs.readFileSync(filepath, "utf8");
|
let updatedContent = fs.readFileSync(filepath, 'utf8')
|
||||||
const match = updatedContent.match(regex);
|
const match = updatedContent.match(regex)
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const matchedContent = match[0];
|
const matchedContent = match[0]
|
||||||
const hasComment = matchedContent.startsWith("# ");
|
const hasComment = matchedContent.startsWith('# ')
|
||||||
if (hasComment) {
|
if (hasComment) {
|
||||||
const hasBreakline = matchedContent.includes("\n");
|
const hasBreakline = matchedContent.includes('\n')
|
||||||
if (hasBreakline) {
|
if (hasBreakline) {
|
||||||
updatedContent = updatedContent.replace(
|
updatedContent = updatedContent.replace(regex, matchedContent.replace(/# /gm, ''))
|
||||||
regex,
|
fs.writeFileSync(filepath, updatedContent, 'utf8')
|
||||||
matchedContent.replace(/# /gm, ""),
|
|
||||||
);
|
|
||||||
fs.writeFileSync(filepath, updatedContent, "utf8");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updatedContent = updatedContent.replace(regex, "# " + matchedContent);
|
updatedContent = updatedContent.replace(regex, '# ' + matchedContent)
|
||||||
fs.writeFileSync(filepath, updatedContent, "utf8");
|
fs.writeFileSync(filepath, updatedContent, 'utf8')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const createNewfolder = (rootfolder, folderName) => {
|
const createNewfolder = (rootfolder, folderName) => {
|
||||||
const newFolder = path.join(rootfolder, folderName);
|
const newFolder = path.join(rootfolder, folderName)
|
||||||
fs.mkdirSync(newFolder, { recursive: true });
|
fs.mkdirSync(newFolder, { recursive: true })
|
||||||
return newFolder;
|
return newFolder
|
||||||
};
|
}
|
||||||
|
|
||||||
const deleteFolder = (folderPath) => {
|
const deleteFolder = (folderPath) => {
|
||||||
if (fs.existsSync(folderPath)) {
|
if (fs.existsSync(folderPath)) {
|
||||||
fs.rmSync(folderPath, { recursive: true, force: true });
|
fs.rmSync(folderPath, { recursive: true, force: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const getFolderName = (rootfolder) => {
|
const getFolderName = (rootfolder) => {
|
||||||
const configPath = path.join(rootfolder, "exampleSite/hugo.toml");
|
const configPath = path.join(rootfolder, 'exampleSite/hugo.toml')
|
||||||
const getConfig = fs.readFileSync(configPath, "utf8");
|
const getConfig = fs.readFileSync(configPath, 'utf8')
|
||||||
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
|
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/)
|
||||||
let selectedTheme = null;
|
let selectedTheme = null
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
selectedTheme = match[1];
|
selectedTheme = match[1]
|
||||||
|
}
|
||||||
|
return selectedTheme
|
||||||
}
|
}
|
||||||
return selectedTheme;
|
|
||||||
};
|
|
||||||
|
|
||||||
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
|
const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
|
||||||
const directory = path.join(rootFolder);
|
const directory = path.join(rootFolder)
|
||||||
const items = fs.readdirSync(directory, { withFileTypes: true });
|
const items = fs.readdirSync(directory, { withFileTypes: true })
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
if (item.isDirectory()) {
|
if (item.isDirectory()) {
|
||||||
createNewfolder(destinationRoot, item.name);
|
createNewfolder(destinationRoot, item.name)
|
||||||
iterateFilesAndFolders(path.join(directory, item.name), {
|
iterateFilesAndFolders(path.join(directory, item.name), {
|
||||||
currentFolder: item.name,
|
currentFolder: item.name,
|
||||||
destinationRoot: path.join(destinationRoot, item.name),
|
destinationRoot: path.join(destinationRoot, item.name),
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
const sourceFile = path.join(directory, item.name);
|
const sourceFile = path.join(directory, item.name)
|
||||||
const destinationFile = path.join(destinationRoot, item.name);
|
const destinationFile = path.join(destinationRoot, item.name)
|
||||||
fs.renameSync(sourceFile, destinationFile);
|
fs.renameSync(sourceFile, destinationFile)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const setupTheme = () => {
|
const setupTheme = () => {
|
||||||
const rootFolder = path.join(__dirname, "../");
|
const rootFolder = path.join(__dirname, '../')
|
||||||
|
|
||||||
if (!fs.existsSync(path.join(rootFolder, "exampleSite"))) {
|
if (!fs.existsSync(path.join(rootFolder, 'exampleSite'))) {
|
||||||
// remove this part if you don't using theme demo as a module
|
// remove this part if you don't using theme demo as a module
|
||||||
[
|
;[
|
||||||
{
|
{
|
||||||
filepath: path.join(rootFolder, "config/_default/module.toml"),
|
filepath: path.join(rootFolder, 'config/_default/module.toml'),
|
||||||
regex: /# \[\[imports\]\]\s*\r?\n# path = "([^"]+)"/,
|
regex: /# \[\[imports\]\]\s*\r?\n# path = "([^"]+)"/,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filepath: path.join(rootFolder, "hugo.toml"),
|
filepath: path.join(rootFolder, 'hugo.toml'),
|
||||||
regex: /^.*theme\s*=\s*("[^"\]]+"|\S+)/m,
|
regex: /^.*theme\s*=\s*("[^"\]]+"|\S+)/m,
|
||||||
},
|
},
|
||||||
].forEach(toggleComment);
|
].forEach(toggleComment)
|
||||||
|
|
||||||
const includesFiles = [
|
const includesFiles = [
|
||||||
"tailwind.config.js",
|
'tailwind.config.js',
|
||||||
"postcss.config.js",
|
'postcss.config.js',
|
||||||
"go.mod",
|
'go.mod',
|
||||||
"hugo.toml",
|
'hugo.toml',
|
||||||
"assets",
|
'assets',
|
||||||
"config",
|
'config',
|
||||||
"data",
|
'data',
|
||||||
"content",
|
'content',
|
||||||
"i18n",
|
'i18n',
|
||||||
"static",
|
'static',
|
||||||
];
|
]
|
||||||
|
|
||||||
const folder = createNewfolder(rootFolder, "exampleSite");
|
const folder = createNewfolder(rootFolder, 'exampleSite')
|
||||||
|
|
||||||
fs.readdirSync(rootFolder, { withFileTypes: true }).forEach((file) => {
|
fs.readdirSync(rootFolder, { withFileTypes: true }).forEach((file) => {
|
||||||
if (includesFiles.includes(file.name)) {
|
if (includesFiles.includes(file.name)) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
const destination = path.join(rootFolder, "exampleSite", file.name);
|
const destination = path.join(rootFolder, 'exampleSite', file.name)
|
||||||
fs.mkdirSync(destination, { recursive: true });
|
fs.mkdirSync(destination, { recursive: true })
|
||||||
iterateFilesAndFolders(path.join(rootFolder, file.name), {
|
iterateFilesAndFolders(path.join(rootFolder, file.name), {
|
||||||
destinationRoot: destination,
|
destinationRoot: destination,
|
||||||
});
|
})
|
||||||
deleteFolder(path.join(rootFolder, file.name));
|
deleteFolder(path.join(rootFolder, file.name))
|
||||||
} else {
|
} else {
|
||||||
fs.renameSync(
|
fs.renameSync(path.join(rootFolder, file.name), path.join(folder, file.name))
|
||||||
path.join(rootFolder, file.name),
|
|
||||||
path.join(folder, file.name),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
const themes = path.join(rootFolder, "themes");
|
const themes = path.join(rootFolder, 'themes')
|
||||||
iterateFilesAndFolders(path.join(themes, getFolderName(rootFolder)), {
|
iterateFilesAndFolders(path.join(themes, getFolderName(rootFolder)), {
|
||||||
destinationRoot: rootFolder,
|
destinationRoot: rootFolder,
|
||||||
});
|
})
|
||||||
deleteFolder(themes);
|
deleteFolder(themes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
setupTheme();
|
setupTheme()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue