Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions adminforth/commands/createApp/templates/index.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export const admin = new AdminForth({
rememberMeDays: 30,
loginBackgroundImage: 'https://images.unsplash.com/photo-1534239697798-120952b76f2b?q=80&w=3389&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
loginBackgroundPosition: '1/2',
loginPromptHTML: async () => {
const adminforthUserExists = await admin.resource("users").count(Filters.EQ('email', 'adminforth')) > 0;
if (adminforthUserExists) {
return "Please use <b>adminforth</b> as username and <b>adminforth</b> as password"
}
return "";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaroslav8765 can we remove this return? I think function shoudl understand undefined as well!

},
},
customization: {
brandName: "{{appName}}",
Expand Down
19 changes: 17 additions & 2 deletions adminforth/modules/restApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,21 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
const resource = this.adminforth.config.resources.find((res) => res.resourceId === this.adminforth.config.auth.usersResourceId);
const usernameColumn = resource.columns.find((col) => col.name === usernameField);

let loginPromptHTML;
if(typeof this.adminforth.config.auth.loginPromptHTML === 'function') {
loginPromptHTML = await this.adminforth.config.auth.loginPromptHTML();
} else {
loginPromptHTML = this.adminforth.config.auth.loginPromptHTML;
}

return {
brandName: this.adminforth.config.customization.brandName,
usernameFieldName: usernameColumn.label,
loginBackgroundImage: this.adminforth.config.auth.loginBackgroundImage,
loginBackgroundPosition: this.adminforth.config.auth.loginBackgroundPosition,
title: this.adminforth.config.customization?.title,
demoCredentials: this.adminforth.config.auth.demoCredentials,
loginPromptHTML: await tr(this.adminforth.config.auth.loginPromptHTML, 'system.loginPromptHTML'),
loginPromptHTML: await tr(loginPromptHTML, 'system.loginPromptHTML'),
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
globalInjections: {
everyPageBottom: this.adminforth.config.customization.globalInjections.everyPageBottom,
Expand Down Expand Up @@ -290,6 +297,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
}

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

let loginPromptHTML;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't repeat yourself

if(typeof this.adminforth.config.auth.loginPromptHTML === 'function') {
loginPromptHTML = await this.adminforth.config.auth.loginPromptHTML();
} else {
loginPromptHTML = this.adminforth.config.auth.loginPromptHTML;
}


const publicPart = {
brandName: this.adminforth.config.customization.brandName,
Expand All @@ -298,7 +313,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
loginBackgroundPosition: this.adminforth.config.auth.loginBackgroundPosition,
title: this.adminforth.config.customization?.title,
demoCredentials: this.adminforth.config.auth.demoCredentials,
loginPromptHTML: await tr(this.adminforth.config.auth.loginPromptHTML, 'system.loginPromptHTML'),
loginPromptHTML: await tr(loginPromptHTML, 'system.loginPromptHTML'),
loginPageInjections: this.adminforth.config.customization.loginPageInjections,
rememberMeDays: this.adminforth.config.auth.rememberMeDays,
}
Expand Down
2 changes: 1 addition & 1 deletion adminforth/types/Back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ export interface AdminForthInputConfig {
/**
* Any prompt to show users on login. Supports HTML.
*/
loginPromptHTML?: string,
loginPromptHTML?: string | (() => string | Promise<string>)

/**
* Remember me days for "Remember Me" checkbox on login page.
Expand Down
2 changes: 1 addition & 1 deletion adminforth/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ export interface AdminForthConfigForFrontend {
loginBackgroundPosition: string,
title?: string,
demoCredentials?: string,
loginPromptHTML?: string,
loginPromptHTML?: string | (() => string | Promise<string>)
loginPageInjections: {
underInputs: Array<AdminForthComponentDeclaration>,
panelHeader: Array<AdminForthComponentDeclaration>,
Expand Down