From a80dc769ce77b9476c741371e9a359edf7edd035 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 28 Jun 2022 20:26:04 +0800 Subject: [PATCH] server: fix js error --- packages/server/src/services/user.service.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/server/src/services/user.service.ts b/packages/server/src/services/user.service.ts index d5c459f..e877d34 100644 --- a/packages/server/src/services/user.service.ts +++ b/packages/server/src/services/user.service.ts @@ -115,6 +115,12 @@ export class UserService { * @returns */ async createUser(user: RegisterUserDto): Promise { + const currentSystemConfig = await this.systemService.getConfigFromDatabase(); + + if (currentSystemConfig.isSystemLocked) { + throw new HttpException('系统维护中,暂不可注册', HttpStatus.FORBIDDEN); + } + if (await this.userRepo.findOne({ name: user.name })) { throw new HttpException('该账户已被注册', HttpStatus.BAD_REQUEST); } @@ -157,6 +163,12 @@ export class UserService { * @param registerUser */ public async resetPassword(resetPasswordDto: ResetPasswordDto) { + const currentSystemConfig = await this.systemService.getConfigFromDatabase(); + + if (currentSystemConfig.isSystemLocked) { + throw new HttpException('系统维护中,暂不可使用', HttpStatus.FORBIDDEN); + } + const { email, password, confirmPassword, verifyCode } = resetPasswordDto; const inDatabaseUser = await this.userRepo.findOne({ email }); @@ -195,7 +207,9 @@ export class UserService { existUser = await this.userRepo.findOne({ where: { email: name } }); } - if (!existUser.isSystemAdmin && currentSystemConfig.isSystemLocked) { + const isExistUserSystemAdmin = existUser ? existUser.isSystemAdmin : false; + + if (currentSystemConfig.isSystemLocked && !isExistUserSystemAdmin) { throw new HttpException('系统维护中,暂不可登录', HttpStatus.FORBIDDEN); }