summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-11-07 00:08:21 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-11-07 00:08:21 +0900
commita6f8327aa263022ed5d079f8e413bb17480feb7b (patch)
treee0f75658f50da107627b838b10832764e71c192c /src/server/api
parent10.42.2 (diff)
downloadsharkey-a6f8327aa263022ed5d079f8e413bb17480feb7b.tar.gz
sharkey-a6f8327aa263022ed5d079f8e413bb17480feb7b.tar.bz2
sharkey-a6f8327aa263022ed5d079f8e413bb17480feb7b.zip
reCAPTCHAの設定をDBに保存するように
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/endpoints/admin/update-meta.ts33
-rw-r--r--src/server/api/endpoints/meta.ts22
-rw-r--r--src/server/api/private/signup.ts19
3 files changed, 57 insertions, 17 deletions
diff --git a/src/server/api/endpoints/admin/update-meta.ts b/src/server/api/endpoints/admin/update-meta.ts
index b4b2b231ab..85266b47cf 100644
--- a/src/server/api/endpoints/admin/update-meta.ts
+++ b/src/server/api/endpoints/admin/update-meta.ts
@@ -88,6 +88,27 @@ export const meta = {
desc: {
'ja-JP': 'リモートのファイルをキャッシュするか否か'
}
+ },
+
+ enableRecaptcha: {
+ validator: $.bool.optional,
+ desc: {
+ 'ja-JP': 'reCAPTCHAを使用するか否か'
+ }
+ },
+
+ recaptchaSiteKey: {
+ validator: $.str.optional,
+ desc: {
+ 'ja-JP': 'reCAPTCHA site key'
+ }
+ },
+
+ recaptchaSecretKey: {
+ validator: $.str.optional,
+ desc: {
+ 'ja-JP': 'reCAPTCHA secret key'
+ }
}
}
};
@@ -139,6 +160,18 @@ export default define(meta, (ps) => new Promise(async (res, rej) => {
set.cacheRemoteFiles = ps.cacheRemoteFiles;
}
+ if (ps.enableRecaptcha !== undefined) {
+ set.enableRecaptcha = ps.enableRecaptcha;
+ }
+
+ if (ps.recaptchaSiteKey !== undefined) {
+ set.recaptchaSiteKey = ps.recaptchaSiteKey;
+ }
+
+ if (ps.recaptchaSecretKey !== undefined) {
+ set.recaptchaSecretKey = ps.recaptchaSecretKey;
+ }
+
await Meta.update({}, {
$set: set
}, { upsert: true });
diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts
index e3d3ad520f..3ed225cc5f 100644
--- a/src/server/api/endpoints/meta.ts
+++ b/src/server/api/endpoints/meta.ts
@@ -35,7 +35,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
}
});
- res({
+ const response: any = {
maintainer: config.maintainer,
version: pkg.version,
@@ -60,24 +60,32 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
driveCapacityPerLocalUserMb: instance.localDriveCapacityMb,
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
cacheRemoteFiles: instance.cacheRemoteFiles,
- recaptchaSitekey: config.recaptcha ? config.recaptcha.site_key : null,
+ recaptchaSiteKey: instance.enableRecaptcha ? instance.recaptchaSiteKey : null,
swPublickey: config.sw ? config.sw.public_key : null,
- hidedTags: (me && me.isAdmin) ? instance.hidedTags : undefined,
bannerUrl: instance.bannerUrl,
maxNoteTextLength: instance.maxNoteTextLength,
emojis: emojis,
+ };
- features: ps.detail ? {
+ if (ps.detail) {
+ response.features = {
registration: !instance.disableRegistration,
localTimeLine: !instance.disableLocalTimeline,
elasticsearch: config.elasticsearch ? true : false,
- recaptcha: config.recaptcha ? true : false,
+ recaptcha: instance.enableRecaptcha,
objectStorage: config.drive && config.drive.storage === 'minio',
twitter: config.twitter ? true : false,
github: config.github ? true : false,
serviceWorker: config.sw ? true : false,
userRecommendation: config.user_recommendation ? config.user_recommendation : {}
- } : undefined
- });
+ };
+ }
+
+ if (me && me.isAdmin) {
+ response.hidedTags = instance.hidedTags;
+ response.recaptchaSecretKey = instance.recaptchaSecretKey;
+ }
+
+ res(response);
}));
diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts
index eefffd8554..3a367ff119 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 * 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;