Add socket.io login handler
This commit is contained in:
parent
54102863ac
commit
91aaed96fa
|
@ -108,6 +108,7 @@ function handleConnection(sock) {
|
|||
guest: false
|
||||
});
|
||||
user.socket.emit("rank", user.global_rank);
|
||||
Logger.syslog.log(ip + " logged in as " + user.name);
|
||||
} else {
|
||||
user.socket.emit("rank", -1);
|
||||
}
|
||||
|
|
|
@ -167,6 +167,7 @@ Server.prototype.unloadChannel = function (chan) {
|
|||
}
|
||||
}
|
||||
|
||||
Logger.syslog.log("Unloaded channel " + chan.name);
|
||||
// Empty all outward references from the channel
|
||||
var keys = Object.keys(chan);
|
||||
for (var i in keys) {
|
||||
|
|
40
lib/user.js
40
lib/user.js
|
@ -67,8 +67,10 @@ function User(socket) {
|
|||
pw = "";
|
||||
}
|
||||
|
||||
if (!pw) {
|
||||
if (!pw && !self.loggingIn && !self.loggedIn) {
|
||||
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 = {};
|
||||
User.prototype.guestLogin = function (name) {
|
||||
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
|
||||
Logger.syslog.log(self.ip + " signed in as " + name);
|
||||
if (self.inChannel()) {
|
||||
self.channel.logger.log(self.ip + " signed in as " + name);
|
||||
}
|
||||
|
|
|
@ -1395,7 +1395,7 @@ function addChatMessage(data) {
|
|||
|
||||
function fluidLayout() {
|
||||
$(".container").removeClass("container").addClass("container-fluid");
|
||||
$("footer .container").removeClass("container-fluid").addClass("container");
|
||||
$("footer .container-fluid").removeClass("container-fluid").addClass("container");
|
||||
$("body").addClass("fluid");
|
||||
resizeStuff();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue