Add unregistration for channel admins

This commit is contained in:
calzoneman 2013-05-13 15:41:29 -04:00
parent 27cfbcb61a
commit 4620fb2d56
9 changed files with 82 additions and 2 deletions

View File

@ -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) { Channel.prototype.getRank = function(name) {
var global = Auth.getGlobalRank(name); var global = Auth.getGlobalRank(name);
if(!this.registered) { if(!this.registered) {

View File

@ -260,6 +260,27 @@ exports.registerChannel = function(chan) {
return results; 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) { exports.lookupChannelRank = function(channame, username) {
var db = exports.getConnection(); var db = exports.getConnection();
if(!db) { if(!db) {

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "1.7.1", "version": "1.7.2",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -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. 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 fs = require("fs");
var Logger = require("./logger.js"); var Logger = require("./logger.js");

29
user.js
View File

@ -272,6 +272,35 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.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) { this.socket.on("adm", function(data) {
if(Rank.hasPermission(this, "acp")) { if(Rank.hasPermission(this, "acp")) {
this.handleAdm(data); this.handleAdm(data);

View File

@ -75,6 +75,15 @@ Callbacks = {
} }
}, },
unregisterChannel: function(data) {
if(data.success) {
alert("Channel unregistered");
}
else {
alert(data.error);
}
},
updateMotd: function(data) { updateMotd: function(data) {
$("#motdtext").val(data.motd); $("#motdtext").val(data.motd);
if(data.motd != "") if(data.motd != "")

View File

@ -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) { function splitreEntry(str) {
var split = []; var split = [];
var current = []; var current = [];

View File

@ -644,6 +644,9 @@ function handleRankChange() {
$("#clearplaylist").css("display", "none"); $("#clearplaylist").css("display", "none");
$("#shuffleplaylist").css("display", "none"); $("#shuffleplaylist").css("display", "none");
} }
if(RANK >= 10) {
$("#drop_channel").parent().css("display", "");
}
} }
function onWindowFocus() { function onWindowFocus() {

View File

@ -140,6 +140,9 @@
<li> <li>
<a href="javascript:void(0)" id="show_acl">Channel Ranks</a> <a href="javascript:void(0)" id="show_acl">Channel Ranks</a>
</li> </li>
<li style="display: none">
<a href="javascript:void(0)" id="drop_channel">Unregister Channel</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>