AI Implementation feature(821): First-Start Create Admin Modal (#2)
This commit was merged in pull request #2.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserEntity } from '../../database/entities/user.entity';
|
||||
@@ -6,6 +7,12 @@ import { SettingEntity } from '../../database/entities/setting.entity';
|
||||
import { ThemeLoaderService } from '../../common/utils/theme-loader.service';
|
||||
import { SETTINGS_KEYS } from '../../config/env.schema';
|
||||
|
||||
export interface PasswordPolicyInfo {
|
||||
minLength: number;
|
||||
requireMixed: boolean;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface BootstrapPayload {
|
||||
initialized: boolean;
|
||||
pageTitle: string;
|
||||
@@ -14,6 +21,7 @@ export interface BootstrapPayload {
|
||||
theme: any;
|
||||
defaultChallengeIp: string;
|
||||
registrationsEnabled: boolean;
|
||||
passwordPolicy: PasswordPolicyInfo;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -22,6 +30,7 @@ export class SystemService {
|
||||
@InjectRepository(UserEntity) private readonly users: Repository<UserEntity>,
|
||||
@InjectRepository(SettingEntity) private readonly settings: Repository<SettingEntity>,
|
||||
private readonly themes: ThemeLoaderService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
|
||||
async bootstrap(): Promise<BootstrapPayload> {
|
||||
@@ -35,9 +44,19 @@ export class SystemService {
|
||||
theme: this.themes.getTheme(themeKey),
|
||||
defaultChallengeIp: await this.getSetting(SETTINGS_KEYS.DEFAULT_CHALLENGE_IP, '127.0.0.1'),
|
||||
registrationsEnabled: (await this.getSetting(SETTINGS_KEYS.REGISTRATIONS_ENABLED, 'false')) === 'true',
|
||||
passwordPolicy: this.passwordPolicy(),
|
||||
};
|
||||
}
|
||||
|
||||
private passwordPolicy(): PasswordPolicyInfo {
|
||||
const minLength = this.config.get<number>('PASSWORD_MIN_LENGTH', 12);
|
||||
const requireMixed = this.config.get<boolean>('PASSWORD_REQUIRE_MIXED', true);
|
||||
const description = requireMixed
|
||||
? `At least ${minLength} characters with upper, lower, digit and symbol`
|
||||
: `At least ${minLength} characters`;
|
||||
return { minLength, requireMixed, description };
|
||||
}
|
||||
|
||||
private async getSetting(key: string, fallback: string): Promise<string> {
|
||||
const row = await this.settings.findOne({ where: { key } });
|
||||
return row?.value ?? fallback;
|
||||
|
||||
Reference in New Issue
Block a user