diff --git a/channel.js b/channel.js index 9ddcf526..f1c4252c 100644 --- a/channel.js +++ b/channel.js @@ -229,6 +229,14 @@ Channel.prototype.tryRegister = function(user) { } } +Channel.prototype.unregister = function() { + if(Database.unregisterChannel(this.name)) { + this.registered = false; + return true; + } + return false; +} + Channel.prototype.getRank = function(name) { var global = Auth.getGlobalRank(name); if(!this.registered) { diff --git a/database.js b/database.js index b431677c..ae881cf7 100644 --- a/database.js +++ b/database.js @@ -260,6 +260,27 @@ exports.registerChannel = function(chan) { return results; } +exports.unregisterChannel = function(channame) { + var db = exports.getConnection(); + if(!db) { + return false; + } + + var query = "DROP TABLE `chan_{}_bans`, `chan_{}_ranks`, `chan_{}_library`" + .replace(/\{\}/g, sqlEscape(channame)); + + var results = db.querySync(query); + if(!results) { + return false; + } + + query = "DELETE FROM channels WHERE name='{}'" + .replace("{}", sqlEscape(channame)); + results = db.querySync(query); + db.closeSync(); + return results; +} + exports.lookupChannelRank = function(channame, username) { var db = exports.getConnection(); if(!db) { diff --git a/package.json b/package.json index 97e1e254..0c7682b4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "1.7.1", + "version": "1.7.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/server.js b/server.js index cd7c2ec2..34c0ae15 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -const VERSION = "1.7.1"; +const VERSION = "1.7.2"; var fs = require("fs"); var Logger = require("./logger.js"); diff --git a/user.js b/user.js index 6423696f..3c4c8364 100644 --- a/user.js +++ b/user.js @@ -272,6 +272,35 @@ User.prototype.initCallbacks = function() { } }.bind(this)); + this.socket.on("unregisterChannel", function() { + if(this.channel == null) { + return; + } + if(!this.channel.registered) { + this.socket.emit("unregisterChannel", { + success: false, + error: "This channel is already unregistered" + }); + } + else if(this.rank < 10) { + this.socket.emit("unregisterChannel", { + success: false, + error: "You don't have permission to unregister" + }); + } + else if(this.channel.unregister()) { + this.socket.emit("unregisterChannel", { + success: true + }); + } + else { + this.socket.emit("unregisterChannel", { + success: false, + error: "Unregistration failed. Please see a site admin if this continues." + }); + } + }.bind(this)); + this.socket.on("adm", function(data) { if(Rank.hasPermission(this, "acp")) { this.handleAdm(data); diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 365ff485..be9a936e 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -75,6 +75,15 @@ Callbacks = { } }, + unregisterChannel: function(data) { + if(data.success) { + alert("Channel unregistered"); + } + else { + alert(data.error); + } + }, + updateMotd: function(data) { $("#motdtext").val(data.motd); if(data.motd != "") diff --git a/www/assets/js/client.js b/www/assets/js/client.js index b1be25f1..4350a274 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -456,6 +456,13 @@ $("#show_acl").click(function() { } }); +$("#drop_channel").click(function() { + var res = confirm("You are about to unregister your channel. This will PERMANENTLY delete your channel data, including ranks, bans, and library videos. This cannot be undone. Are you sure you want to continue?"); + if(res) { + socket.emit("unregisterChannel"); + } +}); + function splitreEntry(str) { var split = []; var current = []; diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index 0c7b9aa4..dc4d93c9 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -644,6 +644,9 @@ function handleRankChange() { $("#clearplaylist").css("display", "none"); $("#shuffleplaylist").css("display", "none"); } + if(RANK >= 10) { + $("#drop_channel").parent().css("display", ""); + } } function onWindowFocus() { diff --git a/www/channel.html b/www/channel.html index 2f4940a6..70424bce 100644 --- a/www/channel.html +++ b/www/channel.html @@ -140,6 +140,9 @@