Fix form password
This commit is contained in:
parent
ac82040080
commit
f156f52608
|
@ -8,10 +8,10 @@ function addAuthHeader(request, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPasswordToFormRequest(request, options) {
|
function addPasswordToFormRequest(request, options) {
|
||||||
const url = request.url
|
if (!request || !request.startsWith('/forms/')) return
|
||||||
if (!url || !url.startsWith('/forms/')) return
|
|
||||||
|
const slug = request.split('/')[2]
|
||||||
|
|
||||||
const slug = url.split('/')[3]
|
|
||||||
const passwordCookie = useCookie('password-' + slug, {maxAge: 60 * 60 * 24 * 30}) // 30 days
|
const passwordCookie = useCookie('password-' + slug, {maxAge: 60 * 60 * 24 * 30}) // 30 days
|
||||||
if (slug !== undefined && slug !== '' && passwordCookie.value !== undefined) {
|
if (slug !== undefined && slug !== '' && passwordCookie.value !== undefined) {
|
||||||
options.headers['form-password'] = passwordCookie.value
|
options.headers['form-password'] = passwordCookie.value
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
<loader class="h-6 w-6 text-nt-blue mx-auto"/>
|
<loader class="h-6 w-6 text-nt-blue mx-auto"/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<open-complete-form v-show="!recordLoading" ref="open-complete-form" :form="form" class="mb-10"
|
<open-complete-form v-show="!recordLoading" ref="openCompleteForm" :form="form" class="mb-10"
|
||||||
@password-entered="passwordEntered"
|
@password-entered="passwordEntered"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
@ -66,6 +66,8 @@ const slug = useRoute().params.slug
|
||||||
const form = computed(() => formsStore.getByKey(slug))
|
const form = computed(() => formsStore.getByKey(slug))
|
||||||
const submitted = ref(false)
|
const submitted = ref(false)
|
||||||
|
|
||||||
|
const openCompleteForm = ref(null)
|
||||||
|
|
||||||
crisp.hideChat()
|
crisp.hideChat()
|
||||||
onBeforeRouteLeave((to, from) => {
|
onBeforeRouteLeave((to, from) => {
|
||||||
crisp.showChat()
|
crisp.showChat()
|
||||||
|
@ -73,26 +75,35 @@ onBeforeRouteLeave((to, from) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const passwordEntered = function (password) {
|
const passwordEntered = function (password) {
|
||||||
|
console.log('passwordEntered', password, sha256(password))
|
||||||
useCookie('password-' + slug, {
|
useCookie('password-' + slug, {
|
||||||
maxAge: {expires: 60 * 60 * 7},
|
maxAge: 60 * 60 * 7,
|
||||||
sameSite: false,
|
sameSite: false,
|
||||||
secure: true
|
secure: true
|
||||||
}).value = sha256(password)
|
}).value = sha256(password)
|
||||||
loadForm(slug).then(() => {
|
loadForm().then(() => {
|
||||||
if (form.value?.is_password_protected) {
|
if (form.value?.is_password_protected) {
|
||||||
this.$refs['open-complete-form'].addPasswordError('Invalid password.')
|
console.log(openCompleteForm.value)
|
||||||
|
openCompleteForm.value.addPasswordError('Invalid password.')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadForm = async () => {
|
const loadForm = async (setup=false) => {
|
||||||
if (formsStore.loading || form.value) return Promise.resolve()
|
console.log('loadForm',setup)
|
||||||
|
if (formsStore.loading || (form.value && !form.value.is_password_protected)) return Promise.resolve()
|
||||||
|
|
||||||
|
if (setup) {
|
||||||
const {data, error} = await formsStore.publicLoad(slug)
|
const {data, error} = await formsStore.publicLoad(slug)
|
||||||
if (error.value) {
|
if (error.value) {
|
||||||
formsStore.stopLoading()
|
formsStore.stopLoading()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
formsStore.save(data.value)
|
formsStore.save(data.value)
|
||||||
|
} else {
|
||||||
|
const data = await formsStore.publicFetch(slug)
|
||||||
|
formsStore.save(data)
|
||||||
|
}
|
||||||
formsStore.stopLoading()
|
formsStore.stopLoading()
|
||||||
|
|
||||||
// Adapt page to form: colors, custom code etc
|
// Adapt page to form: colors, custom code etc
|
||||||
|
@ -108,10 +119,10 @@ const loadForm = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadForm(slug)
|
loadForm()
|
||||||
})
|
})
|
||||||
|
|
||||||
await loadForm(slug)
|
await loadForm(true)
|
||||||
|
|
||||||
useOpnSeoMeta({
|
useOpnSeoMeta({
|
||||||
title: () => {
|
title: () => {
|
||||||
|
|
|
@ -50,6 +50,11 @@ export const useFormsStore = defineStore('forms', () => {
|
||||||
return useOpnApi('/forms/' + slug)
|
return useOpnApi('/forms/' + slug)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const publicFetch = (slug) => {
|
||||||
|
contentStore.startLoading()
|
||||||
|
return opnFetch('/forms/' + slug)
|
||||||
|
}
|
||||||
|
|
||||||
const allTags = computed(() => {
|
const allTags = computed(() => {
|
||||||
let tags = []
|
let tags = []
|
||||||
contentStore.getAll.value.forEach((form) => {
|
contentStore.getAll.value.forEach((form) => {
|
||||||
|
@ -69,6 +74,7 @@ export const useFormsStore = defineStore('forms', () => {
|
||||||
allLoaded,
|
allLoaded,
|
||||||
allTags,
|
allTags,
|
||||||
publicLoad,
|
publicLoad,
|
||||||
|
publicFetch,
|
||||||
loadAll,
|
loadAll,
|
||||||
load,
|
load,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue