Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions components/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
align-self="center"
style="z-index: 1000"
>
<h4 class="pb-3">Please complete the recaptcha to launch the app</h4>
<Recaptcha :site_key="site_key" />
<Recaptcha :color="'secondary'" />
</v-col>
<v-col v-else-if="infra_store.status == Status.CREATING">
<Loading />
Expand Down
98 changes: 73 additions & 25 deletions components/Recaptcha.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
<template>
<ClientOnly>
<vue-recaptcha
ref="recaptcha"
:sitekey="props.site_key"
:load-recaptcha-script="true"
align-self="center"
@expired="infra_store.is_captcha_validated = false"
@verify="submit_recaptcha"
/>
</ClientOnly>
<template align="center" justify="center" style="display: none">
<VRow>
<VCol>
<VForm v-model="valid">
<VContainer>
<VRow>
<VCol cols="12" md="4">
<VTextField v-model="name" label="Name" required />
</VCol>
<VCol cols="12" md="4">
<VTextField
v-model="email"
:rules="emailRules"
label="E-mail"
required
/>
</VCol>
<VCol cols="12" md="4">
<VCheckbox label="Launch the app" v-model="launch" />
</VCol>
</VRow>
</VContainer>
</VForm>
</VCol>
</VRow>
<VRow>
<VCol>
<VBtn
:text="props.button_label"
:color="props.button_color"
@click="submit_recaptcha"
/>
</VCol>
</VRow>
</template>

<script setup>
import { VueRecaptcha } from "vue-recaptcha"
const infra_store = useInfraStore()
const props = defineProps({
site_key: { type: String, required: true },
button_label: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Object keys should be sorted

type: String,
required: false,
default: "Click to launch the app",
},
button_color: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Object keys should be sorted

type: String,
required: false,
default: "primary",
},
})
const infra_store = useInfraStore()
const name = ref("")
const email = ref("")
const launch = ref(false)
const emailRules = [
(value) => {
if (value) return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Expected { after 'if' condition.

return "E-mail is required."
},
(value) => {
if (/.+@.+\..+/.test(value)) return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Expected { after 'if' condition.

return "E-mail must be valid."
},
]
onMounted(() => {
if (import.meta.client) {
Expand All @@ -29,15 +74,18 @@
}
}
})
async function submit_recaptcha(token) {
try {
const response = await $fetch.raw(
`/.netlify/functions/recaptcha?token=${token}`,
)
infra_store.$patch({ is_captcha_validated: response.status == 200 })
recaptcha.reset()
} catch (error) {
console.error(error)
}
async function submit_recaptcha() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Expected a function expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Async function has no 'await' expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
async is not allowed

$fetch(
`/.netlify/functions/recaptcha?name=${name.value}&email=${email.value}&launch=${launch.value}`,
{
onResponse({ response }) {
if (response.ok) {
infra_store.$patch({
is_captcha_validated: response.status == 200,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Expected === and instead saw ==

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
200

})
}
},
},
)
}
</script>
49 changes: 0 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"semver": "7.7.1",
"tree-kill": "1.2.2",
"uuid": "11.1.0",
"vue-recaptcha": "2.0.3",
"vue3-carousel": "0.3.4",
"vuetify": "3.8.12",
"wslink": "1.12.4"
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/utils/recaptcha.nuxt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, test } from "vitest"

import check_recaptcha_params from "@ogw_f/utils/recaptcha.js"

describe("recaptcha.js", () => {
const name = ""
const email = ""
const launch = false
describe("Wrong params", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Enforce lowercase test names

test("name", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Async function has no 'await' expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Enforce test and it usage conventions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
async is not allowed

const name = "test"
const result = check_recaptcha_params(name, email, launch)
expect(result.status).toBe(500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
500

})
test("email", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Async function has no 'await' expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Enforce test and it usage conventions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Missing padding before test block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
async is not allowed

const email = "test"
const result = check_recaptcha_params(name, email, launch)
expect(result.status).toBe(500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
500

})
test("launch", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Async function has no 'await' expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Enforce test and it usage conventions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Missing padding before test block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
async is not allowed

const launch = true
const result = check_recaptcha_params(name, email, launch)
expect(result.status).toBe(500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
500

})
})

describe("Right params", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Enforce lowercase test names

test("name", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
Async function has no 'await' expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
async is not allowed

const result = check_recaptcha_params(name, email, launch)
expect(result.status).toBe(200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
200

})
})
})
8 changes: 8 additions & 0 deletions utils/recaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function check_recaptcha_params(name, email, launch) {
if (name !== "") return { status: 500 }
if (email !== "") return { status: 500 }
if (launch !== false) return { status: 500 }
return { status: 200 }
}

export default check_recaptcha_params
Loading