mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
recaptcha: remove, it's not free anymore
This commit is contained in:
4 files changed
-61
No files matched your search
@@ -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;
|
||||
}));
|
||||
@@ -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 = `\
|
||||
<script src="https://recaptcha.net/recaptcha/api.js?render=${SystemModel.get('recaptcha.key')}"></script>
|
||||
<input type="text" name="captcha" id="_captcha" style="display:none">
|
||||
<input type="submit" id="_submit" style="display:none">`;
|
||||
});
|
||||
|
||||
ctx.i18n.load('zh', {
|
||||
'Failed to solve the captcha': '没有通过 ReCaptcha 验证。',
|
||||
});
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
key:
|
||||
type: text
|
||||
secret:
|
||||
type: text
|
||||
Reference in new issue
Block a user