Skip to content

Commit cdbee18

Browse files
committed
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWeb-Front into feat/save_and_load
2 parents 309b5f4 + 21cb4a4 commit cdbee18

File tree

6 files changed

+134
-27
lines changed

6 files changed

+134
-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: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,74 @@
11
<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>
2+
<VRow align="center" justify="center" style="display: none">
3+
<VCol cols="4">
4+
<VForm v-model="valid">
5+
<VContainer>
6+
<VRow>
7+
<VCol>
8+
<VTextField v-model="name" label="Name" required />
9+
</VCol>
10+
</VRow>
11+
<VRow>
12+
<VCol>
13+
<VTextField
14+
v-model="email"
15+
:rules="emailRules"
16+
label="E-mail"
17+
required
18+
/>
19+
</VCol>
20+
</VRow>
21+
<VRow>
22+
<VCol>
23+
<VCheckbox label="Launch the app" v-model="launch" />
24+
</VCol>
25+
</VRow>
26+
</VContainer>
27+
</VForm>
28+
</VCol>
29+
</VRow>
30+
<VRow align="center" justify="center">
31+
<VCol cols="4" class="d-flex justify-center align-center">
32+
<VBtn
33+
:text="props.button_label"
34+
:color="props.button_color"
35+
@click="submit_recaptcha"
36+
/>
37+
</VCol>
38+
</VRow>
1239
</template>
1340

1441
<script setup>
15-
import { VueRecaptcha } from "vue-recaptcha"
16-
const infra_store = useInfraStore()
17-
1842
const props = defineProps({
19-
site_key: { type: String, required: true },
43+
button_label: {
44+
type: String,
45+
required: false,
46+
default: "Launch the app",
47+
},
48+
button_color: {
49+
type: String,
50+
required: false,
51+
default: "white",
52+
},
2053
})
54+
const infra_store = useInfraStore()
55+
const name = ref("")
56+
const email = ref("")
57+
const launch = ref(false)
58+
const emailRules = [
59+
(value) => {
60+
if (value) {
61+
return true
62+
}
63+
return "E-mail is required."
64+
},
65+
(value) => {
66+
if (/.+@.+\..+/.test(value)) {
67+
return true
68+
}
69+
return "E-mail must be valid."
70+
},
71+
]
2172
2273
onMounted(() => {
2374
if (import.meta.client) {
@@ -29,15 +80,18 @@
2980
}
3081
}
3182
})
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-
}
83+
function submit_recaptcha() {
84+
$fetch(
85+
`/.netlify/functions/recaptcha?name=${name.value}&email=${email.value}&launch=${launch.value}`,
86+
{
87+
onResponse({ response }) {
88+
if (response.ok) {
89+
infra_store.$patch({
90+
is_captcha_validated: response.status === 200,
91+
})
92+
}
93+
},
94+
},
95+
)
4296
}
4397
</script>

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"sass": "1.87.0",
6161
"semver": "7.7.1",
6262
"uuid": "11.1.0",
63-
"vue-recaptcha": "2.0.3",
6463
"vue3-carousel": "0.3.4",
6564
"vuetify": "3.8.12",
6665
"ws": "8.18.3",

tests/integration/microservices/viewer/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
# pip-compile --output-file=tests/integration/microservices/viewer/requirements.txt tests/integration/microservices/viewer/requirements.in
66
#
77

8+
opengeodeweb-viewer==1.*,>=1.11.9rc1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Third party imports
2+
import { describe, expect, test } from "vitest"
3+
4+
// Local imports
5+
import { check_recaptcha_params } from "~/utils/recaptcha.js"
6+
7+
describe("recaptcha.js", () => {
8+
const name = ""
9+
const email = ""
10+
const launch = false
11+
const internal_error = 500
12+
const success = 200
13+
14+
describe("wrong params", () => {
15+
test("name", () => {
16+
const name = "test"
17+
const result = check_recaptcha_params(name, email, launch)
18+
expect(result.status).toBe(internal_error)
19+
})
20+
21+
test("email", () => {
22+
const email = "test"
23+
const result = check_recaptcha_params(name, email, launch)
24+
expect(result.status).toBe(internal_error)
25+
})
26+
27+
test("launch", () => {
28+
const launch = true
29+
const result = check_recaptcha_params(name, email, launch)
30+
expect(result.status).toBe(internal_error)
31+
})
32+
})
33+
34+
describe("right params", () => {
35+
test("name", () => {
36+
const result = check_recaptcha_params(name, email, launch)
37+
expect(result.status).toBe(success)
38+
})
39+
})
40+
})

utils/recaptcha.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function check_recaptcha_params(name, email, launch) {
2+
if (name !== "") {
3+
return { status: 500 }
4+
}
5+
if (email !== "") {
6+
return { status: 500 }
7+
}
8+
if (launch !== false) {
9+
return { status: 500 }
10+
}
11+
return { status: 200 }
12+
}
13+
14+
export { check_recaptcha_params }

0 commit comments

Comments
 (0)