reCAPTCHAの設定をDBに保存するように

This commit is contained in:
syuilo 2018-11-07 00:08:21 +09:00
parent d5ab6b41c9
commit a6f8327aa2
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
10 changed files with 99 additions and 36 deletions

View file

@ -1,7 +1,6 @@
import * as Koa from 'koa';
import * as bcrypt from 'bcryptjs';
import { generate as generateKeypair } from '../../../crypto_key';
const recaptcha = require('recaptcha-promise');
import User, { IUser, validateUsername, validatePassword, pack } from '../../../models/user';
import generateUserToken from '../common/generate-native-user-token';
import config from '../../../config';
@ -10,18 +9,20 @@ import RegistrationTicket from '../../../models/registration-tickets';
import usersChart from '../../../chart/users';
import fetchMeta from '../../../misc/fetch-meta';
if (config.recaptcha) {
recaptcha.init({
secret_key: config.recaptcha.secret_key
});
}
export default async (ctx: Koa.Context) => {
const body = ctx.request.body as any;
const instance = await fetchMeta();
const recaptcha = require('recaptcha-promise');
// Verify recaptcha
// ただしテスト時はこの機構は障害となるため無効にする
if (process.env.NODE_ENV !== 'test' && config.recaptcha != null) {
if (process.env.NODE_ENV !== 'test' && instance.enableRecaptcha) {
recaptcha.init({
secret_key: instance.recaptchaSecretKey
});
const success = await recaptcha(body['g-recaptcha-response']);
if (!success) {
@ -34,8 +35,6 @@ export default async (ctx: Koa.Context) => {
const password = body['password'];
const invitationCode = body['invitationCode'];
const instance = await fetchMeta();
if (instance && instance.disableRegistration) {
if (invitationCode == null || typeof invitationCode != 'string') {
ctx.status = 400;