Refactor codes
This commit is contained in:
parent
b862c055ae
commit
9daa900793
|
@ -40,20 +40,12 @@ export default Vue.extend({
|
||||||
if (window.hcaptcha) { // loaded
|
if (window.hcaptcha) { // loaded
|
||||||
this.available = true;
|
this.available = true;
|
||||||
} else {
|
} else {
|
||||||
const alreadyLoading = document.getElementById('hcaptcha');
|
(document.getElementById('hcaptcha') || (x => document.head.appendChild(Object.assign(x, {
|
||||||
|
async: true,
|
||||||
if (alreadyLoading) { // loading
|
id: 'hcaptcha',
|
||||||
alreadyLoading.addEventListener('load', () => this.available = true);
|
src: 'https://hcaptcha.com/1/api.js?render=explicit',
|
||||||
|
})))(document.createElement('script')))
|
||||||
return;
|
.addEventListener('load', () => this.available = true);
|
||||||
} // init
|
|
||||||
|
|
||||||
const script = document.createElement('script');
|
|
||||||
script.addEventListener('load', () => this.available = true);
|
|
||||||
script.async = true;
|
|
||||||
script.id = 'hcaptcha';
|
|
||||||
script.src = 'https://hcaptcha.com/1/api.js?render=explicit';
|
|
||||||
document.head.appendChild(script);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -371,11 +371,10 @@ export default Vue.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recaptchaLoaded) { // loaded
|
if (recaptchaLoaded) { // loaded
|
||||||
delete window.onRecaptchaLoad;
|
|
||||||
renderRecaptchaPreview();
|
renderRecaptchaPreview();
|
||||||
} else { // init
|
} else { // init
|
||||||
window.onRecaptchaLoad = () => {
|
window.onRecaptchaLoad = () => {
|
||||||
recaptchaLoaded = true;
|
recaptchaLoaded = delete window.onRecaptchaLoad;
|
||||||
renderRecaptchaPreview();
|
renderRecaptchaPreview();
|
||||||
};
|
};
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default async (ctx: Koa.Context) => {
|
||||||
// ただしテスト時はこの機構は障害となるため無効にする
|
// ただしテスト時はこの機構は障害となるため無効にする
|
||||||
if (process.env.NODE_ENV !== 'test' && instance.enableHcaptcha && instance.hcaptchaSecretKey) {
|
if (process.env.NODE_ENV !== 'test' && instance.enableHcaptcha && instance.hcaptchaSecretKey) {
|
||||||
const success = await verify(instance.hcaptchaSecretKey, body['hcaptcha-response']).then(
|
const success = await verify(instance.hcaptchaSecretKey, body['hcaptcha-response']).then(
|
||||||
({ 'error-codes': x }) => !x || !x.length,
|
({ success }) => success,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue