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("/first_install", dependencies=[Depends(check_first_install)])
|
||||
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}")
|
||||
|
|
|
|||
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) {
|
||||
return axios({
|
||||
method: 'POST',
|
||||
|
|
|
|||
|
|
@ -11,13 +11,14 @@ const localStore = (key, defaultValue) => {
|
|||
window.g = Vue.reactive({
|
||||
errorCode: null,
|
||||
errorMessage: null,
|
||||
user: null,
|
||||
wallet: null,
|
||||
isPublicPage: true,
|
||||
isUserAuthorized: !!Quasar.Cookies.get('is_lnbits_user_authorized'),
|
||||
offline: !navigator.onLine,
|
||||
hasCamera: false,
|
||||
visibleDrawer: false,
|
||||
extensions: WINDOW_SETTINGS.EXTENSIONS,
|
||||
user: null,
|
||||
wallet: {},
|
||||
fiatBalance: 0,
|
||||
exchangeRate: 0,
|
||||
fiatTracking: false,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ const routes = [
|
|||
{
|
||||
path: '/wallet',
|
||||
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'}`
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ window.PageHome = {
|
|||
this.password,
|
||||
this.passwordRepeat
|
||||
)
|
||||
window.location.href = '/wallet'
|
||||
this.refreshAuthUser()
|
||||
} catch (e) {
|
||||
LNbits.utils.notifyApiError(e)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ window.PageHome = {
|
|||
this.password,
|
||||
this.passwordRepeat
|
||||
)
|
||||
window.location.href = '/wallet'
|
||||
this.refreshAuthUser()
|
||||
} catch (e) {
|
||||
LNbits.utils.notifyApiError(e)
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ window.PageHome = {
|
|||
async login() {
|
||||
try {
|
||||
await LNbits.api.login(this.username, this.password)
|
||||
window.location.href = '/wallet'
|
||||
this.refreshAuthUser()
|
||||
} catch (e) {
|
||||
LNbits.utils.notifyApiError(e)
|
||||
}
|
||||
|
|
@ -114,8 +114,18 @@ window.PageHome = {
|
|||
async loginUsr() {
|
||||
try {
|
||||
await LNbits.api.loginUsr(this.usr)
|
||||
this.usr = ''
|
||||
window.location.href = '/wallet'
|
||||
this.refreshAuthUser()
|
||||
} 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) {
|
||||
console.warn(e)
|
||||
LNbits.utils.notifyApiError(e)
|
||||
|
|
@ -123,7 +133,7 @@ window.PageHome = {
|
|||
},
|
||||
createWallet() {
|
||||
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() {
|
||||
|
|
@ -136,7 +146,7 @@ window.PageHome = {
|
|||
},
|
||||
created() {
|
||||
if (this.g.isUserAuthorized) {
|
||||
window.location.href = '/wallet'
|
||||
return this.refreshAuthUser()
|
||||
}
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
this.reset_key = urlParams.get('reset_key')
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ window.windowMixin = {
|
|||
}
|
||||
},
|
||||
paymentEvents() {
|
||||
if (!this.g.user) return
|
||||
let timeout
|
||||
this.g.user.wallets.forEach(wallet => {
|
||||
if (!this.g.walletEventListeners.includes(wallet.id)) {
|
||||
|
|
|
|||
|
|
@ -33,23 +33,28 @@
|
|||
<body data-theme="bitcoin">
|
||||
<div id="vue">
|
||||
<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-theme></lnbits-theme>
|
||||
<lnbits-header></lnbits-header>
|
||||
{% block drawer %}
|
||||
<lnbits-drawer></lnbits-drawer>
|
||||
{% endblock %} {% block page_container %}
|
||||
<lnbits-drawer v-if="g.user && !g.isPublicPage"></lnbits-drawer>
|
||||
{% block page_container %}
|
||||
<q-page-container>
|
||||
<q-page class="q-px-md q-py-lg" :class="{'q-px-lg': $q.screen.gt.xs}">
|
||||
<lnbits-wallet-new></lnbits-wallet-new>
|
||||
<lnbits-header-wallets></lnbits-header-wallets>
|
||||
<lnbits-wallet-new
|
||||
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>
|
||||
<!-- FastAPI Content from extensions -->
|
||||
<div v-else>{% block page %}{% endblock %}</div>
|
||||
</q-page>
|
||||
</q-page-container>
|
||||
{% endblock %} {% block footer %}
|
||||
{% endblock %}
|
||||
<!-- Footer -->
|
||||
{% block footer %}
|
||||
<lnbits-footer />
|
||||
{% endblock %}
|
||||
</q-layout>
|
||||
|
|
@ -72,6 +77,9 @@
|
|||
{% if user %}
|
||||
<script>
|
||||
window.g.user = LNbits.map.user(JSON.parse({{ user | tojson | safe }}));
|
||||
{% if not public %}
|
||||
window.g.isPublicPage = false
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endif %}
|
||||
<!-- scripts from extensions -->
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
</q-banner>
|
||||
<q-toolbar>
|
||||
<q-btn
|
||||
v-if="!g.isPublicPage"
|
||||
dense
|
||||
flat
|
||||
round
|
||||
|
|
|
|||
|
|
@ -1,14 +1 @@
|
|||
{% extends "base.html" %} {% block beta %}{% endblock %} {% block drawer_toggle
|
||||
%}{% 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 %}
|
||||
{% extends "base.html" %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue