2017-12-26 14:56:04 +00:00
|
|
|
<template>
|
2018-03-30 21:58:16 +00:00
|
|
|
<div class="main pusher" v-title="'Account Settings'">
|
2017-12-26 14:56:04 +00:00
|
|
|
<div class="ui vertical stripe segment">
|
|
|
|
<div class="ui small text container">
|
2018-04-14 17:28:41 +00:00
|
|
|
<h2 class="ui header"><i18next path="Account settings"/></h2>
|
2018-03-03 11:40:01 +00:00
|
|
|
<form class="ui form" @submit.prevent="submitSettings()">
|
|
|
|
<div v-if="settings.success" class="ui positive message">
|
2018-04-14 17:28:41 +00:00
|
|
|
<div class="header"><i18next path="Settings updated"/></div>
|
2018-03-03 11:40:01 +00:00
|
|
|
</div>
|
|
|
|
<div v-if="settings.errors.length > 0" class="ui negative message">
|
2018-04-14 17:28:41 +00:00
|
|
|
<i18next tag="div" class="header" path="We cannot save your settings"/>
|
2018-03-03 11:40:01 +00:00
|
|
|
<ul class="list">
|
|
|
|
<li v-for="error in settings.errors">{{ error }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="field" v-for="f in orderedSettingsFields">
|
|
|
|
<label :for="f.id">{{ f.label }}</label>
|
|
|
|
<p v-if="f.help">{{ f.help }}</p>
|
|
|
|
<select v-if="f.type === 'dropdown'" class="ui dropdown" v-model="f.value">
|
|
|
|
<option :value="c.value" v-for="c in f.choices">{{ c.label }}</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
2018-04-14 17:28:41 +00:00
|
|
|
<button :class="['ui', {'loading': isLoading}, 'button']" type="submit"><i18next path="Update settings"/></button>
|
2018-03-03 11:40:01 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<div class="ui hidden divider"></div>
|
|
|
|
<div class="ui small text container">
|
2018-04-14 17:28:41 +00:00
|
|
|
<h2 class="ui header"><i18next path="Change my password"/></h2>
|
2018-05-09 20:18:33 +00:00
|
|
|
<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>
|
2018-03-03 11:40:01 +00:00
|
|
|
<form class="ui form" @submit.prevent="submitPassword()">
|
|
|
|
<div v-if="passwordError" class="ui negative message">
|
2018-04-14 17:28:41 +00:00
|
|
|
<div class="header"><i18next path="Cannot change your password"/></div>
|
2017-12-26 14:56:04 +00:00
|
|
|
<ul class="list">
|
2018-04-14 17:28:41 +00:00
|
|
|
<i18next tag="li" v-if="passwordError == 'invalid_credentials'" path="Please double-check your password is correct"/>
|
2017-12-26 14:56:04 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2018-04-14 17:28:41 +00:00
|
|
|
<label><i18next path="Old password"/></label>
|
2018-05-06 09:19:20 +00:00
|
|
|
<password-input required v-model="old_password" />
|
|
|
|
|
2017-12-26 14:56:04 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2018-04-14 17:28:41 +00:00
|
|
|
<label><i18next path="New password"/></label>
|
2018-05-06 09:19:20 +00:00
|
|
|
<password-input required v-model="new_password" />
|
2017-12-26 14:56:04 +00:00
|
|
|
</div>
|
2018-05-09 20:18:33 +00:00
|
|
|
<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>
|
2017-12-26 14:56:04 +00:00
|
|
|
</form>
|
2018-05-09 20:18:33 +00:00
|
|
|
<div class="ui hidden divider" />
|
|
|
|
<subsonic-token-form />
|
2017-12-26 14:56:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-03-03 11:40:01 +00:00
|
|
|
import $ from 'jquery'
|
2018-01-11 20:35:51 +00:00
|
|
|
import axios from 'axios'
|
2017-12-26 14:56:04 +00:00
|
|
|
import logger from '@/logging'
|
2018-05-06 09:19:20 +00:00
|
|
|
import PasswordInput from '@/components/forms/PasswordInput'
|
2018-05-09 20:18:33 +00:00
|
|
|
import SubsonicTokenForm from '@/components/auth/SubsonicTokenForm'
|
2017-12-26 14:56:04 +00:00
|
|
|
|
|
|
|
export default {
|
2018-05-06 09:19:20 +00:00
|
|
|
components: {
|
2018-05-09 20:18:33 +00:00
|
|
|
PasswordInput,
|
|
|
|
SubsonicTokenForm
|
2018-05-06 09:19:20 +00:00
|
|
|
},
|
2017-12-26 14:56:04 +00:00
|
|
|
data () {
|
2018-03-03 11:40:01 +00:00
|
|
|
let d = {
|
2017-12-26 14:56:04 +00:00
|
|
|
// We need to initialize the component with any
|
|
|
|
// properties that will be used in it
|
|
|
|
old_password: '',
|
|
|
|
new_password: '',
|
2018-03-03 11:40:01 +00:00
|
|
|
passwordError: '',
|
|
|
|
isLoading: false,
|
|
|
|
settings: {
|
|
|
|
success: false,
|
|
|
|
errors: [],
|
|
|
|
order: ['privacy_level'],
|
|
|
|
fields: {
|
|
|
|
'privacy_level': {
|
|
|
|
type: 'dropdown',
|
|
|
|
initial: this.$store.state.auth.profile.privacy_level,
|
2018-04-16 20:46:54 +00:00
|
|
|
label: 'Activity visibility',
|
|
|
|
help: 'Determine the visibility level of your activity',
|
2018-03-03 11:40:01 +00:00
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
value: 'me',
|
2018-04-16 20:46:54 +00:00
|
|
|
label: 'Nobody except me'
|
2018-03-03 11:40:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'instance',
|
2018-04-16 20:46:54 +00:00
|
|
|
label: 'Everyone on this instance'
|
2018-03-03 11:40:01 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-26 14:56:04 +00:00
|
|
|
}
|
2018-03-03 11:40:01 +00:00
|
|
|
d.settings.order.forEach(id => {
|
|
|
|
d.settings.fields[id].value = d.settings.fields[id].initial
|
|
|
|
})
|
|
|
|
return d
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
$('select.dropdown').dropdown()
|
2017-12-26 14:56:04 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2018-03-03 11:40:01 +00:00
|
|
|
submitSettings () {
|
|
|
|
this.settings.success = false
|
|
|
|
this.settings.errors = []
|
|
|
|
let self = this
|
|
|
|
let payload = this.settingsValues
|
|
|
|
let url = `users/users/${this.$store.state.auth.username}/`
|
|
|
|
return axios.patch(url, payload).then(response => {
|
|
|
|
logger.default.info('Updated settings successfully')
|
|
|
|
self.settings.success = true
|
|
|
|
}, error => {
|
|
|
|
logger.default.error('Error while updating settings')
|
|
|
|
self.isLoading = false
|
|
|
|
self.settings.errors = error.backendErrors
|
|
|
|
})
|
|
|
|
},
|
|
|
|
submitPassword () {
|
2017-12-26 14:56:04 +00:00
|
|
|
var self = this
|
|
|
|
self.isLoading = true
|
|
|
|
this.error = ''
|
|
|
|
var credentials = {
|
|
|
|
old_password: this.old_password,
|
|
|
|
new_password1: this.new_password,
|
|
|
|
new_password2: this.new_password
|
|
|
|
}
|
2018-02-24 13:28:48 +00:00
|
|
|
let url = 'auth/registration/change-password/'
|
2018-01-11 20:35:51 +00:00
|
|
|
return axios.post(url, credentials).then(response => {
|
2017-12-26 14:56:04 +00:00
|
|
|
logger.default.info('Password successfully changed')
|
2018-02-24 13:28:48 +00:00
|
|
|
self.$router.push({
|
|
|
|
name: 'profile',
|
|
|
|
params: {
|
|
|
|
username: self.$store.state.auth.username
|
|
|
|
}})
|
|
|
|
}, error => {
|
|
|
|
if (error.response.status === 400) {
|
2018-03-03 11:40:01 +00:00
|
|
|
self.passwordError = 'invalid_credentials'
|
2017-12-26 14:56:04 +00:00
|
|
|
} else {
|
2018-03-03 11:40:01 +00:00
|
|
|
self.passwordError = 'unknown_error'
|
2017-12-26 14:56:04 +00:00
|
|
|
}
|
|
|
|
self.isLoading = false
|
|
|
|
})
|
|
|
|
}
|
2018-03-03 11:40:01 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
orderedSettingsFields () {
|
|
|
|
let self = this
|
|
|
|
return this.settings.order.map(id => {
|
|
|
|
return self.settings.fields[id]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
settingsValues () {
|
|
|
|
let self = this
|
|
|
|
let s = {}
|
|
|
|
this.settings.order.forEach(setting => {
|
|
|
|
let conf = self.settings.fields[setting]
|
|
|
|
s[setting] = conf.value
|
|
|
|
})
|
|
|
|
return s
|
|
|
|
}
|
2017-12-26 14:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style scoped>
|
|
|
|
</style>
|