mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
recaptcha: add friendy hint
This commit is contained in:
1 parent
87d8dce528
commit
f236af555b
3 files changed
+5
-3
No files matched your search
@@ -1,10 +1,11 @@
|
|||||||
import superagent from 'superagent';
|
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 { PRIV } from 'hydrooj/dist/model/builtin';
|
||||||
import * as system from 'hydrooj/dist/model/system';
|
import * as system from 'hydrooj/dist/model/system';
|
||||||
import * as bus from 'hydrooj/dist/service/bus';
|
import * as bus from 'hydrooj/dist/service/bus';
|
||||||
|
|
||||||
bus.on('handler/before/UserRegister', async (thisArg) => {
|
bus.on('handler/before/UserRegister', async (thisArg) => {
|
||||||
|
if (!system.get('recaptcha.key')) return;
|
||||||
if (thisArg.request.method !== 'post') {
|
if (thisArg.request.method !== 'post') {
|
||||||
thisArg.UiContext.recaptchaKey = system.get('recaptcha.key');
|
thisArg.UiContext.recaptchaKey = system.get('recaptcha.key');
|
||||||
return;
|
return;
|
||||||
@@ -15,7 +16,7 @@ bus.on('handler/before/UserRegister', async (thisArg) => {
|
|||||||
.field('secret', system.get('recaptcha.secret'))
|
.field('secret', system.get('recaptcha.secret'))
|
||||||
.field('response', thisArg.args.captcha)
|
.field('response', thisArg.args.captcha)
|
||||||
.field('remoteip', thisArg.request.ip);
|
.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) => {
|
bus.on('handler/after/UserRegister', async (thisArg) => {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
captcha fail: 您没有通过 Recaptcha 验证。
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/recaptcha",
|
"name": "@hydrooj/recaptcha",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"description": "Google reCAPTCHA",
|
"description": "Google reCAPTCHA",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user