Skip to content
Snippets Groups Projects
Unverified Commit 208e19ba authored by Marius Friess's avatar Marius Friess Committed by GitHub
Browse files

Add password check when entering channel (#39)

parent f1dc6960
Branches
No related tags found
No related merge requests found
......@@ -51,17 +51,24 @@ export class ChannelGateway implements OnGatewayConnection {
payload: {
name: string;
channelId: string;
password?: string;
},
) {
if (!this.channels.exists(payload.channelId)) {
return { error: 'Der Raum konnte nicht gefunden werden' };
}
const channel = await this.channels.joinAsStudent(
client,
payload.channelId,
payload.name,
);
let channel;
try {
channel = await this.channels.joinAsStudent(
client,
payload.channelId,
payload.name,
payload.password,
);
} catch (e) {
return { error: e.message };
}
return this.channelState(channel);
}
......
......@@ -56,6 +56,7 @@ export class ChannelService {
client: Socket,
channelId: string,
name: string,
password?: string,
): Promise<Channel> {
const channel = this.channels[channelId];
......@@ -63,6 +64,10 @@ export class ChannelService {
throw new WsException('Channel not found');
}
if (channel.room.password && channel.room.password !== password) {
throw new WsException('Wrong password');
}
await channel.joinAsStudent(client, name);
channel.clearCloseTimeout();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment