From 88d204c75200d3185dd70cc583e69f57f3550b09 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 6 Jul 2014 16:23:47 +0200 Subject: Add authentication events --- webcastor.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'webcastor.js') diff --git a/webcastor.js b/webcastor.js index 39c37a9..d1828fc 100644 --- a/webcastor.js +++ b/webcastor.js @@ -173,22 +173,33 @@ var Server = { Channel.getPassword(channel, function(hashedPassword) { if (hashedPassword === null) { - console.log('Client joined an unknown channel'); + console.log('Client tried to join an unknown channel'); + socket.emit('unknown_channel'); return; } socket.join(channel); - if (!imports.passwordHash.verify(password, hashedPassword) && hashedPassword !== 'none') { + if (password === undefined) { + console.log('Client joined ' + channel); - return; - } - console.log('Broadcaster joined ' + channel); + } else { + + if (hashedPassword === 'none' || imports.passwordHash.verify(password, hashedPassword)) { + console.log('Broadcaster joined ' + channel); + socket.emit("authenticated"); + + socket.on('message', function(event) { + Server.broadcast(socket, channel, event); + }); + } else { + console.log('Authentication error on channel ' + channel); + socket.emit('authentication_error'); + } + + } - socket.on('message', function(event) { - Server.broadcast(socket, channel, event); - }); }); }, -- cgit v1.2.3