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

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

View file

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

View file

@ -7,14 +7,16 @@ import generateUserToken from '../common/generate-native-user-token';
import config from '../../../config';
import Meta from '../../../models/meta';
recaptcha.init({
secret_key: config.recaptcha.secret_key
});
if (config.recaptcha) {
recaptcha.init({
secret_key: config.recaptcha.secret_key
});
}
export default async (ctx: Koa.Context) => {
// 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']);
if (!success) {