-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/new recaptcha #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Feat/new recaptcha #240
Changes from all commits
cee2ac0
75b7901
23c9180
3e17eea
e1acbb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: { | ||
type: String, | ||
required: false, | ||
default: "Click to launch the app", | ||
}, | ||
button_color: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
return "E-mail is required." | ||
}, | ||
(value) => { | ||
if (/.+@.+\..+/.test(value)) return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
return "E-mail must be valid." | ||
}, | ||
] | ||
onMounted(() => { | ||
if (import.meta.client) { | ||
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
$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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
}) | ||
} | ||
}, | ||
}, | ||
) | ||
} | ||
</script> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
test("name", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
const name = "test" | ||
const result = check_recaptcha_params(name, email, launch) | ||
expect(result.status).toBe(500) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
}) | ||
test("email", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
const email = "test" | ||
const result = check_recaptcha_params(name, email, launch) | ||
expect(result.status).toBe(500) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
}) | ||
test("launch", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
const launch = true | ||
const result = check_recaptcha_params(name, email, launch) | ||
expect(result.status).toBe(500) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
}) | ||
}) | ||
|
||
describe("Right params", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
test("name", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
JulienChampagnol marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
const result = check_recaptcha_params(name, email, launch) | ||
expect(result.status).toBe(200) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function check_recaptcha_params(name, email, launch) { | ||
JulienChampagnol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (name !== "") return { status: 500 } | ||
JulienChampagnol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (email !== "") return { status: 500 } | ||
JulienChampagnol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (launch !== false) return { status: 500 } | ||
JulienChampagnol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { status: 200 } | ||
} | ||
|
||
export default check_recaptcha_params | ||
JulienChampagnol marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
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