Added sign in

This commit is contained in:
Mattias Erming 2014-06-15 21:18:45 +02:00
parent 20a87bc852
commit 86e4ad770f
3 changed files with 65 additions and 56 deletions

View File

@ -120,9 +120,6 @@ button {
#sidebar a:hover .close { #sidebar a:hover .close {
opacity: .4; opacity: .4;
} }
#sidebar a[href="#sign-in"] {
display: none;
}
#sidebar h1, #sidebar h1,
#sidebar h2 { #sidebar h2 {
color: #fff; color: #fff;

View File

@ -1,7 +1,6 @@
$(function() { $(function() {
var chat = $("#chat"); var chat = $("#chat");
var sidebar = $("#sidebar"); var sidebar = $("#sidebar");
var windows = $("#windows");
setTimeout(function() { setTimeout(function() {
// Enable transitions. // Enable transitions.
@ -42,6 +41,7 @@ $(function() {
var socket = io.connect(""); var socket = io.connect("");
var events = [ var events = [
"auth",
"debug", "debug",
"join", "join",
"messages", "messages",
@ -64,6 +64,11 @@ $(function() {
function event(e, data) { function event(e, data) {
switch (e) { switch (e) {
case "auth":
chat.add($("#networks")).empty();
$("#sign-in").addClass("active");
break;
case "debug": case "debug":
console.log(data); console.log(data);
break; break;
@ -298,13 +303,11 @@ $(function() {
viewport.removeClass("lt"); viewport.removeClass("lt");
}); });
} }
}); });
windows.on("submit", "#sign-in-form", function(e) { $("#sign-in-form").on("submit", function(e) {
e.preventDefault(); e.preventDefault();
var password = $("#sign-in-input").val(); socket.emit("auth", $("#sign-in-input").val());
socket.emit("debug", password);
}); });
function complete(word) { function complete(word) {

View File

@ -42,13 +42,11 @@ function listen() {
.use(http.static("client")) .use(http.static("client"))
.listen(port); .listen(port);
var self = this;
sockets = io.listen(app, {log: 0}).sockets.on("connection", function(socket) { sockets = io.listen(app, {log: 0}).sockets.on("connection", function(socket) {
if (!config.password) { init.call(
init.call(socket); socket,
} else { !!config.password
socket.emit("debug", "auth"); );
}
}); });
(config.networks || []).forEach(function(n) { (config.networks || []).forEach(function(n) {
@ -56,15 +54,20 @@ function listen() {
}); });
} }
function init() { function init(login) {
var socket = this; if (login) {
socket.on("debug", debug); this.on("auth", auth);
socket.on("input", input); this.emit("auth");
socket.on("fetch", fetch); } else {
socket.emit( this.join("chat");
"networks", this.on("debug", debug);
{networks: networks} this.on("input", input);
); this.on("fetch", fetch);
this.emit(
"networks",
{networks: networks}
);
}
} }
function index(req, res, next) { function index(req, res, next) {
@ -106,7 +109,7 @@ function connect(params) {
}); });
networks.push(network); networks.push(network);
sockets.emit("networks", {networks: networks}); sockets.in("chat").emit("networks", {networks: networks});
client.nick(params.nick); client.nick(params.nick);
client.user(params.nick, params.realname); client.user(params.nick, params.realname);
@ -127,6 +130,13 @@ function connect(params) {
}); });
} }
function auth(password) {
if (password == config.password) {
this.disable = false;
init.call(this);
}
}
function debug(data) { function debug(data) {
console.log(data); console.log(data);
} }
@ -175,7 +185,7 @@ function input(data) {
text: text, text: text,
}); });
chan.addMsg(msg) chan.addMsg(msg)
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -206,7 +216,7 @@ function input(data) {
text: text, text: text,
}); });
chan.addMsg(msg) chan.addMsg(msg)
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -227,7 +237,7 @@ function input(data) {
text: text, text: text,
}); });
chan.addMsg(msg) chan.addMsg(msg)
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -251,7 +261,6 @@ function input(data) {
if (!args[2] || args[2].charAt(0) == "#") { if (!args[2] || args[2].charAt(0) == "#") {
client.join(args.slice(1)); client.join(args.slice(1));
} else { } else {
console.log(args[1], args[2]);
client.join( client.join(
args[1], args[1],
args[2] // Password args[2] // Password
@ -278,7 +287,7 @@ function input(data) {
var id = chan.id; var id = chan.id;
if (chan.type == "query" || !chan.users.length) { if (chan.type == "query" || !chan.users.length) {
remove(id); remove(id);
sockets.emit("part", { sockets.in("chat").emit("part", {
id: id, id: id,
}); });
} else if (client) { } else if (client) {
@ -360,7 +369,7 @@ function input(data) {
case "disconnect": case "disconnect":
if (client) { if (client) {
networks = _.without(networks, network); networks = _.without(networks, network);
sockets.emit("networks", {networks: networks}); sockets.in("chat").emit("networks", {networks: networks});
client.quit(); client.quit();
} }
break; break;
@ -397,7 +406,7 @@ function event(e, data) {
switch (e) { switch (e) {
case "errors": case "errors":
sockets.emit("msg", { sockets.in("chat").emit("msg", {
msg: new Msg({ msg: new Msg({
type: "error", type: "error",
from: "-!-", from: "-!-",
@ -419,7 +428,7 @@ function event(e, data) {
name: data.channel, name: data.channel,
}); });
this.addChan(chan); this.addChan(chan);
sockets.emit("join", { sockets.in("chat").emit("join", {
id: this.id, id: this.id,
chan: chan, chan: chan,
}); });
@ -427,7 +436,7 @@ function event(e, data) {
var users = chan.users; var users = chan.users;
users.push(new User({name: data.nick})); users.push(new User({name: data.nick}));
chan.sortUsers(); chan.sortUsers();
sockets.emit("users", { sockets.in("chat").emit("users", {
id: chan.id, id: chan.id,
users: users, users: users,
}); });
@ -436,7 +445,7 @@ function event(e, data) {
type: "join", type: "join",
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -452,7 +461,7 @@ function event(e, data) {
} else { } else {
chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.client})); chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.client}));
} }
sockets.emit("users", { sockets.in("chat").emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,
}); });
@ -462,7 +471,7 @@ function event(e, data) {
text: data.client, text: data.client,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -485,7 +494,7 @@ function event(e, data) {
text: data.mode + " " + data.client, text: data.mode + " " + data.client,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -501,7 +510,7 @@ function event(e, data) {
text: m, text: m,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -517,7 +526,7 @@ function event(e, data) {
type: "query", type: "query",
}); });
this.addChan(chan); this.addChan(chan);
sockets.emit("join", { sockets.in("chat").emit("join", {
id: this.id, id: this.id,
chan: chan, chan: chan,
}); });
@ -538,7 +547,7 @@ function event(e, data) {
text: text, text: text,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -554,7 +563,7 @@ function event(e, data) {
chan.addUser(new User(n)); chan.addUser(new User(n));
}); });
chan.sortUsers(); chan.sortUsers();
sockets.emit("users", { sockets.in("chat").emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,
}); });
@ -568,7 +577,7 @@ function event(e, data) {
text: "You're now known as " + data["new"], text: "You're now known as " + data["new"],
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -580,7 +589,7 @@ function event(e, data) {
} }
user.name = data["new"]; user.name = data["new"];
chan.sortUsers(); chan.sortUsers();
sockets.emit("users", { sockets.in("chat").emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,
}); });
@ -590,7 +599,7 @@ function event(e, data) {
text: data["new"], text: data["new"],
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -609,7 +618,7 @@ function event(e, data) {
text: data.message, text: data.message,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -622,12 +631,12 @@ function event(e, data) {
} }
if (data.nick == this.client.me) { if (data.nick == this.client.me) {
remove(chan.id); remove(chan.id);
sockets.emit("part", { sockets.in("chat").emit("part", {
id: chan.id, id: chan.id,
}); });
} else { } else {
chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.nick})); chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.nick}));
sockets.emit("users", { sockets.in("chat").emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,
}); });
@ -636,7 +645,7 @@ function event(e, data) {
from: data.nick, from: data.nick,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -650,7 +659,7 @@ function event(e, data) {
return; return;
} }
chan.users = _.without(chan.users, user); chan.users = _.without(chan.users, user);
sockets.emit("users", { sockets.in("chat").emit("users", {
id: chan.id, id: chan.id,
users: chan.users, users: chan.users,
}); });
@ -659,7 +668,7 @@ function event(e, data) {
from: data.nick, from: data.nick,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -678,7 +687,7 @@ function event(e, data) {
text: data.topic, text: data.topic,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -692,7 +701,7 @@ function event(e, data) {
text: "You're now known as " + data, text: "You're now known as " + data,
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -709,7 +718,7 @@ function event(e, data) {
name: data.nickname, name: data.nickname,
}); });
this.addChan(chan); this.addChan(chan);
sockets.emit("join", { sockets.in("chat").emit("join", {
id: this.id, id: this.id,
chan: chan, chan: chan,
}); });
@ -732,7 +741,7 @@ function event(e, data) {
text: key + " " + data[k], text: key + " " + data[k],
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });
@ -743,7 +752,7 @@ function event(e, data) {
text: "End of /WHOIS list.", text: "End of /WHOIS list.",
}); });
chan.addMsg(msg); chan.addMsg(msg);
sockets.emit("msg", { sockets.in("chat").emit("msg", {
id: chan.id, id: chan.id,
msg: msg, msg: msg,
}); });