Skip to content

Commit cee2ac0

Browse files
save
1 parent 497c563 commit cee2ac0

File tree

3 files changed

+84
-27
lines changed

3 files changed

+84
-27
lines changed

components/Launcher.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
align-self="center"
99
style="z-index: 1000"
1010
>
11-
<h4 class="pb-3">Please complete the recaptcha to launch the app</h4>
12-
<Recaptcha :site_key="site_key" />
11+
<Recaptcha :color="'secondary'" />
1312
</v-col>
1413
<v-col v-else-if="infra_store.status == Status.CREATING">
1514
<Loading />

components/Recaptcha.vue

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,68 @@
1-
<template>
2-
<ClientOnly>
3-
<vue-recaptcha
4-
ref="recaptcha"
5-
:sitekey="props.site_key"
6-
:load-recaptcha-script="true"
7-
align-self="center"
8-
@expired="infra_store.is_captcha_validated = false"
9-
@verify="submit_recaptcha"
10-
/>
11-
</ClientOnly>
1+
<template align="center" justify="center">
2+
<VRow>
3+
<VCol>
4+
<VForm v-model="valid">
5+
<VContainer>
6+
<VRow>
7+
<VCol cols="12" md="4">
8+
<VTextField v-model="name" label="Name" required />
9+
</VCol>
10+
<VCol cols="12" md="4">
11+
<VTextField
12+
v-model="email"
13+
:rules="emailRules"
14+
label="E-mail"
15+
required
16+
/>
17+
</VCol>
18+
<VCol cols="12" md="4">
19+
<VCheckbox label="Launch the app" v-model="launch" />
20+
</VCol>
21+
</VRow>
22+
</VContainer>
23+
</VForm>
24+
</VCol>
25+
</VRow>
26+
<VRow>
27+
<VCol>
28+
<VBtn
29+
:text="props.button_label"
30+
:color="props.button_color"
31+
@click="submit_recaptcha"
32+
/>
33+
</VCol>
34+
</VRow>
1235
</template>
1336

1437
<script setup>
15-
import { VueRecaptcha } from "vue-recaptcha"
16-
const infra_store = useInfraStore()
17-
1838
const props = defineProps({
19-
site_key: { type: String, required: true },
39+
button_label: {
40+
type: String,
41+
required: false,
42+
default: "Click to launch the app",
43+
},
44+
button_color: {
45+
type: String,
46+
required: false,
47+
default: "primary",
48+
},
2049
})
50+
const infra_store = useInfraStore()
51+
const name = ref("")
52+
const email = ref("")
53+
const launch = ref(false)
54+
const emailRules = [
55+
(value) => {
56+
if (value) return true
57+
58+
return "E-mail is required."
59+
},
60+
(value) => {
61+
if (/.+@.+\..+/.test(value)) return true
62+
63+
return "E-mail must be valid."
64+
},
65+
]
2166
2267
onMounted(() => {
2368
if (import.meta.client) {
@@ -29,15 +74,22 @@
2974
}
3075
}
3176
})
32-
async function submit_recaptcha(token) {
33-
try {
34-
const response = await $fetch.raw(
35-
`/.netlify/functions/recaptcha?token=${token}`,
36-
)
37-
infra_store.$patch({ is_captcha_validated: response.status == 200 })
38-
recaptcha.reset()
39-
} catch (error) {
40-
console.error(error)
41-
}
77+
async function submit_recaptcha() {
78+
$fetch(
79+
`/.netlify/functions/recaptcha?name=${name.value}&email=${email.value}&launch=${launch.value}`,
80+
{
81+
onRequestError({ error }) {
82+
console.log("onRequestError", error)
83+
},
84+
onResponse({ response }) {
85+
if (response.ok) {
86+
infra_store.$patch({
87+
is_captcha_validated: response.status == 200,
88+
})
89+
}
90+
},
91+
onResponseError({ response }) {},
92+
},
93+
)
4294
}
4395
</script>

utils/recaptcha.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function check_recaptcha_params(name, email, launch) {
2+
if (name !== "") return { statusCode: 500 }
3+
if (email !== "") return { statusCode: 500 }
4+
if (launch !== false) return { statusCode: 500 }
5+
return { statusCode: 200 }
6+
}

0 commit comments

Comments
 (0)