feat(admin,player,api): 玩家账号密码管理与代理上下分
新增玩家头像、可查密码与全局改密/改账号开关;玩家资料页合并账号密码展示;代理直属玩家列表支持自定义上下分。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
9
apps/api/src/shared/config/system-config.module.ts
Normal file
9
apps/api/src/shared/config/system-config.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { SystemConfigService } from './system-config.service';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [SystemConfigService],
|
||||
exports: [SystemConfigService],
|
||||
})
|
||||
export class SystemConfigModule {}
|
||||
59
apps/api/src/shared/config/system-config.service.ts
Normal file
59
apps/api/src/shared/config/system-config.service.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
export const PLAYER_ALLOW_PASSWORD_CHANGE = 'player.allow_password_change';
|
||||
export const PLAYER_ALLOW_USERNAME_CHANGE = 'player.allow_username_change';
|
||||
|
||||
export type PlayerAccountSettings = {
|
||||
allowPasswordChange: boolean;
|
||||
allowUsernameChange: boolean;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class SystemConfigService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async getBoolean(key: string, defaultValue: boolean): Promise<boolean> {
|
||||
const row = await this.prisma.systemConfig.findUnique({ where: { configKey: key } });
|
||||
if (!row) return defaultValue;
|
||||
return row.configValue === 'true' || row.configValue === '1';
|
||||
}
|
||||
|
||||
async setBoolean(key: string, value: boolean, description?: string) {
|
||||
await this.prisma.systemConfig.upsert({
|
||||
where: { configKey: key },
|
||||
create: {
|
||||
configKey: key,
|
||||
configValue: value ? 'true' : 'false',
|
||||
description,
|
||||
},
|
||||
update: { configValue: value ? 'true' : 'false' },
|
||||
});
|
||||
}
|
||||
|
||||
async getPlayerAccountSettings(): Promise<PlayerAccountSettings> {
|
||||
const [allowPasswordChange, allowUsernameChange] = await Promise.all([
|
||||
this.getBoolean(PLAYER_ALLOW_PASSWORD_CHANGE, true),
|
||||
this.getBoolean(PLAYER_ALLOW_USERNAME_CHANGE, false),
|
||||
]);
|
||||
return { allowPasswordChange, allowUsernameChange };
|
||||
}
|
||||
|
||||
async updatePlayerAccountSettings(data: Partial<PlayerAccountSettings>) {
|
||||
if (data.allowPasswordChange !== undefined) {
|
||||
await this.setBoolean(
|
||||
PLAYER_ALLOW_PASSWORD_CHANGE,
|
||||
data.allowPasswordChange,
|
||||
'玩家是否可在客户端修改密码',
|
||||
);
|
||||
}
|
||||
if (data.allowUsernameChange !== undefined) {
|
||||
await this.setBoolean(
|
||||
PLAYER_ALLOW_USERNAME_CHANGE,
|
||||
data.allowUsernameChange,
|
||||
'玩家是否可在客户端修改登录账号名',
|
||||
);
|
||||
}
|
||||
return this.getPlayerAccountSettings();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user