From b53ac91a6186e94730ad73ba2a7ed6832484f878 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 6 Aug 2013 11:20:15 -0400 Subject: [PATCH] Add 'My Channels' to prevent silly people from forgetting which rooms they own --- api.js | 26 +++++++++++++++++++++++--- database.js | 21 +++++++++++++++++++++ www/account.html | 11 +++++++++++ www/assets/js/account.js | 27 +++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/api.js b/api.js index 3f9dfc25..607b8041 100644 --- a/api.js +++ b/api.js @@ -356,9 +356,6 @@ module.exports = function (Server) { var session = params.session || ""; var img = params.profile_image || ""; var text = params.profile_text || ""; - console.log(name); - console.log(img); - console.log(text); var row = Auth.login(name, pw, session); if(!row) { @@ -501,6 +498,28 @@ module.exports = function (Server) { } }, + handleListUserChannels: function (params, req, res) { + var name = params.name || ""; + var pw = params.pw || ""; + var session = params.session || ""; + + var row = Auth.login(name, pw, session); + if(!row) { + this.sendJSON(res, { + success: false, + error: "Invalid login" + }); + return; + } + + var channels = Server.db.listUserChannels(name); + + this.sendJSON(res, { + success: true, + channels: channels + }); + }, + handleAdmReports: function (params, req, res) { this.sendJSON(res, { error: "Not implemented" @@ -590,6 +609,7 @@ module.exports = function (Server) { "recoverpw" : api.handlePasswordRecover.bind(api), "setprofile" : api.handleProfileChange.bind(api), "getprofile" : api.handleProfileGet.bind(api), + "listuserchannels": api.handleListUserChannels.bind(api), "setemail" : api.handleEmailChange.bind(api), "admreports" : api.handleAdmReports.bind(api), "readactionlog" : api.handleReadActionLog.bind(api) diff --git a/database.js b/database.js index c57bebac..9da571c3 100644 --- a/database.js +++ b/database.js @@ -943,6 +943,26 @@ function deleteUserPlaylist(user, name) { return results; } +function listUserChannels(user) { + var db = getConnection(); + if(!db) { + return []; + } + + var query = createQuery( + "SELECT * FROM channels WHERE owner=? ORDER BY id ASC", + [user] + ); + + var results = db.querySync(query); + if(!results) { + Logger.errlog.log("! Failed to list user channels"); + return []; + } + + return results.fetchAllSync(); +} + /* User Aliases */ function recordVisit(ip, name) { @@ -1058,6 +1078,7 @@ exports.getUserPlaylists = getUserPlaylists; exports.loadUserPlaylist = loadUserPlaylist; exports.saveUserPlaylist = saveUserPlaylist; exports.deleteUserPlaylist = deleteUserPlaylist; +exports.listUserChannels = listUserChannels; exports.recordVisit = recordVisit; exports.getAliases = getAliases; exports.ipForName = ipForName; diff --git a/www/account.html b/www/account.html index fb4e3678..61fa92da 100644 --- a/www/account.html +++ b/www/account.html @@ -47,6 +47,7 @@
  • Reset Password
  • Edit Profile
  • Change Email
  • +
  • My Channels
  • @@ -208,6 +209,16 @@
    +
    diff --git a/www/assets/js/account.js b/www/assets/js/account.js index 391f4f31..1f1d8fe0 100644 --- a/www/assets/js/account.js +++ b/www/assets/js/account.js @@ -70,6 +70,33 @@ $("#profile").click(function() { }); } }); +$("#channels").click(makeTabCallback("#channels", "#channelspane")); +$("#channels").click(function () { + if(!loggedin) { + var error = $("
    ").addClass("alert alert-error") + .text("You must be logged in to view this page") + .insertBefore($("#channellist")); + $("