Add 'My Channels' to prevent silly people from forgetting which rooms they own

This commit is contained in:
calzoneman 2013-08-06 11:20:15 -04:00
parent 6d37c63a3d
commit b53ac91a61
4 changed files with 82 additions and 3 deletions

26
api.js
View File

@ -356,9 +356,6 @@ module.exports = function (Server) {
var session = params.session || ""; var session = params.session || "";
var img = params.profile_image || ""; var img = params.profile_image || "";
var text = params.profile_text || ""; var text = params.profile_text || "";
console.log(name);
console.log(img);
console.log(text);
var row = Auth.login(name, pw, session); var row = Auth.login(name, pw, session);
if(!row) { 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) { handleAdmReports: function (params, req, res) {
this.sendJSON(res, { this.sendJSON(res, {
error: "Not implemented" error: "Not implemented"
@ -590,6 +609,7 @@ module.exports = function (Server) {
"recoverpw" : api.handlePasswordRecover.bind(api), "recoverpw" : api.handlePasswordRecover.bind(api),
"setprofile" : api.handleProfileChange.bind(api), "setprofile" : api.handleProfileChange.bind(api),
"getprofile" : api.handleProfileGet.bind(api), "getprofile" : api.handleProfileGet.bind(api),
"listuserchannels": api.handleListUserChannels.bind(api),
"setemail" : api.handleEmailChange.bind(api), "setemail" : api.handleEmailChange.bind(api),
"admreports" : api.handleAdmReports.bind(api), "admreports" : api.handleAdmReports.bind(api),
"readactionlog" : api.handleReadActionLog.bind(api) "readactionlog" : api.handleReadActionLog.bind(api)

View File

@ -943,6 +943,26 @@ function deleteUserPlaylist(user, name) {
return results; 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 */ /* User Aliases */
function recordVisit(ip, name) { function recordVisit(ip, name) {
@ -1058,6 +1078,7 @@ exports.getUserPlaylists = getUserPlaylists;
exports.loadUserPlaylist = loadUserPlaylist; exports.loadUserPlaylist = loadUserPlaylist;
exports.saveUserPlaylist = saveUserPlaylist; exports.saveUserPlaylist = saveUserPlaylist;
exports.deleteUserPlaylist = deleteUserPlaylist; exports.deleteUserPlaylist = deleteUserPlaylist;
exports.listUserChannels = listUserChannels;
exports.recordVisit = recordVisit; exports.recordVisit = recordVisit;
exports.getAliases = getAliases; exports.getAliases = getAliases;
exports.ipForName = ipForName; exports.ipForName = ipForName;

View File

@ -47,6 +47,7 @@
<li><a href="javascript:void(0)" id="pwreset">Reset Password</a></li> <li><a href="javascript:void(0)" id="pwreset">Reset Password</a></li>
<li><a href="javascript:void(0)" id="profile">Edit Profile</a></li> <li><a href="javascript:void(0)" id="profile">Edit Profile</a></li>
<li><a href="javascript:void(0)" id="email">Change Email</a></li> <li><a href="javascript:void(0)" id="email">Change Email</a></li>
<li><a href="javascript:void(0)" id="channels">My Channels</a></li>
</ul> </ul>
</div> </div>
<div class="span7"> <div class="span7">
@ -208,6 +209,16 @@
</div> </div>
</form> </form>
</div> </div>
<div class="span7" id="channelspane" style="display: none">
<h1>My Channels</h1>
<table id="channellist" class="table table-bordered">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
</table>
</div>
</div> </div>
</div> <!-- /container --> </div> <!-- /container -->
<div class="push"></div> <div class="push"></div>

View File

@ -70,6 +70,33 @@ $("#profile").click(function() {
}); });
} }
}); });
$("#channels").click(makeTabCallback("#channels", "#channelspane"));
$("#channels").click(function () {
if(!loggedin) {
var error = $("<div/>").addClass("alert alert-error")
.text("You must be logged in to view this page")
.insertBefore($("#channellist"));
$("<button/>").addClass("close pull-right").click(function () {
error.remove();
}).html("&times;").prependTo(error);
return;
}
$.getJSON(api + "listuserchannels?name=" + encodeURIComponent(uname) +
"&session=" + session + "&callback=?", function(data) {
$("#channellist tbody").remove();
data.channels.forEach(function (chan) {
var tr = $("<tr/>").appendTo($("#channellist"));
var td = $("<td/>").appendTo(tr);
$("<a/>").attr("href", "./r/" + chan.name)
.attr("target", "_blank")
.text(chan.name)
.appendTo(td);
});
});
});
$("#registerbtn").click(function() { $("#registerbtn").click(function() {
$("#registerpane").find(".alert-error").remove(); $("#registerpane").find(".alert-error").remove();