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
|
|
|
|
@keyup.enter.prevent="auth"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<x-button @click="auth" :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-11-28 14:18:27 +00:00
|
|
|
<message variant="danger" class="mt-4" v-if="errorMessage !== ''">
|
2021-07-09 17:10:25 +00:00
|
|
|
{{ errorMessage }}
|
2021-11-28 14:18:27 +00:00
|
|
|
</message>
|
2019-11-03 12:44:40 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-09 17:55:43 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-09-10 13:04:00 +00:00
|
|
|
import {mapGetters} from 'vuex'
|
2021-11-28 14:18:27 +00:00
|
|
|
import Message from '@/components/misc/message'
|
2019-09-09 17:55:43 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
export default {
|
|
|
|
name: 'LinkSharingAuth',
|
2021-11-28 14:18:27 +00:00
|
|
|
components: {Message},
|
2020-09-05 20:35:52 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2021-04-11 13:18:19 +00:00
|
|
|
loading: true,
|
|
|
|
authenticateWithPassword: false,
|
2021-07-09 17:10:25 +00:00
|
|
|
errorMessage: '',
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
hash: '',
|
2021-04-11 13:18:19 +00:00
|
|
|
password: '',
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.auth()
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-06-23 23:24:57 +00:00
|
|
|
this.setTitle(this.$t('sharing.authenticating'))
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2021-09-10 13:04:00 +00:00
|
|
|
computed: mapGetters('auth', [
|
|
|
|
'authLinkShare',
|
|
|
|
]),
|
2020-09-05 20:35:52 +00:00
|
|
|
methods: {
|
2021-10-11 17:37:20 +00:00
|
|
|
async auth() {
|
2021-07-09 17:10:25 +00:00
|
|
|
this.errorMessage = ''
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2021-04-09 14:29:07 +00:00
|
|
|
if (this.authLinkShare) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-11 13:18:19 +00:00
|
|
|
this.loading = true
|
|
|
|
|
2021-10-11 17:37:20 +00:00
|
|
|
try {
|
|
|
|
const r = await this.$store.dispatch('auth/linkShareAuth', {
|
|
|
|
hash: this.$route.params.share,
|
|
|
|
password: this.password,
|
2020-09-05 20:35:52 +00:00
|
|
|
})
|
2021-10-11 17:37:20 +00:00
|
|
|
this.$router.push({name: 'list.list', params: {listId: r.list_id}})
|
2021-11-28 14:18:27 +00:00
|
|
|
} catch (e) {
|
2021-10-11 17:37:20 +00:00
|
|
|
if (typeof e.response.data.code !== 'undefined' && e.response.data.code === 13001) {
|
|
|
|
this.authenticateWithPassword = true
|
|
|
|
return
|
|
|
|
}
|
2021-04-11 13:18:19 +00:00
|
|
|
|
2021-10-11 17:37:20 +00:00
|
|
|
// TODO: Put this logic in a global errorMessage handler method which checks all auth codes
|
|
|
|
let errorMessage = this.$t('sharing.error')
|
|
|
|
if (e.response && e.response.data && e.response.data.message) {
|
|
|
|
errorMessage = e.response.data.message
|
|
|
|
}
|
|
|
|
if (typeof e.response.data.code !== 'undefined' && e.response.data.code === 13002) {
|
|
|
|
errorMessage = this.$t('sharing.invalidPassword')
|
|
|
|
}
|
|
|
|
this.errorMessage = errorMessage
|
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
2019-11-03 12:44:40 +00:00
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
|
|
|
}
|
2019-09-09 17:55:43 +00:00
|
|
|
</script>
|