See #75: user can now manage the Subsonic API token from their settings page
This commit is contained in:
parent
7595936260
commit
24cb1d9519
5 changed files with 264 additions and 4 deletions
|
|
@ -26,6 +26,10 @@
|
|||
<div class="ui hidden divider"></div>
|
||||
<div class="ui small text container">
|
||||
<h2 class="ui header"><i18next path="Change my password"/></h2>
|
||||
<div class="ui message">
|
||||
{{ $t('Changing your password will also change your Subsonic API password if you have requested one.') }}
|
||||
{{ $t('You will have to update your password on your clients that use this password.') }}
|
||||
</div>
|
||||
<form class="ui form" @submit.prevent="submitPassword()">
|
||||
<div v-if="passwordError" class="ui negative message">
|
||||
<div class="header"><i18next path="Cannot change your password"/></div>
|
||||
|
|
@ -41,10 +45,25 @@
|
|||
<div class="field">
|
||||
<label><i18next path="New password"/></label>
|
||||
<password-input required v-model="new_password" />
|
||||
|
||||
</div>
|
||||
<button :class="['ui', {'loading': isLoading}, 'button']" type="submit"><i18next path="Change password"/></button>
|
||||
<dangerous-button
|
||||
color="yellow"
|
||||
:class="['ui', {'loading': isLoading}, 'button']"
|
||||
:action="submitPassword">
|
||||
{{ $t('Change password') }}
|
||||
<p slot="modal-header">{{ $t('Change your password?') }}</p>
|
||||
<div slot="modal-content">
|
||||
<p>{{ $t("Changing your password will have the following consequences") }}</p>
|
||||
<ul>
|
||||
<li>{{ $t('You will be logged out from this session and have to log out with the new one') }}</li>
|
||||
<li>{{ $t('Your Subsonic password will be changed to a new, random one, logging you out from devices that used the old Subsonic password') }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p slot="modal-confirm">{{ $t('Disable access') }}</p>
|
||||
</dangerous-button>
|
||||
</form>
|
||||
<div class="ui hidden divider" />
|
||||
<subsonic-token-form />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -55,10 +74,12 @@ import $ from 'jquery'
|
|||
import axios from 'axios'
|
||||
import logger from '@/logging'
|
||||
import PasswordInput from '@/components/forms/PasswordInput'
|
||||
import SubsonicTokenForm from '@/components/auth/SubsonicTokenForm'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
PasswordInput
|
||||
PasswordInput,
|
||||
SubsonicTokenForm
|
||||
},
|
||||
data () {
|
||||
let d = {
|
||||
|
|
|
|||
137
front/src/components/auth/SubsonicTokenForm.vue
Normal file
137
front/src/components/auth/SubsonicTokenForm.vue
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<template>
|
||||
<form class="ui form" @submit.prevent="requestNewToken()">
|
||||
<h2>{{ $t('Subsonic API password') }}</h2>
|
||||
<p class="ui message" v-if="!subsonicEnabled">
|
||||
{{ $t('The Subsonic API is not available on this Funkwhale instance.') }}
|
||||
</p>
|
||||
<p>
|
||||
{{ $t('Funkwhale is compatible with other music players that support the Subsonic API.') }}
|
||||
{{ $t('You can use those to enjoy your playlist and music in offline mode, on your smartphone or tablet, for instance.') }}
|
||||
</p>
|
||||
<p>
|
||||
{{ $t('However, accessing Funkwhale from those clients require a separate password you can set below.') }}
|
||||
</p>
|
||||
<p><a href="https://docs.funkwhale.audio/users/apps.html#subsonic" target="_blank">
|
||||
{{ $t('Discover how to use Funkwhale from other apps') }}
|
||||
</a></p>
|
||||
<div v-if="success" class="ui positive message">
|
||||
<div class="header">{{ successMessage }}</div>
|
||||
</div>
|
||||
<div v-if="subsonicEnabled && errors.length > 0" class="ui negative message">
|
||||
<div class="header">{{ $t('Error') }}</div>
|
||||
<ul class="list">
|
||||
<li v-for="error in errors">{{ error }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<template v-if="subsonicEnabled">
|
||||
<div v-if="token" class="field">
|
||||
<password-input v-model="token" />
|
||||
</div>
|
||||
<dangerous-button
|
||||
v-if="token"
|
||||
color="grey"
|
||||
:class="['ui', {'loading': isLoading}, 'button']"
|
||||
:action="requestNewToken">
|
||||
{{ $t('Request a new password') }}
|
||||
<p slot="modal-header">{{ $t('Request a new Subsonic API password?') }}</p>
|
||||
<p slot="modal-content">{{ $t('This will log you out from existing devices that use the current password.') }}</p>
|
||||
<p slot="modal-confirm">{{ $t('Request a new password') }}</p>
|
||||
</dangerous-button>
|
||||
<button
|
||||
v-else
|
||||
color="grey"
|
||||
:class="['ui', {'loading': isLoading}, 'button']"
|
||||
@click="requestNewToken">{{ $t('Request a password') }}</button>
|
||||
<dangerous-button
|
||||
v-if="token"
|
||||
color="yellow"
|
||||
:class="['ui', {'loading': isLoading}, 'button']"
|
||||
:action="disable">
|
||||
{{ $t('Disable Subsonic access') }}
|
||||
<p slot="modal-header">{{ $t('Disable Subsonic API access?') }}</p>
|
||||
<p slot="modal-content">{{ $t('This will completely disable access to the Subsonic API using from account.') }}</p>
|
||||
<p slot="modal-confirm">{{ $t('Disable access') }}</p>
|
||||
</dangerous-button>
|
||||
</template>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
import PasswordInput from '@/components/forms/PasswordInput'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
PasswordInput
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
token: null,
|
||||
errors: [],
|
||||
success: false,
|
||||
isLoading: false,
|
||||
successMessage: ''
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.fetchToken()
|
||||
},
|
||||
methods: {
|
||||
fetchToken () {
|
||||
this.success = false
|
||||
this.errors = []
|
||||
this.isLoading = true
|
||||
let self = this
|
||||
let url = `users/users/${this.$store.state.auth.username}/subsonic-token/`
|
||||
return axios.get(url).then(response => {
|
||||
self.token = response.data['subsonic_api_token']
|
||||
self.isLoading = false
|
||||
}, error => {
|
||||
self.isLoading = false
|
||||
self.errors = error.backendErrors
|
||||
})
|
||||
},
|
||||
requestNewToken () {
|
||||
this.successMessage = this.$t('Password updated')
|
||||
this.success = false
|
||||
this.errors = []
|
||||
this.isLoading = true
|
||||
let self = this
|
||||
let url = `users/users/${this.$store.state.auth.username}/subsonic-token/`
|
||||
return axios.post(url, {}).then(response => {
|
||||
self.token = response.data['subsonic_api_token']
|
||||
self.isLoading = false
|
||||
self.success = true
|
||||
}, error => {
|
||||
self.isLoading = false
|
||||
self.errors = error.backendErrors
|
||||
})
|
||||
},
|
||||
disable () {
|
||||
this.successMessage = this.$t('Access disabled')
|
||||
this.success = false
|
||||
this.errors = []
|
||||
this.isLoading = true
|
||||
let self = this
|
||||
let url = `users/users/${this.$store.state.auth.username}/subsonic-token/`
|
||||
return axios.delete(url).then(response => {
|
||||
self.isLoading = false
|
||||
self.token = null
|
||||
self.success = true
|
||||
}, error => {
|
||||
self.isLoading = false
|
||||
self.errors = error.backendErrors
|
||||
})
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
subsonicEnabled () {
|
||||
return this.$store.state.instance.settings.subsonic.enabled.value
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue