Browse Source

* Fixed block

* Removed fake users
master
vvandenb 2 years ago
parent
commit
4c42a9d93a
  1. 1
      back/volume/src/chat/chat.controller.ts
  2. 1
      back/volume/src/chat/chat.gateway.ts
  3. 33
      back/volume/src/users/users.controller.ts
  4. 1
      back/volume/src/users/users.service.ts
  5. 25
      front/volume/src/App.svelte
  6. 29
      front/volume/src/FakeLogin.svelte
  7. 18
      front/volume/src/components/Chat.svelte
  8. 3
      front/volume/src/components/Pong/Pong.svelte

1
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)
}

1
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 ||

33
back/volume/src/users/users.controller.ts

@ -38,8 +38,9 @@ export class UsersController {
@Get('blocked')
@UseGuards(AuthenticatedGuard)
async getBlockedUsers (@Profile42() profile: Profile): Promise<User[]> {
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<void> {
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<void> {
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<User[]> {
return await this.usersService.getFriends(profile.id)
return await this.usersService.getFriends(+profile.id)
}
@Get('invits')
@UseGuards(AuthenticatedGuard)
async getInvits (@Profile42() profile: Profile): Promise<User[]> {
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<void> {
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<StreamableFile> {
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<void> {
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<User | null> {

1
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
}

25
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;
}
</script>
<div>
@ -262,14 +246,7 @@
/>
</div>
{/if}
{#if fakemenu}
<FakeLogin bind:username={usernameFake} bind:ftId={ftIdFake} />
<button on:click={impersonate}>Impersonate</button>
<button on:click={() => (fakemenu = false)}>No impersonate</button>
{:else}
<Pong bind:gamePlaying={gamePlaying} bind:this={pong} {appState} {setAppState} {fakeUser} bind:resetGameConnection={resetGameConnection} />
{/if}
<Pong bind:gamePlaying={gamePlaying} bind:this={pong} {appState} {setAppState} bind:resetGameConnection={resetGameConnection} />
{/if}
</Modal>

29
front/volume/src/FakeLogin.svelte

@ -1,29 +0,0 @@
<script>
import { API_URL } from "./Auth";
export let username;
export let ftId;
async function doPost() {
await fetch(API_URL + "/users/" + ftId, {
method: "POST",
credentials: "include",
mode: "cors",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
ftId,
username,
socketKey: ftId,
avatar: "no avatar",
}),
});
}
</script>
<div>
<input bind:value={username} />
<input bind:value={ftId} />
<button type="button" on:click={doPost}> Post it. </button>
</div>

18
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);
}
};

3
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;
}

Loading…
Cancel
Save