Captcha appearance and layout changes

merge-requests/208/head
Thomas Lynch 4 years ago
parent 1a6307482e
commit f192a0e09c
  1. 4
      .gitignore
  2. 4
      gulp/res/css/nscaptcha.css
  3. 20
      gulp/res/css/style.css
  4. 4
      gulp/res/js/captcha.js
  5. 2
      gulp/res/js/captchaformsection.js
  6. 14
      gulpfile.js
  7. 2
      models/pages/captcha.js
  8. 1
      views/includes/captcha.pug
  9. 4
      views/pages/bypass.pug

4
.gitignore vendored

@ -6,8 +6,8 @@ static/*
gulp/res/js/socket.io.js gulp/res/js/socket.io.js
views/custompages/*.pug views/custompages/*.pug
/gulp/res/css/codethemes /gulp/res/css/codethemes
gulp/res/js/timezone.js gulp/res/css/locals.css
gulp/res/js/themelist.js gulp/res/js/locals.js
gulp/res/js/post.js gulp/res/js/post.js
gulp/res/js/modal.js gulp/res/js/modal.js
tmp/ tmp/

@ -1,6 +1,6 @@
img { img {
width: 200px; width: var(--captcha-w);
height: 200px; height: var(--captcha-h);
image-rendering: crisp-edges; image-rendering: crisp-edges;
margin: 0 auto; margin: 0 auto;
} }

@ -1,7 +1,3 @@
table, img, .label, .pages, .catalog-tile, .post-container, .stickynav, .toggle-summary, .postform-style, input[type="button"], input[type="file"], input[type="number"], input[type="password"], input[type="range"], input[type="submit"], input[type="text"], select, textarea {
border-radius: 2px!important;
}
body { body {
font-family: arial, helvetica, sans-serif; font-family: arial, helvetica, sans-serif;
font-size: 10pt; font-size: 10pt;
@ -1073,19 +1069,23 @@ input[type="file"] {
iframe.captcha, iframe.bypass { iframe.captcha, iframe.bypass {
/*dumb hack cos of noscript wrapping in unstyleable span*/ /*dumb hack cos of noscript wrapping in unstyleable span*/
margin-bottom: -2px; /*margin-bottom: -2px;*/
}
iframe.captcha {
width: 100%;
} }
iframe.bypass { iframe.bypass {
height: var(--bypass-height); height: var(--bypass-height);
width: 450px; width: 350px;
} }
.captcha { .captcha {
border: 1px solid var(--input-borders); border: 1px solid var(--input-borders);
background: white; background: white;
margin-bottom: 1px; margin-bottom: 1px;
width: var(--captcha-w); min-width: var(--captcha-w);
height: var(--captcha-h); height: var(--captcha-h);
box-sizing: border-box; box-sizing: border-box;
object-fit: contain; object-fit: contain;
@ -1245,7 +1245,6 @@ row.wrap.sb .col {
@media only screen and (max-width: 600px) { @media only screen and (max-width: 600px) {
.postmenu { .postmenu {
border-left: .5em solid transparent; border-left: .5em solid transparent;
border-right: .5em solid transparent; border-right: .5em solid transparent;
@ -1311,6 +1310,7 @@ row.wrap.sb .col {
iframe.bypass { iframe.bypass {
height: 100vh; height: 100vh;
width: 100%;
} }
.file-thumb { .file-thumb {
@ -1395,6 +1395,10 @@ row.wrap.sb .col {
width: 100%; width: 100%;
} }
input#file {
width: 100%;
}
} }
.flag { .flag {

@ -74,14 +74,14 @@ class CaptchaController {
captchaDiv.style.display = ''; captchaDiv.style.display = '';
captchaImg.style.margin = '0 auto'; captchaImg.style.margin = '0 auto';
captchaImg.style.display = 'flex'; captchaImg.style.display = 'flex';
captchaImg.style.width = '100%'; //captchaImg.style.width = '100%';
refreshDiv.classList.add('captcharefresh', 'noselect'); refreshDiv.classList.add('captcharefresh', 'noselect');
refreshDiv.addEventListener('click', (e) => this.refreshCaptchas(e), true); refreshDiv.addEventListener('click', (e) => this.refreshCaptchas(e), true);
refreshDiv.textContent = '↻'; refreshDiv.textContent = '↻';
field.placeholder = 'loading'; field.placeholder = 'loading';
captchaImg.src = '/captcha'; captchaImg.src = '/captcha';
captchaImg.onload = function() { captchaImg.onload = function() {
field.placeholder = ''; field.placeholder = 'Captcha text';
captchaDiv.appendChild(captchaImg); captchaDiv.appendChild(captchaImg);
captchaDiv.appendChild(refreshDiv); captchaDiv.appendChild(refreshDiv);
} }

@ -9,7 +9,7 @@ var block = (this && this.block), attributes = (this && this.attributes) || {};
pug_html = pug_html + "\u003Cdetails class=\"row label mr-0\"\u003E\u003Csummary class=\"pv-5\"\u003ECaptcha\u003Cspan class=\"required\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fsummary\u003E"; pug_html = pug_html + "\u003Cdetails class=\"row label mr-0\"\u003E\u003Csummary class=\"pv-5\"\u003ECaptcha\u003Cspan class=\"required\"\u003E*\u003C\u002Fspan\u003E\u003C\u002Fsummary\u003E";
switch (captchaType){ switch (captchaType){
case 'google': case 'google':
pug_html = pug_html + "\u003Cdiv" + (" class=\"g-recaptcha\""+pug_attr("data-sitekey", `${googleRecaptchaSiteKey}`, true, false)+" data-theme=\"dark\" data-size=\"compact\" data-callback=\"recaptchaCallback\"") + "\u003E\u003C\u002Fdiv\u003E"; pug_html = pug_html + "\u003Cdiv" + (" class=\"g-recaptcha\""+pug_attr("data-sitekey", `${googleRecaptchaSiteKey}`, true, false)+" data-theme=\"dark\" data-size=\"compact\" data-callback=\"recaptchaCallback\"") + "\u003E\u003C\u002Fdiv\u003E\u003Cnoscript\u003EPlease enable JavaScript to solve the captcha.\u003C\u002Fnoscript\u003E";
break; break;
case 'text': case 'text':
pug_html = pug_html + "\u003Cnoscript class=\"no-m-p\"\u003E\u003Ciframe" + (" class=\"captcha\""+" src=\"\u002Fcaptcha.html\""+pug_attr("width=210", true, true, false)+" height=\"80\" scrolling=\"no\" loading=\"lazy\"") + "\u003E\u003C\u002Fiframe\u003E\u003C\u002Fnoscript\u003E\u003Cdiv class=\"jsonly captcha\" style=\"display:none;\"\u003E\u003C\u002Fdiv\u003E\u003Cinput" + (" class=\"captchafield\""+" type=\"text\" name=\"captcha\" autocomplete=\"off\" placeholder=\"Captcha text\" pattern=\".{6}\""+pug_attr("required", true, true, false)+" title=\"6 characters\"") + "\u002F\u003E"; pug_html = pug_html + "\u003Cnoscript class=\"no-m-p\"\u003E\u003Ciframe" + (" class=\"captcha\""+" src=\"\u002Fcaptcha.html\""+pug_attr("width=210", true, true, false)+" height=\"80\" scrolling=\"no\" loading=\"lazy\"") + "\u003E\u003C\u002Fiframe\u003E\u003C\u002Fnoscript\u003E\u003Cdiv class=\"jsonly captcha\" style=\"display:none;\"\u003E\u003C\u002Fdiv\u003E\u003Cinput" + (" class=\"captchafield\""+" type=\"text\" name=\"captcha\" autocomplete=\"off\" placeholder=\"Captcha text\" pattern=\".{6}\""+pug_attr("required", true, true, false)+" title=\"6 characters\"") + "\u002F\u003E";

@ -138,13 +138,19 @@ async function css() {
let bypassHeight = configs.captchaOptions.type === 'google' ? 500 let bypassHeight = configs.captchaOptions.type === 'google' ? 500
: configs.captchaOptions.type === 'grid' ? 330 : configs.captchaOptions.type === 'grid' ? 330
: 235; : 235;
let captchaHeight = configs.captchaOptions.type === 'text' ? 80
: configs.captchaOptions.type === 'grid' ? configs.captchaOptions.grid.imageSize+30
: 200; //'google' doesnt need this set
let captchaWidth = configs.captchaOptions.type === 'text' ? 210
: configs.captchaOptions.type === 'grid' ? configs.captchaOptions.grid.imageSize+30
: 200; //'google' doesnt need this set
const cssLocals = `:root { const cssLocals = `:root {
--attachment-img: url('/file/attachment.png'); --attachment-img: url('/file/attachment.png');
--spoiler-img: url('/file/spoiler.png'); --spoiler-img: url('/file/spoiler.png');
--audio-img: url('/file/audio.png'); --audio-img: url('/file/audio.png');
--thumbnail-size: ${configs.thumbSize}px; --thumbnail-size: ${configs.thumbSize}px;
--captcha-w: 200px; --captcha-w: ${captchaWidth}px;
--captcha-h: 200px; --captcha-h: ${captchaHeight}px;
--bypass-height: ${bypassHeight}px; --bypass-height: ${bypassHeight}px;
}`; }`;
fs.writeFileSync('gulp/res/css/locals.css', cssLocals); fs.writeFileSync('gulp/res/css/locals.css', cssLocals);
@ -168,8 +174,10 @@ async function css() {
.pipe(cleanCSS()) .pipe(cleanCSS())
.pipe(gulp.dest(`${paths.styles.dest}/codethemes/`)); .pipe(gulp.dest(`${paths.styles.dest}/codethemes/`));
await gulp.src([ await gulp.src([
`${paths.styles.src}/locals.css`,
`${paths.styles.src}/nscaptcha.css`, `${paths.styles.src}/nscaptcha.css`,
]) ])
.pipe(concat('nscaptcha.css'))
.pipe(less()) .pipe(less())
.pipe(cleanCSS()) .pipe(cleanCSS())
.pipe(gulp.dest(paths.styles.dest)); .pipe(gulp.dest(paths.styles.dest));
@ -264,6 +272,8 @@ const SERVER_TIMEZONE = '${Intl.DateTimeFormat().resolvedOptions().timeZone}';`;
`!${paths.scripts.src}/yous.js`, `!${paths.scripts.src}/yous.js`,
`!${paths.scripts.src}/catalog.js`, `!${paths.scripts.src}/catalog.js`,
`!${paths.scripts.src}/time.js`, `!${paths.scripts.src}/time.js`,
`!${paths.scripts.src}/themelist.js`, //dont include files from my fuck up with git. todo: make this a migration?
`!${paths.scripts.src}/timezone.js`,
]) ])
.pipe(concat('all.js')) .pipe(concat('all.js'))
.pipe(uglify({compress:false})) .pipe(uglify({compress:false}))

@ -2,7 +2,7 @@
const { Captchas, Ratelimits } = require(__dirname+'/../../db/') const { Captchas, Ratelimits } = require(__dirname+'/../../db/')
, { secureCookies, rateLimitCost, captchaOptions } = require(__dirname+'/../../configs/main.js') , { secureCookies, rateLimitCost, captchaOptions } = require(__dirname+'/../../configs/main.js')
, generateCaptcha = require(__dirname+`/../../helpers/captcha/generators/${captchaOptions.type}.js`) , generateCaptcha = captchaOptions.type !== 'google' ? require(__dirname+`/../../helpers/captcha/generators/${captchaOptions.type}.js`) : null
, production = process.env.NODE_ENV === 'production'; , production = process.env.NODE_ENV === 'production';
module.exports = async (req, res, next) => { module.exports = async (req, res, next) => {

@ -1,6 +1,7 @@
case captchaType case captchaType
when 'google' when 'google'
div(class="g-recaptcha" data-sitekey=`${googleRecaptchaSiteKey}` data-theme="dark" data-size="compact" data-callback="recaptchaCallback") div(class="g-recaptcha" data-sitekey=`${googleRecaptchaSiteKey}` data-theme="dark" data-size="compact" data-callback="recaptchaCallback")
noscript Please enable JavaScript to solve the captcha.
when 'text' when 'text'
noscript.no-m-p noscript.no-m-p
iframe.captcha(src='/captcha.html' 'width=210' height='80' scrolling='no' loading='lazy') iframe.captcha(src='/captcha.html' 'width=210' height='80' scrolling='no' loading='lazy')

@ -7,7 +7,9 @@ block content
h1.board-title Block Bypass h1.board-title Block Bypass
.form-wrapper.flex-center.mv-10 .form-wrapper.flex-center.mv-10
form.form-post(action='/forms/blockbypass' method='POST' data-captcha-preload='true') form.form-post(action='/forms/blockbypass' method='POST' data-captcha-preload='true')
include ../includes/captcha.pug .row
.col
include ../includes/captcha.pug
if minimal if minimal
input(type='hidden' name='minimal' value='1') input(type='hidden' name='minimal' value='1')
input(type='submit', value='Submit') input(type='submit', value='Submit')

Loading…
Cancel
Save