diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2021-02-06 11:46:47 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-06 11:46:47 +0900 |
| commit | 0e45f10d99589348cc95bd044e9d06bc8dc1a10a (patch) | |
| tree | 9f0c0546840d4354ec2f86eddb7da9d9a8ec3c59 /src/server | |
| parent | discordapp.com → discord.com (#7140) (diff) | |
| download | sharkey-0e45f10d99589348cc95bd044e9d06bc8dc1a10a.tar.gz sharkey-0e45f10d99589348cc95bd044e9d06bc8dc1a10a.tar.bz2 sharkey-0e45f10d99589348cc95bd044e9d06bc8dc1a10a.zip | |
Improve captcha (#7138)
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/api/private/signup.ts | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index 6dc252ac45..3d467a0e68 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -1,7 +1,6 @@ import * as Koa from 'koa'; import { fetchMeta } from '../../../misc/fetch-meta'; -import { verify } from 'hcaptcha'; -import * as recaptcha from 'recaptcha-promise'; +import { verifyHcaptcha, verifyRecaptcha } from '../../../misc/captcha'; import { Users, RegistrationTickets } from '../../../models'; import { signup } from '../common/signup'; @@ -14,26 +13,15 @@ export default async (ctx: Koa.Context) => { // ただしテスト時はこの機構は障害となるため無効にする if (process.env.NODE_ENV !== 'test') { if (instance.enableHcaptcha && instance.hcaptchaSecretKey) { - const success = await verify(instance.hcaptchaSecretKey, body['hcaptcha-response']).then( - ({ success }) => success, - () => false, - ); - - if (!success) { - ctx.throw(400, 'hcaptcha-failed'); - } + await verifyHcaptcha(instance.hcaptchaSecretKey, body['hcaptcha-response']).catch(e => { + ctx.throw(400, e); + }); } if (instance.enableRecaptcha && instance.recaptchaSecretKey) { - recaptcha.init({ - secret_key: instance.recaptchaSecretKey + await verifyRecaptcha(instance.recaptchaSecretKey, body['g-recaptcha-response']).catch(e => { + ctx.throw(400, e); }); - - const success = await recaptcha(body['g-recaptcha-response']); - - if (!success) { - ctx.throw(400, 'recaptcha-failed'); - } } } |