From f236af555b48dde8a011042de6bb3295e613ecb4 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 19 Apr 2021 13:15:22 +0800 Subject: [PATCH] recaptcha: add friendy hint --- packages/recaptcha/handler.ts | 5 +++-- packages/recaptcha/locale/zh.yaml | 1 + packages/recaptcha/package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 packages/recaptcha/locale/zh.yaml diff --git a/packages/recaptcha/handler.ts b/packages/recaptcha/handler.ts index 376460672..553e13fcd 100644 --- a/packages/recaptcha/handler.ts +++ b/packages/recaptcha/handler.ts @@ -1,10 +1,11 @@ import superagent from 'superagent'; -import { ValidationError } from 'hydrooj/dist/error'; +import { ValidationError, ForbiddenError } from 'hydrooj/dist/error'; import { PRIV } from 'hydrooj/dist/model/builtin'; import * as system from 'hydrooj/dist/model/system'; import * as bus from 'hydrooj/dist/service/bus'; bus.on('handler/before/UserRegister', async (thisArg) => { + if (!system.get('recaptcha.key')) return; if (thisArg.request.method !== 'post') { thisArg.UiContext.recaptchaKey = system.get('recaptcha.key'); return; @@ -15,7 +16,7 @@ bus.on('handler/before/UserRegister', async (thisArg) => { .field('secret', system.get('recaptcha.secret')) .field('response', thisArg.args.captcha) .field('remoteip', thisArg.request.ip); - if (!response.body.success) throw new ValidationError('captcha fail'); + if (!response.body.success) throw new ForbiddenError('captcha fail'); }); bus.on('handler/after/UserRegister', async (thisArg) => { diff --git a/packages/recaptcha/locale/zh.yaml b/packages/recaptcha/locale/zh.yaml new file mode 100644 index 000000000..8979369c9 --- /dev/null +++ b/packages/recaptcha/locale/zh.yaml @@ -0,0 +1 @@ +captcha fail: 您没有通过 Recaptcha 验证。 \ No newline at end of file diff --git a/packages/recaptcha/package.json b/packages/recaptcha/package.json index cabd8e370..501b51cb6 100644 --- a/packages/recaptcha/package.json +++ b/packages/recaptcha/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/recaptcha", - "version": "1.0.2", + "version": "1.0.3", "description": "Google reCAPTCHA", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git",