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
---
views/client.html | 22 +++++++++++++++++++---
webcastor.js | 27 +++++++++++++++++++--------
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/views/client.html b/views/client.html
index c322042..ebb3810 100644
--- a/views/client.html
+++ b/views/client.html
@@ -5,6 +5,8 @@
+
+
@@ -43,9 +45,9 @@
var socket;
var socketConnected = false;
- function connectSocket(channel, password) {
+ function connectSocket(channel, password, authenticate) {
socket = io.connect("/", {
- "query" : "channel=" + channel + "&password=" + password,
+ "query" : "channel=" + channel + ( authenticate ? "&password=" + password : ""),
"force new connection" : true
});
@@ -59,6 +61,20 @@
println("disconnected");
});
+ socket.on("unknown_channel", function() {
+ changeControlState(false);
+ println("unknown_channel");
+ });
+
+ socket.on("authentication_error", function() {
+ changeControlState(false);
+ println("authentication_error");
+ });
+
+ socket.on("authenticated", function() {
+ println("authenticated");
+ });
+
socket.on("message", function(message) {
println(message);
});
@@ -70,7 +86,7 @@
if (socketConnected) {
socket.disconnect();
} else {
- connectSocket(channelField.value, passwordField.value);
+ connectSocket(channelField.value, passwordField.value, usePassword.checked);
}
});
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