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'
|
2022-07-21 16:45:58 +00:00
|
|
|
import {useStore} from '@/store'
|
2021-12-08 12:22:39 +00:00
|
|
|
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-09-07 19:49:14 +00:00
|
|
|
import {LOGO_VISIBLE} from '@/store/mutation-types'
|
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'))
|
|
|
|
|
2022-01-16 21:24:51 +00:00
|
|
|
function useAuth() {
|
2021-12-08 12:22:39 +00:00
|
|
|
const store = useStore()
|
|
|
|
const route = useRoute()
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
const authenticateWithPassword = ref(false)
|
|
|
|
const errorMessage = ref('')
|
|
|
|
const password = ref('')
|
|
|
|
|
|
|
|
const authLinkShare = computed(() => store.getters['auth/authLinkShare'])
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// FIXME: push to 'list.list' since authenticated?
|
|
|
|
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 {
|
|
|
|
const {list_id: listId} = await store.dispatch('auth/linkShareAuth', {
|
|
|
|
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
|
|
|
|
store.commit(LOGO_VISIBLE, logoVisible)
|
2021-12-08 12:22:39 +00:00
|
|
|
router.push({name: 'list.list', params: {listId}})
|
2022-01-16 21:24:51 +00:00
|
|
|
} catch (e: any) {
|
2021-12-08 12:22:39 +00:00
|
|
|
if (e.response?.data?.code === 13001) {
|
|
|
|
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')
|
2021-12-08 12:22:39 +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
|
|
|
}
|
|
|
|
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>
|