Fix a few things

This commit is contained in:
calzoneman 2014-02-15 00:12:11 -06:00
parent 1cbb1c2a6a
commit 573e59680e
4 changed files with 75 additions and 49 deletions

View file

@ -547,7 +547,7 @@ Channel.prototype.join = function (user) {
self.sendVoteskipUpdate(self.users); self.sendVoteskipUpdate(self.users);
self.sendUsercount(self.users); self.sendUsercount(self.users);
user.whenLoggedIn(function () { user.once("channelRank", function () {
if (!self.registered) { if (!self.registered) {
afterLogin(); afterLogin();
return; return;
@ -1341,7 +1341,7 @@ Channel.prototype.sendPoll = function (users) {
var unobscured = self.poll.packUpdate(true); var unobscured = self.poll.packUpdate(true);
users.forEach(function (u) { users.forEach(function (u) {
if (self.hasPermission(u, "viewpollresults")) { if (self.hasPermission(u, "viewhiddenpoll")) {
u.socket.emit("newPoll", unobscured); u.socket.emit("newPoll", unobscured);
} else { } else {
u.socket.emit("newPoll", obscured); u.socket.emit("newPoll", obscured);

View file

@ -1,9 +1,16 @@
var crypto = require("crypto"); (function () {
var root, crypto = false;
if (typeof window === "undefined") {
root = module.exports;
} else {
root = window.utils = {};
}
if (typeof require === "function") {
crypto = require("crypto");
}
/*
Set prototype- simple wrapper around JS objects to
manipulate them like a set
*/
var Set = function (items) { var Set = function (items) {
this._items = {}; this._items = {};
var self = this; var self = this;
@ -34,16 +41,17 @@ Set.prototype.forEach = function (fn) {
} }
}; };
module.exports = { root.Set = Set;
isValidChannelName: function (name) {
root.isValidChannelName = function (name) {
return name.match(/^[\w-]{1,30}$/); return name.match(/^[\w-]{1,30}$/);
}, },
isValidUserName: function (name) { root.isValidUserName = function (name) {
return name.match(/^[\w-]{1,20}$/); return name.match(/^[\w-]{1,20}$/);
}, },
isValidEmail: function (email) { root.isValidEmail = function (email) {
if (email.length > 255) { if (email.length > 255) {
return false; return false;
} }
@ -59,7 +67,7 @@ module.exports = {
return true; return true;
}, },
randomSalt: function (length) { root.randomSalt = function (length) {
var chars = "abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var chars = "abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789!@#$%^&*_+=~"; + "0123456789!@#$%^&*_+=~";
var salt = []; var salt = [];
@ -69,7 +77,7 @@ module.exports = {
return salt.join(''); return salt.join('');
}, },
maskIP: function (ip) { root.maskIP = function (ip) {
if(ip.match(/^\d+\.\d+\.\d+\.\d+$/)) { if(ip.match(/^\d+\.\d+\.\d+\.\d+$/)) {
// standard 32 bit IP // standard 32 bit IP
return ip.replace(/\d+\.\d+\.(\d+\.\d+)/, "x.x.$1"); return ip.replace(/\d+\.\d+\.(\d+\.\d+)/, "x.x.$1");
@ -79,7 +87,7 @@ module.exports = {
} }
}, },
formatTime: function (sec) { root.formatTime = function (sec) {
if(sec === "--:--") if(sec === "--:--")
return sec; return sec;
@ -107,7 +115,7 @@ module.exports = {
return [h, m, s].join(":"); return [h, m, s].join(":");
}, },
newRateLimiter: function () { root.newRateLimiter = function () {
return { return {
count: 0, count: 0,
lastTime: 0, lastTime: 0,
@ -152,7 +160,7 @@ module.exports = {
}; };
}, },
formatLink: function (id, type) { root.formatLink = function (id, type) {
switch (type) { switch (type) {
case "yt": case "yt":
return "http://youtu.be/" + id; return "http://youtu.be/" + id;
@ -181,7 +189,7 @@ module.exports = {
} }
}, },
isLive: function (type) { root.isLive = function (type) {
switch (type) { switch (type) {
case "li": case "li":
case "tw": case "tw":
@ -197,11 +205,12 @@ module.exports = {
} }
}, },
Set: Set, root.sha1 = function (data) {
if (!crypto) {
sha1: function (data) { return "";
}
var shasum = crypto.createHash("sha1"); var shasum = crypto.createHash("sha1");
shasum.update(data); shasum.update(data);
return shasum.digest("hex"); return shasum.digest("hex");
} }
}; })();

View file

@ -179,7 +179,15 @@ function handleSocketConfig(req, res) {
function handleUserAgreement(req, res) { function handleUserAgreement(req, res) {
logRequest(req); logRequest(req);
var loginName = false;
if (req.cookies.auth) {
loginName = req.cookies.auth.split(":")[0];
}
sendJade(res, "tos", { sendJade(res, "tos", {
loggedIn: loginName !== false,
loginName: loginName,
domain: Config.get("http.domain") domain: Config.get("http.domain")
}); });
} }
@ -187,6 +195,11 @@ function handleUserAgreement(req, res) {
function handleContactPage(req, res) { function handleContactPage(req, res) {
logRequest(req); logRequest(req);
var loginName = false;
if (req.cookies.auth) {
loginName = req.cookies.auth.split(":")[0];
}
// Make a copy to prevent messing with the original // Make a copy to prevent messing with the original
var contacts = Config.get("contacts").map(function (c) { var contacts = Config.get("contacts").map(function (c) {
return { return {
@ -210,6 +223,8 @@ function handleContactPage(req, res) {
}); });
sendJade(res, "contact", { sendJade(res, "contact", {
loggedIn: loginName !== false,
loginName: loginName,
contacts: contacts contacts: contacts
}); });
} }

View file

@ -1596,6 +1596,8 @@ function genPermissionsEditor() {
makeOption("Edit MOTD", "motdedit", modplus, CHANNEL.perms.motdedit+""); makeOption("Edit MOTD", "motdedit", modplus, CHANNEL.perms.motdedit+"");
makeOption("Edit chat filters", "filteredit", modplus, CHANNEL.perms.filteredit+""); makeOption("Edit chat filters", "filteredit", modplus, CHANNEL.perms.filteredit+"");
makeOption("Import chat filters", "filterimport", modplus, CHANNEL.perms.filterimport+""); makeOption("Import chat filters", "filterimport", modplus, CHANNEL.perms.filterimport+"");
makeOption("Edit chat emotes", "emoteedit", modplus, CHANNEL.perms.emoteedit+"");
makeOption("Import chat emotes", "emoteimport", modplus, CHANNEL.perms.emoteimport+"");
addDivider("Misc"); addDivider("Misc");
makeOption("Drink calls", "drink", modleader, CHANNEL.perms.drink+""); makeOption("Drink calls", "drink", modleader, CHANNEL.perms.drink+"");