Fix: don't show register if new users not allowed (#3010)

* enforce allow new user flag on UI
* chore: bundle
* ensure we get a boolean

---------

Co-authored-by: dni  <office@dnilabs.com>
This commit is contained in:
Tiago Vasconcelos 2025-03-03 11:53:58 +00:00 committed by GitHub
parent c5964436b5
commit fe9b62e8a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 9 deletions

View file

@ -59,6 +59,9 @@
} }
} }
</style> </style>
<script>
const ALLOWED_REGISTER = {{ LNBITS_NEW_ACCOUNTS_ALLOWED | tojson }};
</script>
<script src="{{ static_url_for('static', 'js/index.js') }}"></script> <script src="{{ static_url_for('static', 'js/index.js') }}"></script>
{% endblock %} {% block page_container %} {% endblock %} {% block page_container %}
<q-page-container> <q-page-container>
@ -145,7 +148,7 @@
{%else%} {%else%}
<username-password <username-password
v-if="authMethod != 'user-id-only'" v-if="authMethod != 'user-id-only'"
:allowed_new_users="{{ LNBITS_NEW_ACCOUNTS_ALLOWED | tojson }}" :allowed_new_users="allowedRegister"
:auth-methods="{{ LNBITS_AUTH_METHODS }}" :auth-methods="{{ LNBITS_AUTH_METHODS }}"
:auth-action="authAction" :auth-action="authAction"
v-model:user-name="username" v-model:user-name="username"
@ -160,7 +163,10 @@
class="text-center text-grey-6" class="text-center text-grey-6"
v-if="authAction !== 'reset'" v-if="authAction !== 'reset'"
> >
<p v-if="authAction === 'login'" class="q-mb-none"> <p
v-if="authAction === 'login' && allowedRegister"
class="q-mb-none"
>
Not registered? Create an Not registered? Create an
<span <span
class="text-secondary cursor-pointer" class="text-secondary cursor-pointer"
@ -168,7 +174,14 @@
>Account</span >Account</span
> >
</p> </p>
<p v-else class="q-mb-none"> <p
v-else-if="authAction === 'login' && !allowedRegister"
class="q-mb-none"
>
<span v-text="$t('new_user_not_allowed')"></span>
</p>
<p v-else-if="authAction === 'register'" class="q-mb-none">
Aready have an account? Aready have an account?
<span <span
class="text-secondary cursor-pointer" class="text-secondary cursor-pointer"
@ -180,7 +193,7 @@
</username-password> </username-password>
{% if "user-id-only" in LNBITS_AUTH_METHODS %} {% if "user-id-only" in LNBITS_AUTH_METHODS %}
<user-id-only <user-id-only
:allowed_new_users="{{ LNBITS_NEW_ACCOUNTS_ALLOWED | tojson }}" :allowed_new_users="allowedRegister"
v-model:usr="usr" v-model:usr="usr"
v-model:wallet="walletName" v-model:wallet="walletName"
:auth-action="authAction" :auth-action="authAction"

File diff suppressed because one or more lines are too long

View file

@ -514,6 +514,7 @@ window.localisation.en = {
allowed_users_label: 'User ID', allowed_users_label: 'User ID',
allow_creation_user: 'Allow creation of new users', allow_creation_user: 'Allow creation of new users',
allow_creation_user_desc: 'Allow creation of new users on the index page', allow_creation_user_desc: 'Allow creation of new users on the index page',
new_user_not_allowed: 'Registration is disabled.',
components: 'Components', components: 'Components',
long_running_endpoints: 'Top 5 Long Running Endpoints', long_running_endpoints: 'Top 5 Long Running Endpoints',
http_request_methods: 'HTTP Request Methods', http_request_methods: 'HTTP Request Methods',

View file

@ -9,9 +9,7 @@ window.app = Vue.createApp({
description: '' description: ''
}, },
isUserAuthorized: false, isUserAuthorized: false,
authAction: Quasar.LocalStorage.getItem('lnbits.disclaimerShown') authAction: 'login',
? 'login'
: 'register',
authMethod: 'username-password', authMethod: 'username-password',
usr: '', usr: '',
username: '', username: '',
@ -104,6 +102,12 @@ window.app = Vue.createApp({
}, },
created() { created() {
this.description = SITE_DESCRIPTION this.description = SITE_DESCRIPTION
this.allowedRegister = ALLOWED_REGISTER
this.authAction =
!this.allowedRegister ||
Quasar.LocalStorage.getItem('lnbits.disclaimerShown')
? 'login'
: 'register'
this.isUserAuthorized = !!this.$q.cookies.get('is_lnbits_user_authorized') this.isUserAuthorized = !!this.$q.cookies.get('is_lnbits_user_authorized')
const _acccess_cookies_for_safari_refresh_do_not_delete = document.cookie const _acccess_cookies_for_safari_refresh_do_not_delete = document.cookie
if (this.isUserAuthorized) { if (this.isUserAuthorized) {

View file

@ -1259,7 +1259,7 @@
</q-form> </q-form>
</q-card-section> </q-card-section>
<!-- REGISTER --> <!-- REGISTER -->
<q-card-section v-if="authAction === 'register'"> <q-card-section v-if="allowed_new_users && authAction === 'register'">
<q-form @submit="register" class="q-gutter-sm"> <q-form @submit="register" class="q-gutter-sm">
<q-input <q-input
dense dense
@ -1302,6 +1302,9 @@
</div> </div>
</q-form> </q-form>
</q-card-section> </q-card-section>
<q-card-section v-else-if="!allowed_new_users && authAction === 'register'">
<h5 class="text-center" v-text="$t('new_user_not_allowed')"></h5>
</q-card-section>
<slot></slot> <slot></slot>
<!-- RESET --> <!-- RESET -->
<q-card-section v-if="authAction === 'reset'"> <q-card-section v-if="authAction === 'reset'">