Skip to content

Commit dc1c432

Browse files
committed
feat: add turnstile
1 parent 0bdb7b8 commit dc1c432

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
VUE_APP_SELF_HOST=https://web-tech.tw/openchat
22
VUE_APP_OCJI_HOST=https://web-tech.tw/recv/openchat
33

4+
VUE_APP_TURNSTILE_SITE_KEY="0x4AAAAAAAr6LY1hBUbTBkVA"
5+
46
VUE_APP_SARA_INTE_HOST=https://web-tech.tw/sara
57
VUE_APP_SARA_RECV_HOST=https://web-tech.tw/recv/sara
68
VUE_APP_SARA_TOKEN_NAME=unified_token

src/views/JoinChatView.vue

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
</button>
4040
</div>
4141
</div>
42+
<div v-show="!accept" class="checkbox my-3">
43+
<div id="captcha" data-theme="light"></div>
44+
</div>
4245
<div class="flex justify-end mt-4">
4346
<button
4447
:disabled="!ready"
@@ -76,10 +79,12 @@ export default {
7679
description: null,
7780
url: null
7881
},
82+
captcha: null,
7983
secret: null,
8084
status: null,
8185
accept: false,
82-
ready: true
86+
ready: true,
87+
turnstileScript: null,
8388
}),
8489
computed: {
8590
icon() {
@@ -111,6 +116,7 @@ export default {
111116
this.ready = false;
112117
const form = new URLSearchParams();
113118
form.set('slug', this.code);
119+
form.set('captcha', this.captcha);
114120
try {
115121
const xhr = await this.$axios.post('application', form)
116122
this.ready = true;
@@ -129,7 +135,24 @@ export default {
129135
}
130136
}
131137
},
138+
mounted() {
139+
document.head.appendChild(this.turnstileScript);
140+
},
141+
beforeDestroy() {
142+
document.head.removeChild(this.turnstileScript);
143+
},
132144
created() {
145+
const turnstileScriptUrl = "https://challenges.cloudflare.com/turnstile/v0/api.js?onload=loadTurnstile";
146+
this.turnstileScript = document.createElement("script");
147+
this.turnstileScript.setAttribute("src", turnstileScriptUrl);
148+
window.loadTurnstile = () => {
149+
window.turnstile.render("#captcha", {
150+
sitekey: process.env.VUE_APP_TURNSTILE_SITE_KEY,
151+
callback: (token) => {
152+
this.captcha = token;
153+
},
154+
});
155+
};
133156
if (this.code in data) {
134157
this.info = data[this.code];
135158
} else {

0 commit comments

Comments
 (0)