lnbits-legend/lnbits/static/js/index.js
Vlad Stan bb918a8523
Login improve UI config (#2171)
* feat: show auth configs on the admin UI
* fix: do not access settings on load
* fix: redirect for click on item (not only on text)
* fix: remove `Display Name`
* fix: do not show `Verify email with` if no auth option is available
* feat: show warning before logout
* feat: i18n of account page
* fix: show account icon for user ID login
* fix: always check `isUserAuthorized`
* fix: update the `disclaimer_dialog` message
* feat: hide user ID by default
* fix: redirect from login page when user authorized
* feat: update logout message
* fix: do not translate company names
2023-12-14 11:34:23 +01:00

102 lines
2.4 KiB
JavaScript

new Vue({
el: '#vue',
mixins: [windowMixin],
data: function () {
return {
disclaimerDialog: {
show: false,
data: {},
description: ''
},
isUserAuthorized: false,
authAction: 'login',
authMethod: 'username-password',
usr: '',
username: '',
email: '',
password: '',
passwordRepeat: '',
walletName: '',
signup: false
}
},
computed: {
formatDescription() {
return LNbits.utils.convertMarkdown(this.description)
},
isAccessTokenExpired() {
return this.$q.cookies.get('is_access_token_expired')
}
},
methods: {
showLogin: function (authMethod) {
this.authAction = 'login'
this.authMethod = authMethod
},
showRegister: function (authMethod) {
this.user = ''
this.username = null
this.password = null
this.passwordRepeat = null
this.authAction = 'register'
this.authMethod = authMethod
},
register: async function () {
try {
await LNbits.api.register(
this.username,
this.email,
this.password,
this.passwordRepeat
)
window.location.href = '/wallet'
} catch (e) {
LNbits.utils.notifyApiError(e)
}
},
login: async function () {
try {
await LNbits.api.login(this.username, this.password)
window.location.href = '/wallet'
} catch (e) {
LNbits.utils.notifyApiError(e)
}
},
loginUsr: async function () {
try {
await LNbits.api.loginUsr(this.usr)
this.usr = ''
window.location.href = '/wallet'
} catch (e) {
LNbits.utils.notifyApiError(e)
}
},
createWallet: function () {
LNbits.api.createAccount(this.walletName).then(res => {
window.location = '/wallet?usr=' + res.data.user + '&wal=' + res.data.id
})
},
processing: function () {
this.$q.notify({
timeout: 0,
message: 'Processing...',
icon: null
})
},
validateUsername: function (val) {
const usernameRegex = new RegExp(
'^(?=[a-zA-Z0-9._]{2,20}$)(?!.*[_.]{2})[^_.].*[^_.]$'
)
return usernameRegex.test(val)
}
},
created() {
this.description = SITE_DESCRIPTION
this.isUserAuthorized = !!this.$q.cookies.get('is_lnbits_user_authorized')
if (this.isUserAuthorized) {
window.location.href = '/wallet'
}
}
})