diff --git a/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts b/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts index e34f810e..57c82afb 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts @@ -32,6 +32,7 @@ export class ChatController { new_room.users = room.users; if (room.allowed) new_room.allowed = room.allowed; + return new_room; } @@ -84,6 +85,40 @@ export class ChatController { printCaller("- out "); } + @UseGuards(AuthenticateGuard) + @UseGuards(TwoFactorGuard) + @Get('isadmin') + async isAdmin(@Req() req, @Res() res): Promise + { + printCaller("- in "); + + const room_name = await this.chatService.getCurrentRoomName(req.user.username); + const fields = ["admins"]; + const room_db = await this.chatService.getRoomByName(room_name, fields); + const is_admin = room_db.admins.includes(req.user.username); + + res.status(HttpStatus.OK).json({ is_admin: is_admin }); + printCaller("- out "); + } + +/* + @UseGuards(AuthenticateGuard) + @UseGuards(TwoFactorGuard) + @Get('isadmin') + async isAdmin(@Req() req, @Res() res): Promise + { + printCaller("- in "); + + const room_name = await this.chatService.getCurrentRoomName(req.user.username); + const fields = ["admins"]; + const room_db = await this.chatService.getRoomByName(room_name, fields); + const is_admin = room_db.admins.includes(req.user.username); + + res.status(HttpStatus.OK).json({ is_admin: is_admin }); + printCaller("- out "); + } +*/ + @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) @Get('current') diff --git a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts index 79549595..de5792f5 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts @@ -432,6 +432,8 @@ export class ChatService { printCaller("-- in "); let room_name = await this.getCurrentRoomName(socket.username); + + /* const current_room = await this.getRoomByName(room_name); if (current_room.protection) @@ -442,6 +444,7 @@ export class ChatService { return; } } + */ socket.to(socket.room).emit('message', socket.username, message); await this.addMessageToRoom(room_name, socket.username, message); diff --git a/srcs/requirements/svelte/api_front/src/pieces/chat/Layout_room_set.svelte b/srcs/requirements/svelte/api_front/src/pieces/chat/Layout_room_set.svelte index 07f1c1ae..2f130f53 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/chat/Layout_room_set.svelte +++ b/srcs/requirements/svelte/api_front/src/pieces/chat/Layout_room_set.svelte @@ -1,18 +1,22 @@ -