2023-12-12 12:38:19 +02:00
|
|
|
new Vue({
|
|
|
|
el: '#vue',
|
|
|
|
mixins: [windowMixin],
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
user: null,
|
|
|
|
hasUsername: false,
|
2023-12-14 12:34:23 +02:00
|
|
|
showUserId: false,
|
2024-02-12 10:48:07 +00:00
|
|
|
reactionOptions: [
|
|
|
|
'None',
|
|
|
|
'confettiBothSides',
|
|
|
|
'confettiFireworks',
|
|
|
|
'confettiStars'
|
|
|
|
],
|
2024-01-15 11:51:34 +02:00
|
|
|
tab: 'user',
|
2023-12-12 12:38:19 +02:00
|
|
|
passwordData: {
|
|
|
|
show: false,
|
|
|
|
oldPassword: null,
|
|
|
|
newPassword: null,
|
|
|
|
newPasswordRepeat: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-01-15 11:51:34 +02:00
|
|
|
activeLanguage: function (lang) {
|
|
|
|
return window.i18n.locale === lang
|
|
|
|
},
|
|
|
|
changeLanguage: function (newValue) {
|
|
|
|
window.i18n.locale = newValue
|
|
|
|
this.$q.localStorage.set('lnbits.lang', newValue)
|
|
|
|
},
|
|
|
|
toggleDarkMode: function () {
|
|
|
|
this.$q.dark.toggle()
|
|
|
|
this.$q.localStorage.set('lnbits.darkMode', this.$q.dark.isActive)
|
|
|
|
},
|
2024-02-12 10:48:07 +00:00
|
|
|
reactionChoiceFunc: function () {
|
|
|
|
this.$q.localStorage.set('lnbits.reactions', this.reactionChoice)
|
2024-02-08 13:34:03 +00:00
|
|
|
},
|
2024-01-15 11:51:34 +02:00
|
|
|
changeColor: function (newValue) {
|
|
|
|
document.body.setAttribute('data-theme', newValue)
|
|
|
|
this.$q.localStorage.set('lnbits.theme', newValue)
|
|
|
|
},
|
2023-12-12 12:38:19 +02:00
|
|
|
updateAccount: async function () {
|
|
|
|
try {
|
|
|
|
const {data} = await LNbits.api.request(
|
|
|
|
'PUT',
|
|
|
|
'/api/v1/auth/update',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
user_id: this.user.id,
|
|
|
|
username: this.user.username,
|
|
|
|
email: this.user.email,
|
|
|
|
config: this.user.config
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.user = data
|
|
|
|
this.$q.notify({
|
|
|
|
type: 'positive',
|
|
|
|
message: 'Account updated.'
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updatePassword: async function () {
|
2024-02-06 11:48:13 +02:00
|
|
|
if (!this.user.username) {
|
|
|
|
this.$q.notify({
|
|
|
|
type: 'warning',
|
|
|
|
message: 'Please set a username first.'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2023-12-12 12:38:19 +02:00
|
|
|
try {
|
|
|
|
const {data} = await LNbits.api.request(
|
|
|
|
'PUT',
|
|
|
|
'/api/v1/auth/password',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
user_id: this.user.id,
|
2024-02-06 11:48:13 +02:00
|
|
|
username: this.user.username,
|
2023-12-12 12:38:19 +02:00
|
|
|
password_old: this.passwordData.oldPassword,
|
|
|
|
password: this.passwordData.newPassword,
|
|
|
|
password_repeat: this.passwordData.newPasswordRepeat
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.user = data
|
|
|
|
this.passwordData.show = false
|
|
|
|
this.$q.notify({
|
|
|
|
type: 'positive',
|
|
|
|
message: 'Password updated.'
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
showChangePassword: function () {
|
2024-02-06 11:48:13 +02:00
|
|
|
if (!this.user.username) {
|
|
|
|
this.$q.notify({
|
|
|
|
type: 'warning',
|
|
|
|
message: 'Please set a username first.'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2023-12-12 12:38:19 +02:00
|
|
|
this.passwordData = {
|
|
|
|
show: true,
|
|
|
|
oldPassword: null,
|
|
|
|
newPassword: null,
|
|
|
|
newPasswordRepeat: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created: async function () {
|
|
|
|
try {
|
|
|
|
const {data} = await LNbits.api.getAuthenticatedUser()
|
|
|
|
this.user = data
|
|
|
|
this.hasUsername = !!data.username
|
2023-12-12 17:25:35 +00:00
|
|
|
if (!this.user.config) this.user.config = {}
|
2023-12-12 12:38:19 +02:00
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|