diff --git a/packages/recaptcha/frontend/captcha-main.page.js b/packages/recaptcha/frontend/captcha-main.page.js deleted file mode 100644 index 8f016d9cc..000000000 --- a/packages/recaptcha/frontend/captcha-main.page.js +++ /dev/null @@ -1,16 +0,0 @@ -import { addPage, NamedPage } from '@hydrooj/ui-default'; -/* global grecaptcha */ - -addPage(new NamedPage('user_register', () => { - function captcha(event) { - event.preventDefault(); - grecaptcha.ready(() => { - grecaptcha.execute(UiContext.recaptchaKey, { action: 'submit' }).then((token) => { - document.getElementById('_captcha').value = token; - document.getElementById('_submit').click(); - }); - }); - } - const element = document.getElementById('submit'); - if (element) element.onclick = captcha; -})); diff --git a/packages/recaptcha/index.ts b/packages/recaptcha/index.ts deleted file mode 100644 index aa3868aa4..000000000 --- a/packages/recaptcha/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - Context, ForbiddenError, PRIV, superagent, SystemModel, ValidationError, -} from 'hydrooj'; - -export function apply(ctx: Context) { - ctx.on('handler/before/UserRegister', async (thisArg) => { - if (!SystemModel.get('recaptcha.key')) return; - if (thisArg.request.method !== 'post') { - thisArg.UiContext.recaptchaKey = SystemModel.get('recaptcha.key'); - return; - } - if (thisArg.user.hasPriv(PRIV.PRIV_UNLIMITED_ACCESS)) return; - if (!thisArg.args.captcha) throw new ValidationError('captcha'); - const response = await superagent.post('https://recaptcha.net/recaptcha/api/siteverify') - .field('secret', SystemModel.get('recaptcha.secret')) - .field('response', thisArg.args.captcha) - .field('remoteip', thisArg.request.ip); - if (!response.body.success) throw new ForbiddenError('Failed to solve the captcha.'); - }); - - ctx.on('handler/after/UserRegister', async (thisArg) => { - thisArg.response.body.captcha = `\ - - -`; - }); - - ctx.i18n.load('zh', { - 'Failed to solve the captcha': '没有通过 ReCaptcha 验证。', - }); -} diff --git a/packages/recaptcha/package.json b/packages/recaptcha/package.json deleted file mode 100644 index 2f3eee221..000000000 --- a/packages/recaptcha/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@hydrooj/recaptcha", - "version": "1.2.0", - "description": "Google reCAPTCHA", - "main": "index.ts", - "repository": "https://github.com/hydro-dev/Hydro.git", - "author": "undefined", - "license": "AGPL-3.0-or-later", - "preferUnplugged": true -} diff --git a/packages/recaptcha/setting.yaml b/packages/recaptcha/setting.yaml deleted file mode 100644 index ccb745706..000000000 --- a/packages/recaptcha/setting.yaml +++ /dev/null @@ -1,4 +0,0 @@ -key: - type: text -secret: - type: text \ No newline at end of file