From ecb27a1ea0e5d7f317891418ac154c0d34e19b12 Mon Sep 17 00:00:00 2001 From: HF Date: Sat, 16 May 2020 10:45:14 +0200 Subject: [PATCH] change captcha remove noauthUser, which was just confusing remove rest of api/pixel --- src/client.js | 26 ++++ src/components/App.jsx | 2 - src/components/Html.jsx | 29 ++--- src/components/ReCaptcha.jsx | 47 ------- src/core/config.js | 6 +- src/core/isProxy.js | 9 +- src/core/passport.js | 8 +- src/data/models/User.js | 6 +- src/routes/admintools.js | 2 +- src/routes/api/auth/register.js | 4 +- src/routes/api/captcha.js | 42 +----- src/routes/api/index.js | 58 ++++----- src/routes/api/me.js | 2 +- src/routes/api/pixel.js | 224 -------------------------------- src/socket/APISocketServer.js | 2 +- src/socket/ProtocolClient.js | 8 +- src/socket/SocketServer.js | 42 ++---- src/socket/verifyClient.js | 23 +--- src/utils/captcha.js | 103 +++++++++++++++ src/utils/ip.js | 9 +- src/utils/recaptcha.js | 50 ------- 21 files changed, 216 insertions(+), 486 deletions(-) delete mode 100644 src/components/ReCaptcha.jsx delete mode 100644 src/routes/api/pixel.js create mode 100644 src/utils/captcha.js delete mode 100644 src/utils/recaptcha.js diff --git a/src/client.js b/src/client.js index 1222fbe..43367da 100644 --- a/src/client.js +++ b/src/client.js @@ -19,6 +19,7 @@ import { receiveChatHistory, receivePixelReturn, setMobile, + tryPlacePixel, } from './actions'; import store from './ui/store'; @@ -116,3 +117,28 @@ document.addEventListener('DOMContentLoaded', () => { } setInterval(runGC, 300000); }); + + +// on captcha received +// TODO: this really isn't beautiful +window.onCaptcha = async function onCaptcha(token: string) { + const body = JSON.stringify({ + token, + }); + await fetch('/api/captcha', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body, + // https://github.com/github/fetch/issues/349 + credentials: 'include', + }); + + const { + i, j, offset, color, + } = window.pixel; + store.dispatch(tryPlacePixel(i, j, offset, color)); + + window.grecaptcha.reset(); +}; diff --git a/src/components/App.jsx b/src/components/App.jsx index 5e07c0a..e2a2819 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -18,7 +18,6 @@ import ChatButton from './ChatButton'; import ChatBox from './ChatBox'; import Menu from './Menu'; import UI from './UI'; -import ReCaptcha from './ReCaptcha'; import ExpandMenuButton from './ExpandMenuButton'; import MinecraftTPButton from './MinecraftTPButton'; import ModalRoot from './ModalRoot'; @@ -27,7 +26,6 @@ const App = () => (