Bladeren bron

feat: comment out OAuth login methods in AuthController and AuthService for future refactoring

Dave 2 maanden geleden
bovenliggende
commit
52fee754cf

+ 25 - 25
apps/box-mgnt-api/src/mgnt-backend/core/auth/auth.controller.ts

@@ -52,32 +52,32 @@ export class AuthController {
     return this.authService.logout(user, req);
   }
 
-  @Public()
-  @UseGuards(RateLimitGuard, LocalAuthGuard)
-  @Post('oauth-login')
-  @ApiOperation({
-    summary: 'CS User login',
-    description: 'Allows CS user only to log in using their credentials.',
-  })
-  @ApiResponse({ status: 200, description: 'Login successful.' })
-  @ApiResponse({ status: 401, description: 'Unauthorized.' })
-  async oauthlogin(@AuthUser() user: User, @Req() req: FastifyRequest) {
-    return this.authService.oauth(user, req);
-  }
+  // @Public()
+  // @UseGuards(RateLimitGuard, LocalAuthGuard)
+  // @Post('oauth-login')
+  // @ApiOperation({
+  //   summary: 'CS User login',
+  //   description: 'Allows CS user only to log in using their credentials.',
+  // })
+  // @ApiResponse({ status: 200, description: 'Login successful.' })
+  // @ApiResponse({ status: 401, description: 'Unauthorized.' })
+  // async oauthlogin(@AuthUser() user: User, @Req() req: FastifyRequest) {
+  //   return this.authService.oauth(user, req);
+  // }
 
-  @Public()
-  @UseGuards(RateLimitGuard, LocalAuthGuard)
-  @Post('oauth-login-2fa')
-  @ApiOperation({
-    summary: 'CS User login with 2FA',
-    description:
-      'Allows CS user only to log in using their credentials and 2FA code.',
-  })
-  @ApiResponse({ status: 200, description: 'Login successful.' })
-  @ApiResponse({ status: 401, description: 'Unauthorized.' })
-  async oauthlogin2fa(@AuthUser() user: User, @Req() req: FastifyRequest) {
-    return this.authService.oauth2fa(user, req);
-  }
+  // @Public()
+  // @UseGuards(RateLimitGuard, LocalAuthGuard)
+  // @Post('oauth-login-2fa')
+  // @ApiOperation({
+  //   summary: 'CS User login with 2FA',
+  //   description:
+  //     'Allows CS user only to log in using their credentials and 2FA code.',
+  // })
+  // @ApiResponse({ status: 200, description: 'Login successful.' })
+  // @ApiResponse({ status: 401, description: 'Unauthorized.' })
+  // async oauthlogin2fa(@AuthUser() user: User, @Req() req: FastifyRequest) {
+  //   return this.authService.oauth2fa(user, req);
+  // }
 
   @Post('2fa/generate')
   @ApiOperation({

+ 93 - 93
apps/box-mgnt-api/src/mgnt-backend/core/auth/auth.service.ts

@@ -292,52 +292,52 @@ export class AuthService {
     }
   }
 
-  async oauth(user: User, req: FastifyRequest) {
-    await this.loginLogService.createLog(
-      user.username,
-      req,
-      LoginType.LOGIN,
-      LoginStatus.SUCCESS,
-    );
-
-    const roleIds = await this.userService.getUserRoleIds(user.id, true);
-    // check if roleIds in 2, 3, 4
-    if (!roleIds.some((id: number) => [2, 3, 4].includes(id))) {
-      throw new UnauthorizedException('您没有权限访问此资源');
-    }
-
-    const roleInfo: any[] = [];
-    for (const roleId of roleIds) {
-      const role = await this.roleService.get(roleId);
-
-      roleInfo.push({
-        id: role.id,
-        name: role.name,
-      });
-    }
-
-    const payload: JwtPayload = {
-      username: user.username,
-      userId: user.id,
-      roleIds: roleIds,
-    };
-    const token = this.jwtService.sign(payload);
-
-    // 更新用户的 JWT Token
-    await this.userService.updateOAuthJwtToken(user.id, token);
-
-    const userData = await this.userService.get(user.id);
-
-    return {
-      kfId: user.id,
-      account: user.username,
-      token: this.jwtService.sign(payload),
-      avatar: user.photo || '',
-      nick: user.nick || '',
-      // quota: user.quota,
-      roleInfo: roleInfo,
-    };
-  }
+  // async oauth(user: User, req: FastifyRequest) {
+  //   await this.loginLogService.createLog(
+  //     user.username,
+  //     req,
+  //     LoginType.LOGIN,
+  //     LoginStatus.SUCCESS,
+  //   );
+
+  //   const roleIds = await this.userService.getUserRoleIds(user.id, true);
+  //   // check if roleIds in 2, 3, 4
+  //   if (!roleIds.some((id: number) => [2, 3, 4].includes(id))) {
+  //     throw new UnauthorizedException('您没有权限访问此资源');
+  //   }
+
+  //   const roleInfo: any[] = [];
+  //   for (const roleId of roleIds) {
+  //     const role = await this.roleService.get(roleId);
+
+  //     roleInfo.push({
+  //       id: role.id,
+  //       name: role.name,
+  //     });
+  //   }
+
+  //   const payload: JwtPayload = {
+  //     username: user.username,
+  //     userId: user.id,
+  //     roleIds: roleIds,
+  //   };
+  //   const token = this.jwtService.sign(payload);
+
+  //   // 更新用户的 JWT Token
+  //   await this.userService.updateOAuthJwtToken(user.id, token);
+
+  //   const userData = await this.userService.get(user.id);
+
+  //   return {
+  //     kfId: user.id,
+  //     account: user.username,
+  //     token: this.jwtService.sign(payload),
+  //     avatar: user.photo || '',
+  //     nick: user.nick || '',
+  //     // quota: user.quota,
+  //     roleInfo: roleInfo,
+  //   };
+  // }
 
   // auth.service.ts (excerpt)
   async login(user: User, req: FastifyRequest) {
@@ -398,53 +398,53 @@ export class AuthService {
     };
   }
 
-  async oauth2fa(user: User, req: FastifyRequest) {
-    // 1) login audit
-    await this.loginLogService.createLog(
-      user.username,
-      req,
-      LoginType.LOGIN,
-      LoginStatus.SUCCESS,
-    );
-
-    // 2) role gate: only allow roles 2/3/4
-    const roleIds = await this.userService.getUserRoleIds(user.id, true);
-    if (!roleIds.some((id: number) => [2, 3, 4].includes(id))) {
-      throw new UnauthorizedException('您没有权限访问此资源');
-    }
-
-    // 3) role info (unchanged)
-    const roleInfo: Array<{ id: number; name: string }> = [];
-    for (const roleId of roleIds) {
-      const role = await this.roleService.get(roleId);
-      roleInfo.push({ id: role.id, name: role.name });
-    }
-
-    // 4) build OAuth payload (NO mfa / NO stage)
-    const payload: JwtPayload = {
-      userId: user.id,
-      username: user.username,
-      roleIds,
-      // mfa: undefined,  // intentionally omitted
-      // stage: undefined // intentionally omitted
-    };
-
-    // 5) sign OAuth token (explicit expiry, e.g., 8h)
-    const token = await this.jwtService.signAsync(payload);
-
-    // 6) persist ONLY the OAuth token (do not touch user.jwtToken)
-    await this.userService.updateOAuthJwtToken(user.id, token);
-
-    // 7) response (same shape you used)
-    return {
-      kfId: user.id,
-      account: user.username,
-      token, // OAuth token
-      avatar: user.photo || '',
-      nick: user.nick || '',
-      roleInfo,
-    };
-  }
+  // async oauth2fa(user: User, req: FastifyRequest) {
+  //   // 1) login audit
+  //   await this.loginLogService.createLog(
+  //     user.username,
+  //     req,
+  //     LoginType.LOGIN,
+  //     LoginStatus.SUCCESS,
+  //   );
+
+  //   // 2) role gate: only allow roles 2/3/4
+  //   const roleIds = await this.userService.getUserRoleIds(user.id, true);
+  //   if (!roleIds.some((id: number) => [2, 3, 4].includes(id))) {
+  //     throw new UnauthorizedException('您没有权限访问此资源');
+  //   }
+
+  //   // 3) role info (unchanged)
+  //   const roleInfo: Array<{ id: number; name: string }> = [];
+  //   for (const roleId of roleIds) {
+  //     const role = await this.roleService.get(roleId);
+  //     roleInfo.push({ id: role.id, name: role.name });
+  //   }
+
+  //   // 4) build OAuth payload (NO mfa / NO stage)
+  //   const payload: JwtPayload = {
+  //     userId: user.id,
+  //     username: user.username,
+  //     roleIds,
+  //     // mfa: undefined,  // intentionally omitted
+  //     // stage: undefined // intentionally omitted
+  //   };
+
+  //   // 5) sign OAuth token (explicit expiry, e.g., 8h)
+  //   const token = await this.jwtService.signAsync(payload);
+
+  //   // 6) persist ONLY the OAuth token (do not touch user.jwtToken)
+  //   await this.userService.updateOAuthJwtToken(user.id, token);
+
+  //   // 7) response (same shape you used)
+  //   return {
+  //     kfId: user.id,
+  //     account: user.username,
+  //     token, // OAuth token
+  //     avatar: user.photo || '',
+  //     nick: user.nick || '',
+  //     roleInfo,
+  //   };
+  // }
 
   async login2fa(user: User, req: FastifyRequest) {
     // 1) login audit

+ 4 - 4
apps/box-mgnt-api/src/mgnt-backend/core/user/user.service.ts

@@ -285,10 +285,10 @@ export class UserService {
     return { list, total };
   }
 
-  async listAllJdCs() {
-    const jdCsRoleId = 3; // 假设 3 是 JD 客服的角色 ID
-    return this.findByRoleId(jdCsRoleId);
-  }
+  // async listAllJdCs() {
+  //   const jdCsRoleId = 3; // 假设 3 是 JD 客服的角色 ID
+  //   return this.findByRoleId(jdCsRoleId);
+  // }
 
   // get all user by roleId
   async findByRoleId(roleId: number) {