Work on unregistered channels; fixes

This commit is contained in:
calzoneman 2014-02-02 12:41:41 -06:00
parent 0603a02d2e
commit b214c07fe0
10 changed files with 284 additions and 60 deletions

View File

@ -9,6 +9,7 @@ var MakeEmitter = require("./emitter");
var InfoGetter = require("./get-info"); var InfoGetter = require("./get-info");
var ChatCommand = require("./chatcommand"); var ChatCommand = require("./chatcommand");
var XSS = require("./xss"); var XSS = require("./xss");
var Media = require("./media").Media;
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
@ -452,6 +453,9 @@ Channel.prototype.preJoin = function (user, password) {
if (err) { if (err) {
user.rank = user.global_rank; user.rank = user.global_rank;
} else { } else {
if (!self.registered && user.rank > 2 && rank <= 2) {
return;
}
user.rank = Math.max(rank, user.global_rank); user.rank = Math.max(rank, user.global_rank);
} }
@ -515,6 +519,21 @@ Channel.prototype.join = function (user) {
} }
} }
if (!self.registered) {
var hasAdmin = false;
for (var i = 0; i < self.users.length; i++) {
if (self.users[i].rank > 2) {
hasAdmin = true;
break;
}
}
if (!hasAdmin) {
user.rank = 4;
user.socket.emit("rank", 4);
}
}
self.sendUserJoin(self.users, user); self.sendUserJoin(self.users, user);
self.sendUserlist([user]); self.sendUserlist([user]);
}; };
@ -524,11 +543,20 @@ Channel.prototype.join = function (user) {
user.socket.join(self.uniqueName); user.socket.join(self.uniqueName);
user.channel = self; user.channel = self;
if (!self.registered) {
user.socket.emit("channelNotRegistered");
}
self.users.push(user); self.users.push(user);
self.sendVoteskipUpdate(self.users); self.sendVoteskipUpdate(self.users);
self.sendUsercount(self.users); self.sendUsercount(self.users);
user.whenLoggedIn(function () { user.whenLoggedIn(function () {
if (!self.registered) {
afterLogin();
return;
}
db.channels.isNameBanned(self.name, user.name, function (err, banned) { db.channels.isNameBanned(self.name, user.name, function (err, banned) {
if (!err && banned) { if (!err && banned) {
user.kick("You're banned!"); user.kick("You're banned!");
@ -554,6 +582,11 @@ Channel.prototype.join = function (user) {
Logger.syslog.log(user.ip + " joined channel " + self.name); Logger.syslog.log(user.ip + " joined channel " + self.name);
}; };
if (!self.registered) {
afterIPBan();
return;
}
db.channels.isIPBanned(self.name, user.ip, function (err, banned) { db.channels.isIPBanned(self.name, user.ip, function (err, banned) {
if (!err && banned) { if (!err && banned) {
user.kick("You're banned!"); user.kick("You're banned!");
@ -595,6 +628,19 @@ Channel.prototype.part = function (user) {
self.users.splice(idx, 1); self.users.splice(idx, 1);
} }
if (!self.registered && user.rank === 4) {
if (self.users.length > 0) {
for (var i = 0; i < self.users.length; i++) {
self.users[i].rank = 4;
self.users[i].socket.emit("rank", 4);
self.sendAll("setUserRank", {
name: self.users[i].name,
rank: 4
});
}
}
}
// A change in usercount might cause a voteskip result to change // A change in usercount might cause a voteskip result to change
self.checkVoteskipPass(); self.checkVoteskipPass();
self.sendUsercount(self.users); self.sendUsercount(self.users);
@ -911,6 +957,10 @@ Channel.prototype.banIP = function (actor, ip, name, reason, range) {
Channel.prototype.sendBanlist = function (users) { Channel.prototype.sendBanlist = function (users) {
var self = this; var self = this;
if (!self.registered) {
return;
}
var bans = []; var bans = [];
var unmaskedbans = []; var unmaskedbans = [];
db.channels.listBans(self.name, function (err, banlist) { db.channels.listBans(self.name, function (err, banlist) {
@ -954,6 +1004,11 @@ Channel.prototype.sendBanlist = function (users) {
*/ */
Channel.prototype.sendChannelRanks = function (users) { Channel.prototype.sendChannelRanks = function (users) {
var self = this; var self = this;
if (!self.registered) {
return;
}
db.channels.allRanks(self.name, function (err, ranks) { db.channels.allRanks(self.name, function (err, ranks) {
if (err) { if (err) {
return; return;

View File

@ -37,6 +37,10 @@ function User(socket) {
self.initChannelCallbacks(); self.initChannelCallbacks();
}); });
self.socket.once("initUserPLCallbacks", function () {
self.initUserPLCallbacks();
});
self.socket.once("initACP", function () { self.socket.once("initACP", function () {
self.whenLoggedIn(function () { self.whenLoggedIn(function () {
if (self.global_rank >= 255) { if (self.global_rank >= 255) {
@ -274,10 +278,13 @@ User.prototype.initChannelCallbacks = function () {
}); });
wrapTypecheck("queue", function (data) { wrapTypecheck("queue", function (data) {
console.log("queue", data);
self.channel.handleQueue(self, data); self.channel.handleQueue(self, data);
}); });
wrapTypecheck("queuePlaylist", function (data) {
self.channel.handleQueuePlaylist(self, data);
});
wrapTypecheck("setTemp", function (data) { wrapTypecheck("setTemp", function (data) {
self.channel.handleSetTemp(self, data); self.channel.handleSetTemp(self, data);
}); });
@ -526,4 +533,8 @@ User.prototype.guestLogin = function (name) {
}); });
}; };
User.prototype.initUserPLCallbacks = function () {
require("./userplaylists").init(this);
};
module.exports = User; module.exports = User;

77
lib/userplaylists.js Normal file
View File

@ -0,0 +1,77 @@
var db = require("./database");
function listPlaylists(user) {
db.listUserPlaylists(user.name, function (err, rows) {
if (err) {
user.socket.emit("errorMsg", {
msg: "Database error when attempting to fetch list of playlists"
});
return;
}
user.socket.emit("listPlaylists", rows);
});
}
function clonePlaylist(user, data) {
if (!user.inChannel()) {
user.socket.emit("errorMsg", {
msg: "You must be in a channel in order to clone its playlist"
});
return;
}
if (typeof data.name !== "string") {
return;
}
var pl = user.channel.playlist.items.toArray();
db.saveUserPlaylist(pl, user.name, data.name, function (err, res) {
if (err) {
user.socket.emit("errorMsg", {
msg: "Database error when saving playlist"
});
} else {
listPlaylists(user);
}
});
}
function deletePlaylist(user, data) {
if (typeof data.name !== "string") {
return;
}
db.deleteUserPlaylist(user.name, data.name, function (err) {
if (err) {
user.socket.emit("errorMsg", {
msg: err
});
return;
}
setImmediate(function () {
listPlaylists(user);
});
});
}
module.exports.init = function (user) {
console.log('Initializing playlists for ' + user.name);
var s = user.socket;
var wrap = function (cb) {
return function (data) {
if (!user.loggedIn || user.rank < 1) {
s.emit("errorMsg", {
msg: "You must be logged in to manage playlists"
});
return;
}
cb(user, data);
};
};
s.on("listPlaylists", wrap(listPlaylists));
s.on("clonePlaylist", wrap(clonePlaylist));
s.on("deletePlaylist", wrap(deletePlaylist));
};

View File

@ -56,6 +56,8 @@ html(lang="en")
span.glyphicon.glyphicon-plus span.glyphicon.glyphicon-plus
button#showcustomembed.btn.btn-sm.btn-default(title="Embed a custom frame", data-toggle="collapse", data-target="#customembed") button#showcustomembed.btn.btn-sm.btn-default(title="Embed a custom frame", data-toggle="collapse", data-target="#customembed")
span.glyphicon.glyphicon-th-large span.glyphicon.glyphicon-th-large
button#showplaylistmanager.btn.btn-sm.btn-default(title="Manage playlists", data-toggle="collapse", data-target="#playlistmanager")
span.glyphicon.glyphicon-list
button#clearplaylist.btn.btn-sm.btn-default(title="Clear the playlist") button#clearplaylist.btn.btn-sm.btn-default(title="Clear the playlist")
span.glyphicon.glyphicon-trash span.glyphicon.glyphicon-trash
button#shuffleplaylist.btn.btn-sm.btn-default(title="Shuffle the playlist") button#shuffleplaylist.btn.btn-sm.btn-default(title="Shuffle the playlist")
@ -75,15 +77,6 @@ html(lang="en")
#leftpane-inner.row #leftpane-inner.row
#pollwrap.col-lg-12.col-md-12 #pollwrap.col-lg-12.col-md-12
#playlistmanagerwrap.col-lg-12.col-md-12 #playlistmanagerwrap.col-lg-12.col-md-12
button#showplaylistmanager.btn.btn-default.btn-block(data-toggle="collapse", data-target="#playlistmanager") Playlist Manager
#playlistmanager.collapse
.row.vertical-spacer
.col-lg-12.col-md-12
.input-group
input#userpl_name.form-control(type="text", placeholder="Playlist Name")
span.input-group-btn
button#userpl_save.btn.btn-default Save
ul#userpl_list.col-lg-12.col-md-12
#rightpane.col-lg-7.col-md-7 #rightpane.col-lg-7.col-md-7
#rightpane-inner.row #rightpane-inner.row
#addfromurl.collapse.plcontrol-collapse.col-lg-12.col-md-12 #addfromurl.collapse.plcontrol-collapse.col-lg-12.col-md-12
@ -114,6 +107,13 @@ html(lang="en")
| Paste the embed code below and click Next or At End. | Paste the embed code below and click Next or At End.
| Acceptable embed codes are <code>&lt;iframe&gt;</code> and <code>&lt;object&gt;</code> tags. | Acceptable embed codes are <code>&lt;iframe&gt;</code> and <code>&lt;object&gt;</code> tags.
textarea#customembed-content.input-block-level.form-control(rows="3") textarea#customembed-content.input-block-level.form-control(rows="3")
#playlistmanager.collapse.plcontrol-collapse.col-lg-12.col-md-12
.vertical-spacer
.input-group
input#userpl_name.form-control(type="text", placeholder="Playlist Name")
span.input-group-btn
button#userpl_save.btn.btn-default Save
ul#userpl_list.videolist
#queuefail.col-lg-12.col-md-12 #queuefail.col-lg-12.col-md-12
.vertical-spacer .vertical-spacer
.col-lg-12.col-md-12 .col-lg-12.col-md-12

View File

@ -143,20 +143,20 @@ Callbacks = {
channelNotRegistered: function() { channelNotRegistered: function() {
var div = $("<div/>").addClass("alert alert-info") var div = $("<div/>").addClass("alert alert-info")
.attr("id", "chregnotice") .appendTo($("<div/>").addClass("col-md-12").appendTo($("#announcements")));
.insertBefore($("#main"));
$("<button/>").addClass("close pull-right").html("&times;") $("<button/>").addClass("close pull-right")
.appendTo(div) .appendTo(div)
.click(function() { div.remove(); }); .click(function () {
$("<h3/>").text("This channel isn't registered").appendTo(div); div.parent().remove();
$("<button/>").addClass("btn btn-primary").text("Register it") })
.attr("id", "chanregisterbtn") .html("&times;");
.appendTo(div) $("<h4/>").appendTo(div).text("Unregistered channel");
.click(function() { $("<p/>").appendTo(div)
$(this).attr("disabled", true) .html("This channel is not registered to a CyTube account. You can still " +
.text("Registering..."); "use it, but some features will not be available. To register a " +
socket.emit("registerChannel"); "channel to your account, visit your <a href='/account/channels'>" +
}); "channels</a> page.");
}, },
registerChannel: function(data) { registerChannel: function(data) {
@ -427,15 +427,19 @@ Callbacks = {
}, },
login: function(data) { login: function(data) {
if(!data.success) { if (!data.success) {
if(data.error != "Session expired") { if (data.error != "Session expired") {
alert(data.error); errDialog(data.error);
} }
} } else {
else {
CLIENT.name = data.name; CLIENT.name = data.name;
CLIENT.guest = data.guest; CLIENT.guest = data.guest;
CLIENT.logged_in = true; CLIENT.logged_in = true;
if (!CLIENT.guest) {
socket.emit("initUserPLCallbacks");
socket.emit("listPlaylists");
}
} }
}, },
@ -911,24 +915,16 @@ Callbacks = {
} }
}, },
savePlaylist: function(data) {
if(data.success) {
makeAlert("Success", "Playlist saved.", "alert-success");
}
else {
makeAlert("Error", data.error, "alert-danger")
.addClass("span12")
.insertBefore($("#userpl_list"));
}
},
listPlaylists: function(data) { listPlaylists: function(data) {
$("#userpl_list").data("entries", data);
formatUserPlaylistList();
return;
if(data.error) { if(data.error) {
makeAlert("Error", data.error, "alert-danger") makeAlert("Error", data.error, "alert-danger")
.insertBefore($("#userpl_list")); .insertBefore($("#userpl_list"));
} }
else { else {
var pls = data.pllist; var pls = data;
pls.sort(function(a, b) { pls.sort(function(a, b) {
var x = a.name.toLowerCase(); var x = a.name.toLowerCase();
var y = b.name.toLowerCase(); var y = b.name.toLowerCase();
@ -948,7 +944,7 @@ Callbacks = {
if(pls[i].count != 1) { if(pls[i].count != 1) {
metastr += "s"; metastr += "s";
} }
metastr +=", playtime " + pls[i].time; metastr +=", playtime " + pls[i].duration;
$("<div/>").text(metastr) $("<div/>").text(metastr)
.css("float", "right") .css("float", "right")
.appendTo(li); .appendTo(li);

View File

@ -265,17 +265,13 @@ $("#youtube_search").click(function () {
/* user playlists */ /* user playlists */
$("#showplaylistmanager").click(function() {
socket.emit("listPlaylists");
});
$("#userpl_save").click(function() { $("#userpl_save").click(function() {
if($("#userpl_name").val().trim() == "") { if($("#userpl_name").val().trim() == "") {
makeAlert("Invalid Name", "Playlist name cannot be empty", "alert-danger") makeAlert("Invalid Name", "Playlist name cannot be empty", "alert-danger")
.insertAfter($("#userpl_save").parent()); .insertAfter($("#userpl_save").parent());
return; return;
} }
socket.emit("savePlaylist", { socket.emit("clonePlaylist", {
name: $("#userpl_name").val() name: $("#userpl_name").val()
}); });
}); });
@ -482,7 +478,8 @@ $("#cs-chanranks-mod").click(chanrankSubmit.bind(this, 2));
$("#cs-chanranks-adm").click(chanrankSubmit.bind(this, 3)); $("#cs-chanranks-adm").click(chanrankSubmit.bind(this, 3));
$("#cs-chanranks-owner").click(chanrankSubmit.bind(this, 4)); $("#cs-chanranks-owner").click(chanrankSubmit.bind(this, 4));
["#showmediaurl", "#showsearch", "#showcustomembed"].forEach(function (id) { ["#showmediaurl", "#showsearch", "#showcustomembed", "#showplaylistmanager"]
.forEach(function (id) {
$(id).click(function () { $(id).click(function () {
var wasActive = $(id).hasClass("active"); var wasActive = $(id).hasClass("active");
$(".plcontrol-collapse").collapse("hide"); $(".plcontrol-collapse").collapse("hide");

View File

@ -563,7 +563,6 @@ function rebuildPlaylist() {
function showUserOptions() { function showUserOptions() {
hidePlayer(); hidePlayer();
$("#useroptions").on("hidden.bs.modal", function () { $("#useroptions").on("hidden.bs.modal", function () {
console.log("unhiding");
unhidePlayer(); unhidePlayer();
}); });
@ -642,13 +641,15 @@ function storeOpts() {
function applyOpts() { function applyOpts() {
if ($("#usertheme").attr("href") !== USEROPTS.theme) { if ($("#usertheme").attr("href") !== USEROPTS.theme) {
$("#usertheme").remove(); $("#usertheme").remove();
if(USEROPTS.theme != "default") { var theme = USEROPTS.theme;
$("<link/>").attr("rel", "stylesheet") if (theme === "default") {
.attr("type", "text/css") theme = "/css/themes/default.css";
.attr("id", "usertheme")
.attr("href", USEROPTS.theme)
.appendTo($("head"));
} }
$("<link/>").attr("rel", "stylesheet")
.attr("type", "text/css")
.attr("id", "usertheme")
.attr("href", theme)
.appendTo($("head"));
fixWeirdButtonAlignmentIssue(); fixWeirdButtonAlignmentIssue();
} }
@ -881,13 +882,13 @@ function handlePermissionChange() {
" style of playlist buttons.", " style of playlist buttons.",
"<br>"].join("")) "<br>"].join(""))
.attr("id", "plonotification") .attr("id", "plonotification")
.insertBefore($("#queue")); .insertAfter($("#queuefail"));
al.find(".close").remove(); al.find(".close").remove();
$("<button/>").addClass("btn btn-primary") $("<button/>").addClass("btn btn-primary")
.text("Dismiss") .text("Dismiss")
.appendTo(al) .appendTo(al.find(".alert"))
.click(function() { .click(function() {
USEROPTS.first_visit = false; USEROPTS.first_visit = false;
storeOpts(); storeOpts();
@ -2107,3 +2108,81 @@ function formatCSChatFilterList() {
} }
}); });
} }
function formatTime(sec) {
var h = Math.floor(sec / 3600) + "";
var m = Math.floor((sec % 3600) / 60) + "";
var s = sec % 60 + "";
if (h.length < 2) {
h = "0" + h;
}
if (m.length < 2) {
m = "0" + m;
}
if (s.length < 2) {
s = "0" + s;
}
if (h === "00") {
return [m, s].join(":");
} else {
return [h, m, s].join(":");
}
}
function formatUserPlaylistList() {
var list = $("#userpl_list").data("entries") || [];
list.sort(function (a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return x == y ? 0 : (x < y ? -1 : 1);
});
$("#userpl_list").html("");
list.forEach(function (pl) {
var li = $("<li/>").addClass("queue_entry").appendTo($("#userpl_list"));
var title = $("<span/>").addClass("qe_title").appendTo(li)
.text(pl.name);
var time = $("<span/>").addClass("pull-right").appendTo(li)
.text(pl.count + " items, playtime " + formatTime(pl.duration));
var clear = $("<div/>").addClass("qe_clear").appendTo(li);
var btns = $("<div/>").addClass("btn-group pull-left").prependTo(li);
if (hasPermission("playlistadd")) {
$("<button/>").addClass("btn btn-xs btn-default")
.text("End")
.appendTo(btns)
.click(function () {
socket.emit("queuePlaylist", {
name: pl.name,
pos: "end"
});
});
}
if (hasPermission("playlistadd") && hasPermission("playlistnext")) {
$("<button/>").addClass("btn btn-xs btn-default")
.text("Next")
.prependTo(btns)
.click(function () {
socket.emit("queuePlaylist", {
name: pl.name,
pos: "next"
});
});
}
$("<button/>").addClass("btn btn-xs btn-danger")
.html("<span class='glyphicon glyphicon-trash'></span>")
.attr("title", "Delete playlist")
.appendTo(btns)
.click(function () {
socket.emit("deletePlaylist", {
name: pl.name
});
});
});
}

View File

@ -122,6 +122,7 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
#userpl_list { #userpl_list {
list-style: none outside none; list-style: none outside none;
margin-left: 0; margin-left: 0;
@ -129,6 +130,7 @@
overflow-y: scroll; overflow-y: scroll;
} }
/*
#userpl_list li { #userpl_list li {
display: inline-block; display: inline-block;
line-height: 22px; line-height: 22px;
@ -138,6 +140,7 @@
padding: 2px; padding: 2px;
font-size: 8pt; font-size: 8pt;
} }
*/
#customembed_wrap { #customembed_wrap {
margin: 5px 0; margin: 5px 0;
@ -191,16 +194,20 @@
background-image: url(/img/stripe-diagonal.png); background-image: url(/img/stripe-diagonal.png);
} }
#queue { .videolist {
padding: 0; padding: 0;
margin: 0; margin: 0;
} }
#queue > li:last-child { .videolist > li:last-child {
border-bottom: 0; border-bottom-width: 0;
margin-bottom: 0; margin-bottom: 0;
} }
#userpl_list > li:last-child {
border-bottom-width: 1px;
}
.videolist > li:first-child { .videolist > li:first-child {
border-top-width: 1px; border-top-width: 1px;
} }
@ -435,6 +442,8 @@ li.ui-sortable-helper, li.ui-sortable-placeholder + li.queue_entry {
.qfalert { .qfalert {
margin-bottom: 10px; margin-bottom: 10px;
padding-left: 0!important;
padding-right: 0!important;
} }
#customembed-content { #customembed-content {

View File

@ -21,4 +21,3 @@ footer {
.profile-box, .user-dropdown { .profile-box, .user-dropdown {
background-color: #ffffff; background-color: #ffffff;
} }

View File

@ -18,6 +18,7 @@
css.setAttribute("rel", "stylesheet"); css.setAttribute("rel", "stylesheet");
css.setAttribute("type", "text/css"); css.setAttribute("type", "text/css");
css.setAttribute("href", theme); css.setAttribute("href", theme);
css.setAttribute("id", "usertheme");
document.head.appendChild(css); document.head.appendChild(css);
} }
})(); })();