Add socket.io login handler

This commit is contained in:
calzoneman 2014-02-16 13:27:01 -06:00
parent 54102863ac
commit 91aaed96fa
4 changed files with 42 additions and 2 deletions

View file

@ -108,6 +108,7 @@ function handleConnection(sock) {
guest: false guest: false
}); });
user.socket.emit("rank", user.global_rank); user.socket.emit("rank", user.global_rank);
Logger.syslog.log(ip + " logged in as " + user.name);
} else { } else {
user.socket.emit("rank", -1); user.socket.emit("rank", -1);
} }

View file

@ -167,6 +167,7 @@ Server.prototype.unloadChannel = function (chan) {
} }
} }
Logger.syslog.log("Unloaded channel " + chan.name);
// Empty all outward references from the channel // Empty all outward references from the channel
var keys = Object.keys(chan); var keys = Object.keys(chan);
for (var i in keys) { for (var i in keys) {

View file

@ -67,8 +67,10 @@ function User(socket) {
pw = ""; pw = "";
} }
if (!pw) { if (!pw && !self.loggingIn && !self.loggedIn) {
self.guestLogin(name); self.guestLogin(name);
} else if (pw && !self.loggingIn && !self.loggedIn) {
self.login(name, pw);
} }
}); });
@ -472,6 +474,41 @@ User.prototype.whenLoggedIn = function (fn) {
} }
}; };
User.prototype.login = function (name, pw) {
var self = this;
self.loggingIn = true;
db.users.verifyLogin(name, pw, function (err, user) {
self.loggingIn = false;
if (err) {
if (err === "Invalid username/password combination") {
Logger.eventlog.log("[loginfail] Login failed (bad password): " + name
+ "@" + webserver.ipForRequest(req));
}
self.socket.emit("login", {
success: false,
error: err
});
return;
}
self.rank = self.global_rank = user.global_rank;
self.name = user.name;
self.loggedIn = true;
self.socket.emit("login", {
success: true,
name: user.name
});
self.socket.emit("rank", self.rank);
Logger.syslog.log(self.ip + " logged in as " + name);
if (self.inChannel()) {
self.channel.logger.log(self.ip + " logged in as " + name);
}
self.emit("login");
});
};
var lastguestlogin = {}; var lastguestlogin = {};
User.prototype.guestLogin = function (name) { User.prototype.guestLogin = function (name) {
var self = this; var self = this;
@ -545,6 +582,7 @@ User.prototype.guestLogin = function (name) {
}); });
// TODO you shouldn't be able to guest login without being in a channel // TODO you shouldn't be able to guest login without being in a channel
Logger.syslog.log(self.ip + " signed in as " + name);
if (self.inChannel()) { if (self.inChannel()) {
self.channel.logger.log(self.ip + " signed in as " + name); self.channel.logger.log(self.ip + " signed in as " + name);
} }

View file

@ -1395,7 +1395,7 @@ function addChatMessage(data) {
function fluidLayout() { function fluidLayout() {
$(".container").removeClass("container").addClass("container-fluid"); $(".container").removeClass("container").addClass("container-fluid");
$("footer .container").removeClass("container-fluid").addClass("container"); $("footer .container-fluid").removeClass("container-fluid").addClass("container");
$("body").addClass("fluid"); $("body").addClass("fluid");
resizeStuff(); resizeStuff();
} }