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 ChatCommand = require("./chatcommand");
var XSS = require("./xss");
var Media = require("./media").Media;
var fs = require("fs");
var path = require("path");
@ -452,6 +453,9 @@ Channel.prototype.preJoin = function (user, password) {
if (err) {
user.rank = user.global_rank;
} else {
if (!self.registered && user.rank > 2 && rank <= 2) {
return;
}
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.sendUserlist([user]);
};
@ -524,11 +543,20 @@ Channel.prototype.join = function (user) {
user.socket.join(self.uniqueName);
user.channel = self;
if (!self.registered) {
user.socket.emit("channelNotRegistered");
}
self.users.push(user);
self.sendVoteskipUpdate(self.users);
self.sendUsercount(self.users);
user.whenLoggedIn(function () {
if (!self.registered) {
afterLogin();
return;
}
db.channels.isNameBanned(self.name, user.name, function (err, banned) {
if (!err && banned) {
user.kick("You're banned!");
@ -554,6 +582,11 @@ Channel.prototype.join = function (user) {
Logger.syslog.log(user.ip + " joined channel " + self.name);
};
if (!self.registered) {
afterIPBan();
return;
}
db.channels.isIPBanned(self.name, user.ip, function (err, banned) {
if (!err && banned) {
user.kick("You're banned!");
@ -595,6 +628,19 @@ Channel.prototype.part = function (user) {
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
self.checkVoteskipPass();
self.sendUsercount(self.users);
@ -911,6 +957,10 @@ Channel.prototype.banIP = function (actor, ip, name, reason, range) {
Channel.prototype.sendBanlist = function (users) {
var self = this;
if (!self.registered) {
return;
}
var bans = [];
var unmaskedbans = [];
db.channels.listBans(self.name, function (err, banlist) {
@ -954,6 +1004,11 @@ Channel.prototype.sendBanlist = function (users) {
*/
Channel.prototype.sendChannelRanks = function (users) {
var self = this;
if (!self.registered) {
return;
}
db.channels.allRanks(self.name, function (err, ranks) {
if (err) {
return;

View file

@ -37,6 +37,10 @@ function User(socket) {
self.initChannelCallbacks();
});
self.socket.once("initUserPLCallbacks", function () {
self.initUserPLCallbacks();
});
self.socket.once("initACP", function () {
self.whenLoggedIn(function () {
if (self.global_rank >= 255) {
@ -274,10 +278,13 @@ User.prototype.initChannelCallbacks = function () {
});
wrapTypecheck("queue", function (data) {
console.log("queue", data);
self.channel.handleQueue(self, data);
});
wrapTypecheck("queuePlaylist", function (data) {
self.channel.handleQueuePlaylist(self, data);
});
wrapTypecheck("setTemp", function (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;

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
button#showcustomembed.btn.btn-sm.btn-default(title="Embed a custom frame", data-toggle="collapse", data-target="#customembed")
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")
span.glyphicon.glyphicon-trash
button#shuffleplaylist.btn.btn-sm.btn-default(title="Shuffle the playlist")
@ -75,15 +77,6 @@ html(lang="en")
#leftpane-inner.row
#pollwrap.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-inner.row
#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.
| 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")
#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
.vertical-spacer
.col-lg-12.col-md-12

View file

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

View file

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

View file

@ -563,7 +563,6 @@ function rebuildPlaylist() {
function showUserOptions() {
hidePlayer();
$("#useroptions").on("hidden.bs.modal", function () {
console.log("unhiding");
unhidePlayer();
});
@ -642,13 +641,15 @@ function storeOpts() {
function applyOpts() {
if ($("#usertheme").attr("href") !== USEROPTS.theme) {
$("#usertheme").remove();
if(USEROPTS.theme != "default") {
$("<link/>").attr("rel", "stylesheet")
.attr("type", "text/css")
.attr("id", "usertheme")
.attr("href", USEROPTS.theme)
.appendTo($("head"));
var theme = USEROPTS.theme;
if (theme === "default") {
theme = "/css/themes/default.css";
}
$("<link/>").attr("rel", "stylesheet")
.attr("type", "text/css")
.attr("id", "usertheme")
.attr("href", theme)
.appendTo($("head"));
fixWeirdButtonAlignmentIssue();
}
@ -881,13 +882,13 @@ function handlePermissionChange() {
" style of playlist buttons.",
"<br>"].join(""))
.attr("id", "plonotification")
.insertBefore($("#queue"));
.insertAfter($("#queuefail"));
al.find(".close").remove();
$("<button/>").addClass("btn btn-primary")
.text("Dismiss")
.appendTo(al)
.appendTo(al.find(".alert"))
.click(function() {
USEROPTS.first_visit = false;
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;
}
#userpl_list {
list-style: none outside none;
margin-left: 0;
@ -129,6 +130,7 @@
overflow-y: scroll;
}
/*
#userpl_list li {
display: inline-block;
line-height: 22px;
@ -138,6 +140,7 @@
padding: 2px;
font-size: 8pt;
}
*/
#customembed_wrap {
margin: 5px 0;
@ -191,16 +194,20 @@
background-image: url(/img/stripe-diagonal.png);
}
#queue {
.videolist {
padding: 0;
margin: 0;
}
#queue > li:last-child {
border-bottom: 0;
.videolist > li:last-child {
border-bottom-width: 0;
margin-bottom: 0;
}
#userpl_list > li:last-child {
border-bottom-width: 1px;
}
.videolist > li:first-child {
border-top-width: 1px;
}
@ -435,6 +442,8 @@ li.ui-sortable-helper, li.ui-sortable-placeholder + li.queue_entry {
.qfalert {
margin-bottom: 10px;
padding-left: 0!important;
padding-right: 0!important;
}
#customembed-content {

View file

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

View file

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