Skip to content

Commit 351261f

Browse files
committed
chore: add new endpoind - /get_login_form_config
1 parent b4cdfec commit 351261f

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

adminforth/modules/restApi.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
194194
},
195195
})
196196

197+
server.endpoint({
198+
noAuth: true,
199+
method: 'GET',
200+
path: '/get_login_form_config',
201+
handler: async ({ tr }) => {
202+
const loginPromptHTML = await getLoginPromptHTML(this.adminforth.config.auth.loginPromptHTML);
203+
return {
204+
loginPromptHTML: await tr(loginPromptHTML, 'system.loginPromptHTML'),
205+
}
206+
}
207+
})
208+
197209
server.endpoint({
198210
noAuth: true,
199211
method: 'GET',
@@ -210,16 +222,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
210222
const resource = this.adminforth.config.resources.find((res) => res.resourceId === this.adminforth.config.auth.usersResourceId);
211223
const usernameColumn = resource.columns.find((col) => col.name === usernameField);
212224

213-
const loginPromptHTML = await getLoginPromptHTML(this.adminforth.config.auth.loginPromptHTML);
214-
215225
return {
216226
brandName: this.adminforth.config.customization.brandName,
217227
usernameFieldName: usernameColumn.label,
218228
loginBackgroundImage: this.adminforth.config.auth.loginBackgroundImage,
219229
loginBackgroundPosition: this.adminforth.config.auth.loginBackgroundPosition,
220230
title: this.adminforth.config.customization?.title,
221231
demoCredentials: this.adminforth.config.auth.demoCredentials,
222-
loginPromptHTML: await tr(loginPromptHTML, 'system.loginPromptHTML'),
223232
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
224233
globalInjections: {
225234
everyPageBottom: this.adminforth.config.customization.globalInjections.everyPageBottom,
@@ -292,7 +301,6 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
292301

293302
const announcementBadge: AnnouncementBadgeResponse = this.adminforth.config.customization.announcementBadge?.(adminUser);
294303

295-
const loginPromptHTML = await getLoginPromptHTML(this.adminforth.config.auth.loginPromptHTML);
296304

297305

298306
const publicPart = {
@@ -302,7 +310,6 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
302310
loginBackgroundPosition: this.adminforth.config.auth.loginBackgroundPosition,
303311
title: this.adminforth.config.customization?.title,
304312
demoCredentials: this.adminforth.config.auth.demoCredentials,
305-
loginPromptHTML: await tr(loginPromptHTML, 'system.loginPromptHTML'),
306313
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
307314
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
308315
}

adminforth/spa/src/views/LoginView.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@
104104
</div>
105105
</div>
106106

107-
<div v-if="coreStore.config?.loginPromptHTML"
107+
<div v-if="loginPromptHTML"
108108
class="flex items-center p-4 mb-4 text-sm text-gray-800 rounded-lg bg-gray-50 dark:bg-gray-800 dark:text-gray-400" role="alert"
109109
>
110110
<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">
111111
<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"/>
112112
</svg>
113113
<span class="sr-only">{{ $t('Info') }}</span>
114-
<div v-html="coreStore.config?.loginPromptHTML"></div>
114+
<div v-html="loginPromptHTML"></div>
115115
</div>
116116
<Button @click="login" :loader="inProgress" :disabled="inProgress" class="w-full">
117117
{{ $t('Login to your account') }}
@@ -150,7 +150,7 @@ const password = ref('');
150150
const route = useRoute();
151151
const router = useRouter();
152152
const inProgress = ref(false);
153-
153+
const loginPromptHTML = ref()
154154
const coreStore = useCoreStore();
155155
const user = useUserStore();
156156
@@ -162,6 +162,14 @@ const backgroundPosition = computed(() => {
162162
return coreStore.config?.loginBackgroundPosition || '1/2';
163163
});
164164
165+
async function getLoginFormConfig() {
166+
const response = await callAdminForthApi({
167+
path: '/get_login_form_config',
168+
method: 'GET',
169+
});
170+
loginPromptHTML.value = response.loginPromptHTML || '';
171+
}
172+
165173
onBeforeMount(() => {
166174
if (localStorage.getItem('isAuthorized') === 'true') {
167175
// if route has next param, redirect
@@ -175,6 +183,7 @@ onBeforeMount(() => {
175183
})
176184
177185
onMounted(async () => {
186+
getLoginFormConfig();
178187
if (coreStore.config?.demoCredentials) {
179188
const [demoUsername, demoPassword] = coreStore.config.demoCredentials.split(':');
180189
username.value = demoUsername;

0 commit comments

Comments
 (0)