Add support for hCaptcha
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as Koa from 'koa';
|
||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||
import { verify } from 'hcaptcha';
|
||||
import * as recaptcha from 'recaptcha-promise';
|
||||
import { Users, RegistrationTickets } from '../../../models';
|
||||
import { signup } from '../common/signup';
|
||||
@@ -9,8 +10,18 @@ export default async (ctx: Koa.Context) => {
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
// Verify recaptcha
|
||||
// Verify *Captcha
|
||||
// ただしテスト時はこの機構は障害となるため無効にする
|
||||
if (process.env.NODE_ENV !== 'test' && instance.enableHcaptcha && instance.hcaptchaSecretKey) {
|
||||
const success = await verify(instance.hcaptchaSecretKey, body['hcaptcha-response']).then(
|
||||
({ 'error-codes': x }) => !x || !x.length,
|
||||
() => false,
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
ctx.throw(400, 'hcaptcha-failed');
|
||||
}
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'test' && instance.enableRecaptcha && instance.recaptchaSecretKey) {
|
||||
recaptcha.init({
|
||||
secret_key: instance.recaptchaSecretKey
|
||||
|
Reference in New Issue
Block a user