2019-09-09 17:55:43 +00:00
|
|
|
<template>
|
2021-04-11 13:18:19 +00:00
|
|
|
<div>
|
2021-11-28 14:18:27 +00:00
|
|
|
<message v-if="loading">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('sharing.authenticating') }}
|
2021-11-28 14:18:27 +00:00
|
|
|
</message>
|
2021-04-11 13:18:19 +00:00
|
|
|
<div v-if="authenticateWithPassword" class="box">
|
|
|
|
<p class="pb-2">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('sharing.passwordRequired') }}
|
2019-11-03 12:44:40 +00:00
|
|
|
</p>
|
2021-04-11 13:18:19 +00:00
|
|
|
<div class="field">
|
|
|
|
<div class="control">
|
|
|
|
<input
|
|
|
|
id="linkSharePassword"
|
|
|
|
type="password"
|
|
|
|
class="input"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('user.auth.passwordPlaceholder')"
|
2021-04-11 13:18:19 +00:00
|
|
|
v-model="password"
|
|
|
|
v-focus
|
2021-12-08 12:22:39 +00:00
|
|
|
@keyup.enter.prevent="authenticate()"
|
2021-04-11 13:18:19 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
<x-button @click="authenticate()" :loading="loading">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('user.auth.login') }}
|
2021-04-11 13:18:19 +00:00
|
|
|
</x-button>
|
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
<Message variant="danger" class="mt-4" v-if="errorMessage !== ''">
|
2021-07-09 17:10:25 +00:00
|
|
|
{{ errorMessage }}
|
2021-12-08 12:22:39 +00:00
|
|
|
</Message>
|
2019-11-03 12:44:40 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-09 17:55:43 +00:00
|
|
|
</template>
|
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import {ref, computed} from 'vue'
|
|
|
|
import {useRoute, useRouter} from 'vue-router'
|
|
|
|
import {useI18n} from 'vue-i18n'
|
|
|
|
import {useTitle} from '@vueuse/core'
|
2019-09-09 17:55:43 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
import Message from '@/components/misc/message.vue'
|
2022-11-13 21:04:57 +00:00
|
|
|
import {PROJECT_VIEWS, type ProjectView} from '@/types/ProjectView'
|
2023-04-01 13:17:09 +00:00
|
|
|
import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash'
|
2022-09-24 13:20:40 +00:00
|
|
|
|
|
|
|
import {useBaseStore} from '@/stores/base'
|
2022-09-21 01:37:39 +00:00
|
|
|
import {useAuthStore} from '@/stores/auth'
|
2023-04-01 10:14:52 +00:00
|
|
|
import {useRedirectToLastVisited} from '@/composables/useRedirectToLastVisited'
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2022-05-23 05:23:59 +00:00
|
|
|
const {t} = useI18n({useScope: 'global'})
|
2021-12-08 12:22:39 +00:00
|
|
|
useTitle(t('sharing.authenticating'))
|
2023-04-01 12:12:47 +00:00
|
|
|
const {getLastVisitedRoute} = useRedirectToLastVisited()
|
2021-12-08 12:22:39 +00:00
|
|
|
|
2022-01-16 21:24:51 +00:00
|
|
|
function useAuth() {
|
2022-09-24 13:20:40 +00:00
|
|
|
const baseStore = useBaseStore()
|
2022-09-21 01:37:39 +00:00
|
|
|
const authStore = useAuthStore()
|
2021-12-08 12:22:39 +00:00
|
|
|
const route = useRoute()
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
const authenticateWithPassword = ref(false)
|
|
|
|
const errorMessage = ref('')
|
|
|
|
const password = ref('')
|
|
|
|
|
2022-09-21 01:37:39 +00:00
|
|
|
const authLinkShare = computed(() => authStore.authLinkShare)
|
2021-12-08 12:22:39 +00:00
|
|
|
|
|
|
|
async function authenticate() {
|
|
|
|
authenticateWithPassword.value = false
|
|
|
|
errorMessage.value = ''
|
2022-09-07 19:49:14 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
if (authLinkShare.value) {
|
2022-11-13 21:04:57 +00:00
|
|
|
// FIXME: push to 'project.list' since authenticated?
|
2021-12-08 12:22:39 +00:00
|
|
|
return
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
2022-09-07 19:49:14 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
// TODO: no password
|
2022-09-07 19:49:14 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
loading.value = true
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
try {
|
2022-11-13 21:04:57 +00:00
|
|
|
const {project_id: projectId} = await authStore.linkShareAuth({
|
2021-12-08 12:22:39 +00:00
|
|
|
hash: route.params.share,
|
|
|
|
password: password.value,
|
|
|
|
})
|
2022-09-07 19:49:14 +00:00
|
|
|
const logoVisible = route.query.logoVisible
|
|
|
|
? route.query.logoVisible === 'true'
|
|
|
|
: true
|
2022-09-24 13:20:40 +00:00
|
|
|
baseStore.setLogoVisible(logoVisible)
|
2022-09-07 20:29:54 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
const view = route.query.view && Object.values(PROJECT_VIEWS).includes(route.query.view as ProjectView)
|
2022-09-08 12:11:19 +00:00
|
|
|
? route.query.view
|
2023-03-14 12:43:43 +00:00
|
|
|
: 'list'
|
2022-09-08 12:11:19 +00:00
|
|
|
|
2023-04-01 12:15:54 +00:00
|
|
|
const hash = LINK_SHARE_HASH_PREFIX + route.params.share
|
2023-04-01 10:14:52 +00:00
|
|
|
|
2023-04-01 12:12:47 +00:00
|
|
|
const last = getLastVisitedRoute()
|
2023-04-01 10:14:52 +00:00
|
|
|
if (last) {
|
2023-04-01 12:18:38 +00:00
|
|
|
return router.push({
|
2023-04-01 10:14:52 +00:00
|
|
|
...last,
|
|
|
|
hash,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-01 12:18:38 +00:00
|
|
|
return router.push({
|
2023-04-01 10:14:52 +00:00
|
|
|
name: `project.${view}`,
|
|
|
|
params: {projectId},
|
|
|
|
hash,
|
|
|
|
})
|
2023-10-20 19:34:11 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (e?.response?.data?.code === 13001) {
|
2021-12-08 12:22:39 +00:00
|
|
|
authenticateWithPassword.value = true
|
2021-04-09 14:29:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
// TODO: Put this logic in a global errorMessage handler method which checks all auth codes
|
2022-01-16 21:24:51 +00:00
|
|
|
let err = t('sharing.error')
|
2023-10-20 19:34:11 +00:00
|
|
|
if (e?.response?.data?.message) {
|
2022-01-16 21:24:51 +00:00
|
|
|
err = e.response.data.message
|
2021-12-08 12:22:39 +00:00
|
|
|
}
|
2023-10-20 19:34:11 +00:00
|
|
|
if (e?.response?.data?.code === 13002) {
|
2022-01-16 21:24:51 +00:00
|
|
|
err = t('sharing.invalidPassword')
|
2021-12-08 12:22:39 +00:00
|
|
|
}
|
2022-01-16 21:24:51 +00:00
|
|
|
errorMessage.value = err
|
2021-12-08 12:22:39 +00:00
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
}
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
authenticate()
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2021-12-08 12:22:39 +00:00
|
|
|
return {
|
|
|
|
loading,
|
|
|
|
authenticateWithPassword,
|
|
|
|
errorMessage,
|
|
|
|
password,
|
|
|
|
authenticate,
|
|
|
|
}
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
2021-12-08 12:22:39 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
loading,
|
|
|
|
authenticateWithPassword,
|
|
|
|
errorMessage,
|
|
|
|
password,
|
|
|
|
authenticate,
|
|
|
|
} = useAuth()
|
2019-09-09 17:55:43 +00:00
|
|
|
</script>
|