reCAPTCHAをオプションに

This commit is contained in:
syuilo 2018-07-19 00:04:09 +09:00
parent 532f8f8e4c
commit efaa41ba49
7 changed files with 35 additions and 30 deletions

View file

@ -41,10 +41,6 @@ redis:
port: 6379 port: 6379
pass: example-pass pass: example-pass
recaptcha:
site_key: example-site-key
secret_key: example-secret-key
# If enabled: # If enabled:
# Server will not cache remote files (Using direct link instead). # Server will not cache remote files (Using direct link instead).
# You can save your storage. # You can save your storage.
@ -67,6 +63,11 @@ preventCache: false
# port: 9200 # port: 9200
# pass: null # pass: null
# reCAPTCHA
# recaptcha:
# site_key: example-site-key
# secret_key: example-secret-key
# ServiceWorker # ServiceWorker
# sw: # sw:
# # Public key of VAPID # # Public key of VAPID

View file

@ -48,9 +48,9 @@ In root :
4. `git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)` Checkout to the [latest release](https://github.com/syuilo/misskey/releases/latest) 4. `git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)` Checkout to the [latest release](https://github.com/syuilo/misskey/releases/latest)
5. `npm install` Install misskey dependencies. 5. `npm install` Install misskey dependencies.
*5.* reCAPTCHA tokens *(optional)* reCAPTCHA tokens
---------------------------------------------------------------- ----------------------------------------------------------------
Misskey requires reCAPTCHA tokens. If you want to enable reCAPTCHA, you need to generate reCAPTCHA tokens:
Please visit https://www.google.com/recaptcha/intro/ and generate keys. Please visit https://www.google.com/recaptcha/intro/ and generate keys.
*(optional)* Generating VAPID keys *(optional)* Generating VAPID keys
@ -63,13 +63,12 @@ npm install web-push -g
web-push generate-vapid-keys web-push generate-vapid-keys
``` ```
*5.* Make configuration file
*6.* Make configuration file
---------------------------------------------------------------- ----------------------------------------------------------------
1. `cp .config/example.yml .config/default.yml` Copy the `.config/example.yml` and rename it to `default.yml`. 1. `cp .config/example.yml .config/default.yml` Copy the `.config/example.yml` and rename it to `default.yml`.
2. Edit `default.yml` 2. Edit `default.yml`
*7.* Build Misskey *6.* Build Misskey
---------------------------------------------------------------- ----------------------------------------------------------------
Build misskey with the following: Build misskey with the following:
@ -85,7 +84,7 @@ If you're still encountering errors about some modules, use node-gyp:
3. `node-gyp build` 3. `node-gyp build`
4. `npm run build` 4. `npm run build`
*8.* That is it. *7.* That is it.
---------------------------------------------------------------- ----------------------------------------------------------------
Well done! Now, you have an environment that run to Misskey. Well done! Now, you have an environment that run to Misskey.

View file

@ -47,10 +47,10 @@ adduser --disabled-password --disabled-login misskey
4. `git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)` [最新のリリース](https://github.com/syuilo/misskey/releases/latest)を確認 4. `git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)` [最新のリリース](https://github.com/syuilo/misskey/releases/latest)を確認
5. `npm install` Misskeyの依存パッケージをインストール 5. `npm install` Misskeyの依存パッケージをインストール
*5.* reCAPTCHAトークン *(オプション)* reCAPTCHAトークン
---------------------------------------------------------------- ----------------------------------------------------------------
MisskeyはreCAPTCHAトークンを必要とします。 reCAPTCHAを有効にする場合、reCAPTCHAトークンを取得する必要があります。
https://www.google.com/recaptcha/intro/ にアクセスしてトークンを生成してください。 https://www.google.com/recaptcha/intro/ にアクセスしてトークンを取得してください。
*(オプション)* VAPIDキーペアの生成 *(オプション)* VAPIDキーペアの生成
---------------------------------------------------------------- ----------------------------------------------------------------
@ -61,12 +61,12 @@ npm install web-push -g
web-push generate-vapid-keys web-push generate-vapid-keys
``` ```
*6.* Make configuration file *5.* 設定ファイルを作成する
---------------------------------------------------------------- ----------------------------------------------------------------
1. `cp .config/example.yml .config/default.yml` `.config/example.yml`をコピーし名前を`default.yml`にする。 1. `cp .config/example.yml .config/default.yml` `.config/example.yml`をコピーし名前を`default.yml`にする。
2. `default.yml` を編集する。 2. `default.yml` を編集する。
*7.* Misskeyのビルド *6.* Misskeyのビルド
---------------------------------------------------------------- ----------------------------------------------------------------
次のコマンドでMisskeyをビルドしてください: 次のコマンドでMisskeyをビルドしてください:
@ -81,8 +81,7 @@ Debianをお使いであれば、`build-essential`パッケージをインスト
3. `node-gyp build` 3. `node-gyp build`
4. `npm run build` 4. `npm run build`
*7.* 以上です!
*6.* 以上です!
---------------------------------------------------------------- ----------------------------------------------------------------
お疲れ様でした。これでMisskeyを動かす準備は整いました。 お疲れ様でした。これでMisskeyを動かす準備は整いました。

View file

@ -29,7 +29,7 @@
<p slot="text" v-if="passwordRetypeState == 'not-match'" style="color:#FF1161">%fa:exclamation-triangle .fw% %i18n:@password-not-matched%</p> <p slot="text" v-if="passwordRetypeState == 'not-match'" style="color:#FF1161">%fa:exclamation-triangle .fw% %i18n:@password-not-matched%</p>
</div> </div>
</ui-input> </ui-input>
<div class="g-recaptcha" :data-sitekey="recaptchaSitekey" style="margin: 16px 0;"></div> <div v-if="recaptchaSitekey != null" class="g-recaptcha" :data-sitekey="recaptchaSitekey" style="margin: 16px 0;"></div>
<label class="agree-tou" style="display: block; margin: 16px 0;"> <label class="agree-tou" style="display: block; margin: 16px 0;">
<input name="agree-tou" type="checkbox" required/> <input name="agree-tou" type="checkbox" required/>
<p><a :href="touUrl" target="_blank">利用規約</a>に同意する</p> <p><a :href="touUrl" target="_blank">利用規約</a>に同意する</p>
@ -115,7 +115,7 @@ export default Vue.extend({
(this as any).api('signup', { (this as any).api('signup', {
username: this.username, username: this.username,
password: this.password, password: this.password,
'g-recaptcha-response': (window as any).grecaptcha.getResponse() 'g-recaptcha-response': recaptchaSitekey != null ? (window as any).grecaptcha.getResponse() : null
}).then(() => { }).then(() => {
(this as any).api('signin', { (this as any).api('signin', {
username: this.username, username: this.username,
@ -126,16 +126,20 @@ export default Vue.extend({
}).catch(() => { }).catch(() => {
alert('%i18n:@some-error%'); alert('%i18n:@some-error%');
if (recaptchaSitekey != null) {
(window as any).grecaptcha.reset(); (window as any).grecaptcha.reset();
}
}); });
} }
}, },
mounted() { mounted() {
if (recaptchaSitekey != null) {
const head = document.getElementsByTagName('head')[0]; const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('src', 'https://www.google.com/recaptcha/api.js'); script.setAttribute('src', 'https://www.google.com/recaptcha/api.js');
head.appendChild(script); head.appendChild(script);
} }
}
}); });
</script> </script>

View file

@ -40,7 +40,7 @@ export type Source = {
port: number; port: number;
pass: string; pass: string;
}; };
recaptcha: { recaptcha?: {
site_key: string; site_key: string;
secret_key: string; secret_key: string;
}; };

View file

@ -7,14 +7,16 @@ import generateUserToken from '../common/generate-native-user-token';
import config from '../../../config'; import config from '../../../config';
import Meta from '../../../models/meta'; import Meta from '../../../models/meta';
recaptcha.init({ if (config.recaptcha) {
recaptcha.init({
secret_key: config.recaptcha.secret_key secret_key: config.recaptcha.secret_key
}); });
}
export default async (ctx: Koa.Context) => { export default async (ctx: Koa.Context) => {
// Verify recaptcha // Verify recaptcha
// ただしテスト時はこの機構は障害となるため無効にする // ただしテスト時はこの機構は障害となるため無効にする
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test' && config.recaptcha != null) {
const success = await recaptcha(ctx.request.body['g-recaptcha-response']); const success = await recaptcha(ctx.request.body['g-recaptcha-response']);
if (!success) { if (!success) {

View file

@ -72,7 +72,7 @@ const output = {
//#region Define consts //#region Define consts
const consts = { const consts = {
_RECAPTCHA_SITEKEY_: config.recaptcha.site_key, _RECAPTCHA_SITEKEY_: config.recaptcha ? config.recaptcha.site_key : null,
_SW_PUBLICKEY_: config.sw ? config.sw.public_key : null, _SW_PUBLICKEY_: config.sw ? config.sw.public_key : null,
_THEME_COLOR_: constants.themeColor, _THEME_COLOR_: constants.themeColor,
_COPYRIGHT_: constants.copyright, _COPYRIGHT_: constants.copyright,