diff --git a/backend/services/identity-service/src/application/commands/auto-create-account/auto-create-account.handler.ts b/backend/services/identity-service/src/application/commands/auto-create-account/auto-create-account.handler.ts index c3e1c754..8cde0615 100644 --- a/backend/services/identity-service/src/application/commands/auto-create-account/auto-create-account.handler.ts +++ b/backend/services/identity-service/src/application/commands/auto-create-account/auto-create-account.handler.ts @@ -8,7 +8,7 @@ import { TokenService } from '@/application/services/token.service'; import { EventPublisherService } from '@/infrastructure/kafka/event-publisher.service'; import { ApplicationError } from '@/shared/exceptions/domain.exception'; import { AutoCreateAccountResult } from '../index'; -import { generateRandomIdentity } from '@/shared/utils'; +import { generateIdentity } from '@/shared/utils'; @Injectable() export class AutoCreateAccountHandler { @@ -43,8 +43,8 @@ export class AutoCreateAccountHandler { // 3. 生成用户序列号 const accountSequence = await this.sequenceGenerator.generateNextUserSequence(); - // 4. 生成随机用户名和头像 - const identity = generateRandomIdentity(); + // 4. 生成用户名和头像 + const identity = generateIdentity(accountSequence.value); // 5. 构建设备名称,保存完整的设备信息 JSON let deviceNameStr = '未命名设备'; diff --git a/backend/services/identity-service/src/application/services/user-application.service.ts b/backend/services/identity-service/src/application/services/user-application.service.ts index 9d3f7410..b605f5f0 100644 --- a/backend/services/identity-service/src/application/services/user-application.service.ts +++ b/backend/services/identity-service/src/application/services/user-application.service.ts @@ -20,7 +20,7 @@ import { MpcWalletService } from '@/infrastructure/external/mpc'; import { BlockchainWalletHandler } from '../event-handlers/blockchain-wallet.handler'; import { MpcKeygenCompletedHandler } from '../event-handlers/mpc-keygen-completed.handler'; import { ApplicationError } from '@/shared/exceptions/domain.exception'; -import { generateRandomIdentity } from '@/shared/utils'; +import { generateIdentity } from '@/shared/utils'; import { MpcKeygenRequestedEvent } from '@/domain/events'; import { AutoCreateAccountCommand, RecoverByMnemonicCommand, RecoverByPhoneCommand, @@ -88,8 +88,8 @@ export class UserApplicationService { // 3. 生成用户序列号 const accountSequence = await this.sequenceGenerator.generateNextUserSequence(); - // 4. 生成随机用户名和头像 - const identity = generateRandomIdentity(); + // 4. 生成用户名和头像 + const identity = generateIdentity(accountSequence.value); // 5. 构建设备名称字符串 let deviceNameStr = '未命名设备'; diff --git a/backend/services/identity-service/src/shared/utils/random-identity.util.ts b/backend/services/identity-service/src/shared/utils/random-identity.util.ts index 2178e878..d26a58a3 100644 --- a/backend/services/identity-service/src/shared/utils/random-identity.util.ts +++ b/backend/services/identity-service/src/shared/utils/random-identity.util.ts @@ -1,27 +1,10 @@ /** - * 随机用户名和头像生成器 + * 用户名和头像生成器 */ -// 形容词词库 (水果/美食主题) -const ADJECTIVES = [ - '快乐', '阳光', '活泼', '可爱', '勇敢', '聪明', '温暖', '甜蜜', - '闪亮', '酷炫', '神秘', '优雅', '热情', '淘气', '呆萌', '霸气', - '清新', '软糯', '香甜', '金色', '紫色', '粉色', '蓝色', '绿色', -]; - -// 名词词库 (水果主题 - 榴莲相关) -const NOUNS = [ - '榴莲', '芒果', '椰子', '菠萝', '龙眼', '荔枝', '山竹', '木瓜', - '百香果', '火龙果', '杨桃', '莲雾', '番石榴', '释迦', '红毛丹', - '勇士', '战士', '骑士', '猎手', '侠客', '英雄', '达人', '玩家', -]; - -// 生成随机用户名: 形容词 + 名词 + 随机数字 -export function generateRandomUsername(): string { - const adjective = ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)]; - const noun = NOUNS[Math.floor(Math.random() * NOUNS.length)]; - const number = Math.floor(Math.random() * 90000) + 10000; // 5位数字 - return `${adjective}${noun}_${number}`; +// 生成用户名: 榴莲女皇x号 +export function generateUsername(accountSequence: number): string { + return `榴莲女皇${accountSequence}号`; } // 预定义的柔和配色方案 @@ -148,11 +131,12 @@ export function generateRandomAvatarSvg(): string { } /** - * 生成完整的随机身份 + * 生成用户身份 + * @param accountSequence 用户序列号 */ -export function generateRandomIdentity(): { username: string; avatarSvg: string } { +export function generateIdentity(accountSequence: number): { username: string; avatarSvg: string } { return { - username: generateRandomUsername(), + username: generateUsername(accountSequence), avatarSvg: generateRandomAvatarSvg(), }; }