2021-08-22 17:46:04 +02:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div id="page-wrapper" class="page p-6 overflow-y-auto relative" :class="streamLibraryItem ? 'streaming' : ''">
|
2021-09-05 20:21:02 +02:00
|
|
|
<div class="w-full max-w-xl mx-auto">
|
2022-11-07 00:56:44 +01:00
|
|
|
<h1 class="text-2xl">{{ $strings.HeaderAccount }}</h1>
|
2021-08-22 17:46:04 +02:00
|
|
|
|
|
|
|
<div class="my-4">
|
|
|
|
<div class="flex -mx-2">
|
|
|
|
<div class="w-2/3 px-2">
|
2022-11-07 00:56:44 +01:00
|
|
|
<ui-text-input-with-label disabled :value="username" :label="$strings.LabelUsername" />
|
2021-08-22 17:46:04 +02:00
|
|
|
</div>
|
|
|
|
<div class="w-1/3 px-2">
|
2022-11-07 00:56:44 +01:00
|
|
|
<ui-text-input-with-label disabled :value="usertype" :label="$strings.LabelAccountType" />
|
2021-08-22 17:46:04 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-10 01:00:20 +01:00
|
|
|
<div class="py-4">
|
|
|
|
<p class="px-1 text-sm font-semibold">{{ $strings.LabelLanguage }}</p>
|
|
|
|
<ui-dropdown v-model="selectedLanguage" :items="$languageCodeOptions" small class="max-w-48" @input="updateLocalLanguage" />
|
|
|
|
</div>
|
2021-08-22 17:46:04 +02:00
|
|
|
|
2022-11-10 01:00:20 +01:00
|
|
|
<div class="w-full h-px bg-white/10 my-4" />
|
2021-08-22 17:46:04 +02:00
|
|
|
|
2023-12-02 00:10:33 +01:00
|
|
|
<p v-if="showChangePasswordForm" class="mb-4 text-lg">{{ $strings.HeaderChangePassword }}</p>
|
|
|
|
<form v-if="showChangePasswordForm" @submit.prevent="submitChangePassword">
|
2022-11-07 00:56:44 +01:00
|
|
|
<ui-text-input-with-label v-model="password" :disabled="changingPassword" type="password" :label="$strings.LabelPassword" class="my-2" />
|
|
|
|
<ui-text-input-with-label v-model="newPassword" :disabled="changingPassword" type="password" :label="$strings.LabelNewPassword" class="my-2" />
|
|
|
|
<ui-text-input-with-label v-model="confirmPassword" :disabled="changingPassword" type="password" :label="$strings.LabelConfirmPassword" class="my-2" />
|
2021-08-22 17:46:04 +02:00
|
|
|
<div class="flex items-center py-2">
|
2022-11-07 00:56:44 +01:00
|
|
|
<p v-if="isRoot" class="text-error py-2 text-xs">* {{ $strings.NoteChangeRootPassword }}</p>
|
2021-08-22 17:46:04 +02:00
|
|
|
<div class="flex-grow" />
|
2022-11-09 00:10:08 +01:00
|
|
|
<ui-btn v-show="(password && newPassword && confirmPassword) || isRoot" type="submit" :loading="changingPassword" color="success">{{ $strings.ButtonSubmit }}</ui-btn>
|
2021-08-22 17:46:04 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2021-09-05 20:21:02 +02:00
|
|
|
|
2024-10-26 22:34:34 +02:00
|
|
|
<div v-if="showEreaderTable">
|
|
|
|
<div class="w-full h-px bg-white/10 my-4" />
|
|
|
|
|
|
|
|
<app-settings-content :header-text="$strings.HeaderEreaderDevices">
|
|
|
|
<template #header-items>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
|
|
|
|
<ui-btn color="primary" small @click="addNewDeviceClick">{{ $strings.ButtonAddDevice }}</ui-btn>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<table v-if="ereaderDevices.length" class="tracksTable mt-4">
|
|
|
|
<tr>
|
|
|
|
<th class="text-left">{{ $strings.LabelName }}</th>
|
|
|
|
<th class="text-left">{{ $strings.LabelEmail }}</th>
|
|
|
|
<th class="w-40"></th>
|
|
|
|
</tr>
|
|
|
|
<tr v-for="device in ereaderDevices" :key="device.name">
|
|
|
|
<td>
|
|
|
|
<p class="text-sm md:text-base text-gray-100">{{ device.name }}</p>
|
|
|
|
</td>
|
|
|
|
<td class="text-left">
|
|
|
|
<p class="text-sm md:text-base text-gray-100">{{ device.email }}</p>
|
|
|
|
</td>
|
|
|
|
<td class="w-40">
|
|
|
|
<div class="flex justify-end items-center h-10">
|
|
|
|
<ui-icon-btn icon="edit" borderless :size="8" icon-font-size="1.1rem" :disabled="deletingDeviceName === device.name || device.users?.length !== 1" class="mx-1" @click="editDeviceClick(device)" />
|
|
|
|
<ui-icon-btn icon="delete" borderless :size="8" icon-font-size="1.1rem" :disabled="deletingDeviceName === device.name || device.users?.length !== 1" @click="deleteDeviceClick(device)" />
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<div v-else-if="!loading" class="text-center py-4">
|
|
|
|
<p class="text-lg text-gray-100">{{ $strings.MessageNoDevices }}</p>
|
|
|
|
</div>
|
|
|
|
</app-settings-content>
|
|
|
|
</div>
|
|
|
|
|
2021-09-05 20:21:02 +02:00
|
|
|
<div class="py-4 mt-8 flex">
|
2024-07-08 18:36:37 +02:00
|
|
|
<ui-btn color="primary flex items-center text-lg" @click="logout"><span class="material-symbols mr-4 icon-text">logout</span>{{ $strings.ButtonLogout }}</ui-btn>
|
2021-09-05 20:21:02 +02:00
|
|
|
</div>
|
2024-10-26 22:34:34 +02:00
|
|
|
|
|
|
|
<modals-emails-user-e-reader-device-modal v-model="showEReaderDeviceModal" :existing-devices="revisedEreaderDevices" :ereader-device="selectedEReaderDevice" @update="ereaderDevicesUpdated" />
|
2021-08-22 17:46:04 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2024-10-26 22:34:34 +02:00
|
|
|
loading: false,
|
2021-08-22 17:46:04 +02:00
|
|
|
password: null,
|
|
|
|
newPassword: null,
|
|
|
|
confirmPassword: null,
|
2022-11-10 01:00:20 +01:00
|
|
|
changingPassword: false,
|
2024-10-26 22:34:34 +02:00
|
|
|
selectedLanguage: '',
|
|
|
|
newEReaderDevice: {
|
|
|
|
name: '',
|
|
|
|
email: ''
|
|
|
|
},
|
|
|
|
ereaderDevices: [],
|
|
|
|
deletingDeviceName: null,
|
|
|
|
selectedEReaderDevice: null,
|
|
|
|
showEReaderDeviceModal: false
|
2021-08-22 17:46:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-11-04 23:35:59 +01:00
|
|
|
},
|
2021-08-22 17:46:04 +02:00
|
|
|
user() {
|
2021-08-24 01:31:04 +02:00
|
|
|
return this.$store.state.user.user || null
|
2021-08-22 17:46:04 +02:00
|
|
|
},
|
|
|
|
username() {
|
|
|
|
return this.user.username
|
|
|
|
},
|
|
|
|
usertype() {
|
|
|
|
return this.user.type
|
|
|
|
},
|
|
|
|
isRoot() {
|
|
|
|
return this.usertype === 'root'
|
2022-04-30 01:38:13 +02:00
|
|
|
},
|
|
|
|
isGuest() {
|
|
|
|
return this.usertype === 'guest'
|
2023-12-02 00:10:33 +01:00
|
|
|
},
|
|
|
|
isPasswordAuthEnabled() {
|
|
|
|
const activeAuthMethods = this.$store.getters['getServerSetting']('authActiveAuthMethods') || []
|
|
|
|
return activeAuthMethods.includes('local')
|
|
|
|
},
|
|
|
|
showChangePasswordForm() {
|
|
|
|
return !this.isGuest && this.isPasswordAuthEnabled
|
2024-10-26 22:34:34 +02:00
|
|
|
},
|
|
|
|
showEreaderTable() {
|
|
|
|
return this.usertype !== 'root' && this.usertype !== 'admin' && this.user.permissions?.createEreader
|
|
|
|
},
|
|
|
|
revisedEreaderDevices() {
|
|
|
|
return this.ereaderDevices.filter((device) => device.users?.length === 1)
|
2021-08-22 17:46:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-11-10 01:00:20 +01:00
|
|
|
updateLocalLanguage(lang) {
|
|
|
|
this.$setLanguageCode(lang)
|
|
|
|
},
|
2021-09-05 20:21:02 +02:00
|
|
|
logout() {
|
2024-02-17 23:58:49 +01:00
|
|
|
// Disconnect from socket
|
|
|
|
if (this.$root.socket) {
|
|
|
|
console.log('Disconnecting from socket', this.$root.socket.id)
|
|
|
|
this.$root.socket.removeAllListeners()
|
|
|
|
this.$root.socket.disconnect()
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
2024-01-24 22:47:50 +01:00
|
|
|
|
2021-09-05 20:21:02 +02:00
|
|
|
if (localStorage.getItem('token')) {
|
|
|
|
localStorage.removeItem('token')
|
|
|
|
}
|
2022-11-27 22:12:55 +01:00
|
|
|
this.$store.commit('libraries/setUserPlaylists', [])
|
|
|
|
this.$store.commit('libraries/setCollections', [])
|
2024-01-24 22:47:50 +01:00
|
|
|
|
2024-02-17 23:58:49 +01:00
|
|
|
this.$axios
|
|
|
|
.$post('/logout')
|
|
|
|
.then((logoutPayload) => {
|
|
|
|
const redirect_url = logoutPayload.redirect_url
|
2024-01-24 22:47:50 +01:00
|
|
|
|
2024-02-17 23:58:49 +01:00
|
|
|
if (redirect_url) {
|
|
|
|
window.location.href = redirect_url
|
|
|
|
} else {
|
|
|
|
this.$router.push('/login')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
})
|
2021-09-05 20:21:02 +02:00
|
|
|
},
|
2021-08-22 17:46:04 +02:00
|
|
|
resetForm() {
|
|
|
|
this.password = null
|
|
|
|
this.newPassword = null
|
|
|
|
this.confirmPassword = null
|
|
|
|
},
|
|
|
|
submitChangePassword() {
|
|
|
|
if (this.newPassword !== this.confirmPassword) {
|
2024-08-31 00:47:49 +02:00
|
|
|
return this.$toast.error(this.$strings.ToastUserPasswordMismatch)
|
2021-08-22 17:46:04 +02:00
|
|
|
}
|
2021-08-27 14:01:47 +02:00
|
|
|
if (this.password === this.newPassword) {
|
2024-08-31 00:47:49 +02:00
|
|
|
return this.$toast.error(this.$strings.ToastUserPasswordMustChange)
|
2021-08-27 14:01:47 +02:00
|
|
|
}
|
2021-08-22 17:46:04 +02:00
|
|
|
this.changingPassword = true
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$patch('/api/me/password', {
|
2021-08-22 17:46:04 +02:00
|
|
|
password: this.password,
|
|
|
|
newPassword: this.newPassword
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
if (res.success) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastUserPasswordChangeSuccess)
|
2021-08-22 17:46:04 +02:00
|
|
|
this.resetForm()
|
|
|
|
} else {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(res.error || this.$strings.ToastUnknownError)
|
2021-08-22 17:46:04 +02:00
|
|
|
}
|
|
|
|
this.changingPassword = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastUnknownError)
|
2021-08-22 17:46:04 +02:00
|
|
|
this.changingPassword = false
|
|
|
|
})
|
2024-10-26 22:34:34 +02:00
|
|
|
},
|
|
|
|
addNewDeviceClick() {
|
|
|
|
this.selectedEReaderDevice = null
|
|
|
|
this.showEReaderDeviceModal = true
|
|
|
|
},
|
|
|
|
editDeviceClick(device) {
|
|
|
|
this.selectedEReaderDevice = device
|
|
|
|
this.showEReaderDeviceModal = true
|
|
|
|
},
|
|
|
|
deleteDeviceClick(device) {
|
|
|
|
const payload = {
|
|
|
|
message: this.$getString('MessageConfirmDeleteDevice', [device.name]),
|
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.deleteDevice(device)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
|
|
|
deleteDevice(device) {
|
|
|
|
const payload = {
|
|
|
|
ereaderDevices: this.revisedEreaderDevices.filter((d) => d.name !== device.name)
|
|
|
|
}
|
|
|
|
this.deletingDeviceName = device.name
|
|
|
|
this.$axios
|
|
|
|
.$post(`/api/me/ereader-devices`, payload)
|
|
|
|
.then((data) => {
|
|
|
|
this.ereaderDevicesUpdated(data.ereaderDevices)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to delete device', error)
|
|
|
|
this.$toast.error(this.$strings.ToastRemoveFailed)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.deletingDeviceName = null
|
|
|
|
})
|
|
|
|
},
|
|
|
|
ereaderDevicesUpdated(ereaderDevices) {
|
|
|
|
this.ereaderDevices = ereaderDevices
|
2021-08-22 17:46:04 +02:00
|
|
|
}
|
|
|
|
},
|
2022-11-10 01:00:20 +01:00
|
|
|
mounted() {
|
|
|
|
this.selectedLanguage = this.$languageCodes.current
|
2024-10-26 22:34:34 +02:00
|
|
|
this.ereaderDevices = this.$store.state.libraries.ereaderDevices || []
|
2022-11-10 01:00:20 +01:00
|
|
|
}
|
2021-08-22 17:46:04 +02:00
|
|
|
}
|
2024-08-31 00:47:49 +02:00
|
|
|
</script>
|