Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions adminforth/spa/src/stores/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ export const useCoreStore = defineStore('core', () => {
config.value = {...config.value, ...res};
}

async function getLoginFormConfig() {
const res = await callAdminForthApi({
path: '/get_login_form_config',
method: 'GET',
});
config.value = {...config.value, ...res};
}

const username = computed(() => {
const usernameField = config.value?.usernameField;
Expand All @@ -218,6 +225,7 @@ export const useCoreStore = defineStore('core', () => {
userFullname,
getPublicConfig,
fetchMenuAndResource,
getLoginFormConfig,
fetchRecord,
record,
fetchResourceFull,
Expand Down
15 changes: 3 additions & 12 deletions adminforth/spa/src/views/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
@update:disableLoginButton="setDisableLoginButton($event)"
/>

<div v-if="loginPromptHTML"
<div v-if="coreStore.config?.loginPromptHTML"
class="flex items-center p-4 mb-4 text-sm text-lightLoginViewPromptText rounded-lg bg-lightLoginViewPromptBackground dark:bg-darkLoginViewPromptBackground dark:text-darkLoginViewPromptText" role="alert"
>
<svg class="flex-shrink-0 inline w-4 h-4 me-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
</svg>
<span class="sr-only">{{ $t('Info') }}</span>
<div v-html="loginPromptHTML"></div>
<div v-html="coreStore.config?.loginPromptHTML"></div>
</div>
<Button @click="login" :loader="inProgress" :disabled="inProgress || disableLoginButton" class="w-full">
{{ $t('Login to your account') }}
Expand Down Expand Up @@ -146,7 +146,6 @@ const password = ref('');
const route = useRoute();
const router = useRouter();
const inProgress = ref(false);
const loginPromptHTML = ref()
const coreStore = useCoreStore();
const user = useUserStore();

Expand All @@ -160,14 +159,6 @@ const backgroundPosition = computed(() => {
});


async function getLoginFormConfig() {
const response = await callAdminForthApi({
path: '/get_login_form_config',
method: 'GET',
});
loginPromptHTML.value = response.loginPromptHTML;
}

onBeforeMount(() => {
if (localStorage.getItem('isAuthorized') === 'true') {
// if route has next param, redirect
Expand All @@ -181,7 +172,7 @@ onBeforeMount(() => {
})

onMounted(async () => {
getLoginFormConfig();
coreStore.getLoginFormConfig();
if (coreStore.config?.demoCredentials) {
const [demoUsername, demoPassword] = coreStore.config.demoCredentials.split(':');
username.value = demoUsername;
Expand Down