diff --git a/back/volume/src/chat/chat.controller.ts b/back/volume/src/chat/chat.controller.ts index fc7f0bf..2dff850 100644 --- a/back/volume/src/chat/chat.controller.ts +++ b/back/volume/src/chat/chat.controller.ts @@ -81,6 +81,7 @@ export class ChatController { if (await this.channelService.isBanned(channel.id, target.id)) { throw new BadRequestException('User is banned from this channel') } + user.socketKey = '' channel.users.push(user) await this.channelService.save(channel) } diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index bea4803..5daa9e8 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -65,6 +65,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { throw new WsException('You are banned from this channel'); } const user = await this.userService.getFullUser(connect.UserId); + user.socketKey = ''; if (channel.password && channel.password !== '') { if ( !connect.pwd || diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index 627fefa..3f4f62a 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -38,8 +38,9 @@ export class UsersController { @Get('blocked') @UseGuards(AuthenticatedGuard) async getBlockedUsers (@Profile42() profile: Profile): Promise { - const user = await this.usersService.getFullUser(profile.id) + const user = await this.usersService.getFullUser(+profile.id) if (user === null) throw new BadRequestException('User not found') + user.socketKey = '' return user.blocked } @@ -47,14 +48,16 @@ export class UsersController { @UseGuards(AuthenticatedGuard) async blockUser ( @Profile42() profile: Profile, - @Param('id') id: number + @Param('id', ParseIntPipe) id: number ): Promise { - const user = await this.usersService.getFullUser(profile.id) + const user = await this.usersService.getFullUser(+profile.id) const target = await this.usersService.findUser(id) if (user === null || target === null) { throw new BadRequestException('User not found') } user.blocked.push(target) + console.log('user', JSON.stringify(user)) + console.log('user', JSON.stringify(target)) await this.usersService.save(user) } @@ -62,9 +65,9 @@ export class UsersController { @UseGuards(AuthenticatedGuard) async unblockUser ( @Profile42() profile: Profile, - @Param('id') id: number + @Param('id', ParseIntPipe) id: number ): Promise { - const user = await this.usersService.getFullUser(profile.id) + const user = await this.usersService.getFullUser(+profile.id) if (user === null) throw new BadRequestException('User not found') user.blocked = user.blocked.filter((usr: User) => { return usr.id !== id @@ -85,13 +88,13 @@ export class UsersController { @Get('friends') @UseGuards(AuthenticatedGuard) async getFriends (@Profile42() profile: Profile): Promise { - return await this.usersService.getFriends(profile.id) + return await this.usersService.getFriends(+profile.id) } @Get('invits') @UseGuards(AuthenticatedGuard) async getInvits (@Profile42() profile: Profile): Promise { - return await this.usersService.getInvits(profile.id) + return await this.usersService.getInvits(+profile.id) } @Get('leaderboard') @@ -127,7 +130,7 @@ export class UsersController { @UploadedFile() file: Express.Multer.File ): Promise { if (file === undefined) return - await this.usersService.addAvatar(profile.id, file.filename) + await this.usersService.addAvatar(+profile.id, file.filename) } @Get('avatar') @@ -136,7 +139,7 @@ export class UsersController { @Profile42() profile: Profile, @Res({ passthrough: true }) response: Response ): Promise { - return await this.getAvatarById(profile.id, response) + return await this.getAvatarById(+profile.id, response) } @Get(':name/byname') @@ -161,7 +164,7 @@ export class UsersController { if (+profile.id === +target.ftId) { throw new BadRequestException("You can't invite yourself.") } - const ret: string = await this.usersService.invit(profile.id, target.ftId) + const ret: string = await this.usersService.invit(+profile.id, target.ftId) if (ret !== 'OK') throw new BadRequestException(ret) } @@ -191,16 +194,6 @@ export class UsersController { return user } - @Post(':id') - async createById (@Body() payload: UserDto): Promise { - const user = await this.usersService.findUser(payload.ftId) - if (user != null) { - await this.usersService.update(user, payload) - } else { - await this.usersService.create(payload) - } - } - @Get() @UseGuards(AuthenticatedGuard) async getUser (@Profile42() profile: Profile): Promise { diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index ee46ee0..88f09cc 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -70,7 +70,6 @@ export class UsersService { relations: ['results', 'blocked', 'friends'] }) if (user === null) throw new BadRequestException('User not found.') - user.socketKey = '' return user } diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index ec7a916..b2af0d3 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -30,7 +30,6 @@ import { API_URL } from "./Auth"; import { store, getUser, login, verify } from "./Auth"; - import FakeLogin from "./FakeLogin.svelte"; // Single Page Application config let appState: string = APPSTATE.HOME; @@ -151,21 +150,6 @@ let pong: Pong; let gamePlaying: boolean = false; let resetGameConnection: () => void; - - // FAKE LOGIN - let usernameFake = "test"; - let ftIdFake = "42"; - let fakemenu = true; - let fakeUser = false; - function impersonate() { - const user = { - username: usernameFake, - socketKey: ftIdFake, - }; - store.set(user); - fakeUser = true; - fakemenu = false; - }
@@ -262,14 +246,7 @@ />
{/if} - - {#if fakemenu} - - - - {:else} - - {/if} + {/if} diff --git a/front/volume/src/FakeLogin.svelte b/front/volume/src/FakeLogin.svelte deleted file mode 100644 index 2f76ef5..0000000 --- a/front/volume/src/FakeLogin.svelte +++ /dev/null @@ -1,29 +0,0 @@ - - -
- - - -
diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 10e4698..17ed16f 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -161,14 +161,10 @@ }); if (response.ok) { const target = await response.json(); - response = await fetch(API_URL + "/users/" + target.ftId + "/block", { + response = await fetch(API_URL + "/users/block/" + target.ftId, { + method: "GET", credentials: "include", - method: "POST", - mode: "cors", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ id: target.ftId }), + mode: "cors" }); } if (response.ok) await show_popup("User blocked", false); @@ -312,9 +308,9 @@ }); } if (response.ok) { - await show_popup("User admined", false); + await show_popup("User promoted", false); } else { - await show_popup("Failed to admin user", false); + await show_popup("Failed to promote user", false); } }; @@ -338,9 +334,9 @@ }); } if (response.ok) { - await show_popup("User de-admined", false); + await show_popup("User demoted", false); } else { - await show_popup("Failed to admin user", false); + await show_popup("Failed to demote user", false); } }; diff --git a/front/volume/src/components/Pong/Pong.svelte b/front/volume/src/components/Pong/Pong.svelte index 96fc268..e742b8d 100644 --- a/front/volume/src/components/Pong/Pong.svelte +++ b/front/volume/src/components/Pong/Pong.svelte @@ -28,7 +28,6 @@ setupSocket(renderCanvas, canvas, context); } - export let fakeUser: boolean; export let appState: string; export let setAppState: (newState: APPSTATE | string) => void; @@ -118,7 +117,7 @@ } async function onSocketOpen() { - if (!fakeUser) await getUser(); + await getUser(); void logIn(); connected = true; }