2024-09-24 11:06:27 +02:00
|
|
|
window.app = Vue.createApp({
|
2023-12-12 12:38:19 +02:00
|
|
|
el: '#vue',
|
2024-09-24 11:06:27 +02:00
|
|
|
mixins: [window.windowMixin],
|
2024-12-10 13:42:01 +01:00
|
|
|
data() {
|
2023-12-12 12:38:19 +02:00
|
|
|
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-10-29 09:58:22 +01:00
|
|
|
borderOptions: ['retro-border', 'hard-border', 'no-border'],
|
2024-01-15 11:51:34 +02:00
|
|
|
tab: 'user',
|
2024-09-30 14:53:38 +03:00
|
|
|
credentialsData: {
|
2023-12-12 12:38:19 +02:00
|
|
|
show: false,
|
|
|
|
oldPassword: null,
|
|
|
|
newPassword: null,
|
2024-09-30 14:53:38 +03:00
|
|
|
newPasswordRepeat: null,
|
|
|
|
username: null,
|
|
|
|
pubkey: null
|
2023-12-12 12:38:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-12-10 13:42:01 +01:00
|
|
|
activeLanguage(lang) {
|
2024-09-25 12:09:00 +02:00
|
|
|
return window.i18n.global.locale === lang
|
2024-01-15 11:51:34 +02:00
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
changeLanguage(newValue) {
|
2024-09-25 12:09:00 +02:00
|
|
|
window.i18n.global.locale = newValue
|
2024-01-15 11:51:34 +02:00
|
|
|
this.$q.localStorage.set('lnbits.lang', newValue)
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
toggleDarkMode() {
|
2024-01-15 11:51:34 +02:00
|
|
|
this.$q.dark.toggle()
|
|
|
|
this.$q.localStorage.set('lnbits.darkMode', this.$q.dark.isActive)
|
2024-08-30 17:16:24 +01:00
|
|
|
if (!this.$q.dark.isActive && this.gradientChoice) {
|
|
|
|
this.toggleGradient()
|
|
|
|
}
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
applyGradient() {
|
2024-08-30 17:16:24 +01:00
|
|
|
darkBgColor = this.$q.localStorage.getItem('lnbits.darkBgColor')
|
|
|
|
primaryColor = this.$q.localStorage.getItem('lnbits.primaryColor')
|
|
|
|
if (this.gradientChoice) {
|
|
|
|
if (!this.$q.dark.isActive) {
|
|
|
|
this.toggleDarkMode()
|
|
|
|
}
|
|
|
|
const gradientStyle = `linear-gradient(to bottom right, ${LNbits.utils.hexDarken(String(primaryColor), -70)}, #0a0a0a)`
|
|
|
|
document.body.style.setProperty(
|
|
|
|
'background-image',
|
|
|
|
gradientStyle,
|
|
|
|
'important'
|
|
|
|
)
|
|
|
|
const gradientStyleCards = `background-color: ${LNbits.utils.hexAlpha(String(darkBgColor), 0.4)} !important`
|
|
|
|
const style = document.createElement('style')
|
|
|
|
style.innerHTML =
|
|
|
|
`body[data-theme="${this.$q.localStorage.getItem('lnbits.theme')}"] .q-card:not(.q-dialog .q-card, .lnbits__dialog-card, .q-dialog-plugin--dark), body.body${this.$q.dark.isActive ? '--dark' : ''} .q-header, body.body${this.$q.dark.isActive ? '--dark' : ''} .q-drawer { ${gradientStyleCards} }` +
|
|
|
|
`body[data-theme="${this.$q.localStorage.getItem('lnbits.theme')}"].body--dark{background: ${LNbits.utils.hexDarken(String(primaryColor), -88)} !important; }` +
|
|
|
|
`[data-theme="${this.$q.localStorage.getItem('lnbits.theme')}"] .q-card--dark{background: ${String(darkBgColor)} !important;} }`
|
|
|
|
document.head.appendChild(style)
|
|
|
|
this.$q.localStorage.set('lnbits.gradientBg', true)
|
|
|
|
} else {
|
|
|
|
this.$q.localStorage.set('lnbits.gradientBg', false)
|
|
|
|
}
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
applyBorder() {
|
2024-10-29 09:58:22 +01:00
|
|
|
if (this.borderChoice) {
|
|
|
|
this.$q.localStorage.setItem('lnbits.border', this.borderChoice)
|
|
|
|
}
|
|
|
|
let borderStyle = this.$q.localStorage.getItem('lnbits.border')
|
|
|
|
this.borderChoice = borderStyle
|
|
|
|
let borderStyleCSS
|
|
|
|
if (borderStyle == 'hard-border') {
|
|
|
|
borderStyleCSS = `box-shadow: 0 0 0 1px rgba(0,0,0,.12), 0 0 0 1px #ffffff47; border: none;`
|
|
|
|
}
|
|
|
|
if (borderStyle == 'no-border') {
|
|
|
|
borderStyleCSS = `box-shadow: none; border: none;`
|
|
|
|
}
|
|
|
|
if (borderStyle == 'retro-border') {
|
|
|
|
borderStyleCSS = `border: none; border-color: rgba(255, 255, 255, 0.28); box-shadow: 0 1px 5px rgba(255, 255, 255, 0.2), 0 2px 2px rgba(255, 255, 255, 0.14), 0 3px 1px -2px rgba(255, 255, 255, 0.12);`
|
|
|
|
}
|
|
|
|
let style = document.createElement('style')
|
|
|
|
style.innerHTML = `body[data-theme="${this.$q.localStorage.getItem('lnbits.theme')}"] .q-card.q-card--dark, .q-date--dark { ${borderStyleCSS} }`
|
|
|
|
document.head.appendChild(style)
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
toggleGradient() {
|
2024-08-30 17:16:24 +01:00
|
|
|
this.gradientChoice = !this.gradientChoice
|
|
|
|
this.applyGradient()
|
|
|
|
if (!this.gradientChoice) {
|
|
|
|
window.location.reload()
|
|
|
|
}
|
|
|
|
this.gradientChoice = this.$q.localStorage.getItem('lnbits.gradientBg')
|
2024-01-15 11:51:34 +02:00
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
reactionChoiceFunc() {
|
2024-02-12 10:48:07 +00:00
|
|
|
this.$q.localStorage.set('lnbits.reactions', this.reactionChoice)
|
2024-02-08 13:34:03 +00:00
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
changeColor(newValue) {
|
2024-01-15 11:51:34 +02:00
|
|
|
document.body.setAttribute('data-theme', newValue)
|
|
|
|
this.$q.localStorage.set('lnbits.theme', newValue)
|
2024-08-30 17:16:24 +01:00
|
|
|
this.setColors()
|
|
|
|
if (this.$q.localStorage.getItem('lnbits.gradientBg')) {
|
|
|
|
this.applyGradient()
|
|
|
|
}
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
async updateAccount() {
|
2023-12-12 12:38:19 +02:00
|
|
|
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,
|
2024-10-29 09:58:22 +01:00
|
|
|
extra: this.user.extra
|
2023-12-12 12:38:19 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
this.user = data
|
2024-09-30 14:53:38 +03:00
|
|
|
this.hasUsername = !!data.username
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2023-12-12 12:38:19 +02:00
|
|
|
type: 'positive',
|
|
|
|
message: 'Account updated.'
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
|
|
|
}
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
disableUpdatePassword() {
|
2024-09-30 14:53:38 +03:00
|
|
|
return (
|
|
|
|
!this.credentialsData.newPassword ||
|
|
|
|
!this.credentialsData.newPasswordRepeat ||
|
|
|
|
this.credentialsData.newPassword !==
|
|
|
|
this.credentialsData.newPasswordRepeat
|
|
|
|
)
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
async updatePassword() {
|
2024-09-30 14:53:38 +03:00
|
|
|
if (!this.credentialsData.username) {
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2024-02-06 11:48:13 +02:00
|
|
|
type: 'warning',
|
2024-09-30 14:53:38 +03:00
|
|
|
message: 'Please set a username.'
|
2024-02-06 11:48:13 +02:00
|
|
|
})
|
|
|
|
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-09-30 14:53:38 +03:00
|
|
|
username: this.credentialsData.username,
|
|
|
|
password_old: this.credentialsData.oldPassword,
|
|
|
|
password: this.credentialsData.newPassword,
|
|
|
|
password_repeat: this.credentialsData.newPasswordRepeat
|
2023-12-12 12:38:19 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
this.user = data
|
2024-09-30 14:53:38 +03:00
|
|
|
this.hasUsername = !!data.username
|
|
|
|
this.credentialsData.show = false
|
2024-09-24 16:18:56 +02:00
|
|
|
Quasar.Notify.create({
|
2023-12-12 12:38:19 +02:00
|
|
|
type: 'positive',
|
|
|
|
message: 'Password updated.'
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
|
|
|
}
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
async updatePubkey() {
|
2024-09-30 14:53:38 +03:00
|
|
|
try {
|
|
|
|
const {data} = await LNbits.api.request(
|
|
|
|
'PUT',
|
|
|
|
'/api/v1/auth/pubkey',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
user_id: this.user.id,
|
|
|
|
pubkey: this.credentialsData.pubkey
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.user = data
|
|
|
|
this.hasUsername = !!data.username
|
|
|
|
this.credentialsData.show = false
|
|
|
|
this.$q.notify({
|
|
|
|
type: 'positive',
|
|
|
|
message: 'Public key updated.'
|
2024-02-06 11:48:13 +02:00
|
|
|
})
|
2024-09-30 14:53:38 +03:00
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
2024-02-06 11:48:13 +02:00
|
|
|
}
|
2024-09-30 14:53:38 +03:00
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
showUpdateCredentials() {
|
2024-09-30 14:53:38 +03:00
|
|
|
this.credentialsData = {
|
2023-12-12 12:38:19 +02:00
|
|
|
show: true,
|
|
|
|
oldPassword: null,
|
2024-09-30 14:53:38 +03:00
|
|
|
username: this.user.username,
|
|
|
|
pubkey: this.user.pubkey,
|
2023-12-12 12:38:19 +02:00
|
|
|
newPassword: null,
|
|
|
|
newPasswordRepeat: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-12-10 13:42:01 +01:00
|
|
|
async created() {
|
2023-12-12 12:38:19 +02:00
|
|
|
try {
|
|
|
|
const {data} = await LNbits.api.getAuthenticatedUser()
|
|
|
|
this.user = data
|
|
|
|
this.hasUsername = !!data.username
|
2024-10-29 09:58:22 +01:00
|
|
|
if (!this.user.extra) this.user.extra = {}
|
2023-12-12 12:38:19 +02:00
|
|
|
} catch (e) {
|
|
|
|
LNbits.utils.notifyApiError(e)
|
|
|
|
}
|
2024-08-30 17:16:24 +01:00
|
|
|
if (this.$q.localStorage.getItem('lnbits.gradientBg')) {
|
|
|
|
this.applyGradient()
|
|
|
|
}
|
2024-10-29 09:58:22 +01:00
|
|
|
if (this.$q.localStorage.getItem('lnbits.border')) {
|
|
|
|
this.applyBorder()
|
|
|
|
}
|
2024-12-20 08:07:50 +00:00
|
|
|
const hash = window.location.hash.replace('#', '')
|
|
|
|
if (hash) {
|
|
|
|
this.tab = hash
|
|
|
|
}
|
2023-12-12 12:38:19 +02:00
|
|
|
}
|
|
|
|
})
|