feat: dynamic login and registering (#3604)
This commit is contained in:
parent
73634e5161
commit
625fa6503c
11 changed files with 49 additions and 34 deletions
|
|
@ -225,7 +225,7 @@ async def index(
|
||||||
@generic_router.get("/node/public")
|
@generic_router.get("/node/public")
|
||||||
@generic_router.get("/first_install", dependencies=[Depends(check_first_install)])
|
@generic_router.get("/first_install", dependencies=[Depends(check_first_install)])
|
||||||
async def index_public(request: Request) -> HTMLResponse:
|
async def index_public(request: Request) -> HTMLResponse:
|
||||||
return template_renderer().TemplateResponse(request, "index_public.html")
|
return template_renderer().TemplateResponse(request, "index.html", {"public": True})
|
||||||
|
|
||||||
|
|
||||||
@generic_router.get("/uuidv4/{hex_value}")
|
@generic_router.get("/uuidv4/{hex_value}")
|
||||||
|
|
|
||||||
2
lnbits/static/bundle-components.min.js
vendored
2
lnbits/static/bundle-components.min.js
vendored
File diff suppressed because one or more lines are too long
2
lnbits/static/bundle.min.js
vendored
2
lnbits/static/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -89,6 +89,12 @@ window._lnbitsApi = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
getAuthUser() {
|
||||||
|
return axios({
|
||||||
|
method: 'GET',
|
||||||
|
url: '/api/v1/auth'
|
||||||
|
})
|
||||||
|
},
|
||||||
login(username, password) {
|
login(username, password) {
|
||||||
return axios({
|
return axios({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,14 @@ const localStore = (key, defaultValue) => {
|
||||||
window.g = Vue.reactive({
|
window.g = Vue.reactive({
|
||||||
errorCode: null,
|
errorCode: null,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
|
user: null,
|
||||||
|
wallet: null,
|
||||||
|
isPublicPage: true,
|
||||||
isUserAuthorized: !!Quasar.Cookies.get('is_lnbits_user_authorized'),
|
isUserAuthorized: !!Quasar.Cookies.get('is_lnbits_user_authorized'),
|
||||||
offline: !navigator.onLine,
|
offline: !navigator.onLine,
|
||||||
hasCamera: false,
|
hasCamera: false,
|
||||||
visibleDrawer: false,
|
visibleDrawer: false,
|
||||||
extensions: WINDOW_SETTINGS.EXTENSIONS,
|
extensions: WINDOW_SETTINGS.EXTENSIONS,
|
||||||
user: null,
|
|
||||||
wallet: {},
|
|
||||||
fiatBalance: 0,
|
fiatBalance: 0,
|
||||||
exchangeRate: 0,
|
exchangeRate: 0,
|
||||||
fiatTracking: false,
|
fiatTracking: false,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ const routes = [
|
||||||
{
|
{
|
||||||
path: '/wallet',
|
path: '/wallet',
|
||||||
redirect: to => {
|
redirect: to => {
|
||||||
const walletId = window.g?.lastActiveWallet || window.user?.wallets[0].id
|
const walletId =
|
||||||
|
window.g?.lastActiveWallet || window.g?.user?.wallets[0].id
|
||||||
return `/wallet/${to.query.wal || walletId || 'default'}`
|
return `/wallet/${to.query.wal || walletId || 'default'}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ window.PageHome = {
|
||||||
this.password,
|
this.password,
|
||||||
this.passwordRepeat
|
this.passwordRepeat
|
||||||
)
|
)
|
||||||
window.location.href = '/wallet'
|
this.refreshAuthUser()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LNbits.utils.notifyApiError(e)
|
LNbits.utils.notifyApiError(e)
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +98,7 @@ window.PageHome = {
|
||||||
this.password,
|
this.password,
|
||||||
this.passwordRepeat
|
this.passwordRepeat
|
||||||
)
|
)
|
||||||
window.location.href = '/wallet'
|
this.refreshAuthUser()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LNbits.utils.notifyApiError(e)
|
LNbits.utils.notifyApiError(e)
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ window.PageHome = {
|
||||||
async login() {
|
async login() {
|
||||||
try {
|
try {
|
||||||
await LNbits.api.login(this.username, this.password)
|
await LNbits.api.login(this.username, this.password)
|
||||||
window.location.href = '/wallet'
|
this.refreshAuthUser()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LNbits.utils.notifyApiError(e)
|
LNbits.utils.notifyApiError(e)
|
||||||
}
|
}
|
||||||
|
|
@ -114,8 +114,18 @@ window.PageHome = {
|
||||||
async loginUsr() {
|
async loginUsr() {
|
||||||
try {
|
try {
|
||||||
await LNbits.api.loginUsr(this.usr)
|
await LNbits.api.loginUsr(this.usr)
|
||||||
this.usr = ''
|
this.refreshAuthUser()
|
||||||
window.location.href = '/wallet'
|
} catch (e) {
|
||||||
|
console.warn(e)
|
||||||
|
LNbits.utils.notifyApiError(e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async refreshAuthUser() {
|
||||||
|
try {
|
||||||
|
const res = await LNbits.api.getAuthUser()
|
||||||
|
this.g.user = LNbits.map.user(res.data)
|
||||||
|
this.g.isPublicPage = false
|
||||||
|
this.$router.push(`/wallet/${this.g.user.wallets[0].id}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e)
|
console.warn(e)
|
||||||
LNbits.utils.notifyApiError(e)
|
LNbits.utils.notifyApiError(e)
|
||||||
|
|
@ -123,7 +133,7 @@ window.PageHome = {
|
||||||
},
|
},
|
||||||
createWallet() {
|
createWallet() {
|
||||||
LNbits.api.createAccount(this.walletName).then(res => {
|
LNbits.api.createAccount(this.walletName).then(res => {
|
||||||
window.location = '/wallet?usr=' + res.data.user + '&wal=' + res.data.id
|
this.$router.push(`/wallet/${res.data.id}`)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
processing() {
|
processing() {
|
||||||
|
|
@ -136,7 +146,7 @@ window.PageHome = {
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.g.isUserAuthorized) {
|
if (this.g.isUserAuthorized) {
|
||||||
window.location.href = '/wallet'
|
return this.refreshAuthUser()
|
||||||
}
|
}
|
||||||
const urlParams = new URLSearchParams(window.location.search)
|
const urlParams = new URLSearchParams(window.location.search)
|
||||||
this.reset_key = urlParams.get('reset_key')
|
this.reset_key = urlParams.get('reset_key')
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ window.windowMixin = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
paymentEvents() {
|
paymentEvents() {
|
||||||
|
if (!this.g.user) return
|
||||||
let timeout
|
let timeout
|
||||||
this.g.user.wallets.forEach(wallet => {
|
this.g.user.wallets.forEach(wallet => {
|
||||||
if (!this.g.walletEventListeners.includes(wallet.id)) {
|
if (!this.g.walletEventListeners.includes(wallet.id)) {
|
||||||
|
|
|
||||||
|
|
@ -33,23 +33,28 @@
|
||||||
<body data-theme="bitcoin">
|
<body data-theme="bitcoin">
|
||||||
<div id="vue">
|
<div id="vue">
|
||||||
<q-layout view="hHh lpR lfr" v-cloak>
|
<q-layout view="hHh lpR lfr" v-cloak>
|
||||||
<lnbits-disclaimer></lnbits-disclaimer>
|
<lnbits-disclaimer v-if="g.user && !g.isPublicPage"></lnbits-disclaimer>
|
||||||
<lnbits-qrcode-scanner @detect="handleScan"></lnbits-qrcode-scanner>
|
<lnbits-qrcode-scanner @detect="handleScan"></lnbits-qrcode-scanner>
|
||||||
<lnbits-theme></lnbits-theme>
|
<lnbits-theme></lnbits-theme>
|
||||||
<lnbits-header></lnbits-header>
|
<lnbits-header></lnbits-header>
|
||||||
{% block drawer %}
|
<lnbits-drawer v-if="g.user && !g.isPublicPage"></lnbits-drawer>
|
||||||
<lnbits-drawer></lnbits-drawer>
|
{% block page_container %}
|
||||||
{% endblock %} {% block page_container %}
|
|
||||||
<q-page-container>
|
<q-page-container>
|
||||||
<q-page class="q-px-md q-py-lg" :class="{'q-px-lg': $q.screen.gt.xs}">
|
<q-page class="q-px-md q-py-lg" :class="{'q-px-lg': $q.screen.gt.xs}">
|
||||||
<lnbits-wallet-new></lnbits-wallet-new>
|
<lnbits-wallet-new
|
||||||
<lnbits-header-wallets></lnbits-header-wallets>
|
v-if="g.user && !g.isPublicPage"
|
||||||
|
></lnbits-wallet-new>
|
||||||
|
<lnbits-header-wallets
|
||||||
|
v-if="g.user && !g.isPublicPage"
|
||||||
|
></lnbits-header-wallets>
|
||||||
<router-view v-if="isVueRoute" :key="$route.path"></router-view>
|
<router-view v-if="isVueRoute" :key="$route.path"></router-view>
|
||||||
<!-- FastAPI Content from extensions -->
|
<!-- FastAPI Content from extensions -->
|
||||||
<div v-else>{% block page %}{% endblock %}</div>
|
<div v-else>{% block page %}{% endblock %}</div>
|
||||||
</q-page>
|
</q-page>
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
{% endblock %} {% block footer %}
|
{% endblock %}
|
||||||
|
<!-- Footer -->
|
||||||
|
{% block footer %}
|
||||||
<lnbits-footer />
|
<lnbits-footer />
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</q-layout>
|
</q-layout>
|
||||||
|
|
@ -72,6 +77,9 @@
|
||||||
{% if user %}
|
{% if user %}
|
||||||
<script>
|
<script>
|
||||||
window.g.user = LNbits.map.user(JSON.parse({{ user | tojson | safe }}));
|
window.g.user = LNbits.map.user(JSON.parse({{ user | tojson | safe }}));
|
||||||
|
{% if not public %}
|
||||||
|
window.g.isPublicPage = false
|
||||||
|
{% endif %}
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- scripts from extensions -->
|
<!-- scripts from extensions -->
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
</q-banner>
|
</q-banner>
|
||||||
<q-toolbar>
|
<q-toolbar>
|
||||||
<q-btn
|
<q-btn
|
||||||
|
v-if="!g.isPublicPage"
|
||||||
dense
|
dense
|
||||||
flat
|
flat
|
||||||
round
|
round
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1 @@
|
||||||
{% extends "base.html" %} {% block beta %}{% endblock %} {% block drawer_toggle
|
{% extends "base.html" %}
|
||||||
%}{% endblock %} {% block drawer %}{% endblock %} {% block toolbar_title %}
|
|
||||||
<a
|
|
||||||
href="/"
|
|
||||||
class="inherit q-btn q-btn-item non-selectable no-outline q-btn--flat q-btn--rectangle q-btn--actionable q-focusable q-hoverable q-btn--no-uppercase q-btn--wrap q-btn--dense q-btn--active"
|
|
||||||
style="font-size: 20px"
|
|
||||||
>
|
|
||||||
{% if USE_CUSTOM_LOGO %}
|
|
||||||
<img height="30px" alt="Logo" src="{{ USE_CUSTOM_LOGO }}" />
|
|
||||||
{%else%} {% if SITE_TITLE != 'LNbits' %} {{ SITE_TITLE }} {% else %}
|
|
||||||
<span><strong>LN</strong>bits</span>
|
|
||||||
{% endif %} {% endif %}
|
|
||||||
</a>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue