Finish users interface on ACP

This commit is contained in:
calzoneman 2014-02-04 22:39:13 -06:00
parent 7b9162f890
commit bde57973c3
3 changed files with 136 additions and 7 deletions

View File

@ -12,6 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var Logger = require("./logger"); var Logger = require("./logger");
var Server = require("./server"); var Server = require("./server");
var db = require("./database"); var db = require("./database");
var util = require("./utilities");
var Config = require("./config");
function handleAnnounce(user, data) { function handleAnnounce(user, data) {
var sv = Server.getServer(); var sv = Server.getServer();
@ -105,11 +107,85 @@ function handleListUsers(user, data) {
} }
function handleSetRank(user, data) { function handleSetRank(user, data) {
var name = data.name;
var rank = data.rank;
if (typeof name !== "string" || typeof rank !== "number") {
return;
}
if (rank >= user.global_rank) {
user.socket.emit("errMessage", {
msg: "You are not permitted to promote others to equal or higher rank than " +
"yourself."
});
return;
}
db.users.getGlobalRank(name, function (err, oldrank) {
if (err) {
user.socket.emit("errMessage", {
msg: err
});
return;
}
if (oldrank >= user.global_rank) {
user.socket.emit("errMessage", {
msg: "You are not permitted to change the rank of users who rank " +
"higher than you."
});
return;
}
db.users.setGlobalRank(name, rank, function (err) {
if (err) {
user.socket.emit("errMessage", {
msg: err
});
} else {
user.socket.emit("acp-set-rank", data);
}
});
});
} }
function handleResetPassword(user, data) { function handleResetPassword(user, data) {
var name = data.name;
var email = data.email;
if (typeof name !== "string" || typeof email !== "string") {
return;
}
db.users.getGlobalRank(name, function (err, rank) {
if (rank >= user.global_rank) {
user.socket.emit("errMessage", {
msg: "You don't have permission to reset the password for " + name
});
return;
}
var hash = util.sha1(util.randomSalt(64));
var expire = Date.now() + 86400000;
db.addPasswordReset({
ip: "",
name: name,
email: email,
hash: hash,
expire: expire
}, function (err) {
if (err) {
user.socket.emit("errMessage", {
msg: err
});
return;
}
user.socket.emit("errMessage", {
msg: "Reset link: " + Config.get("http.domain") +
"/account/passwordrecover/" + hash
});
});
});
} }
function init(user) { function init(user) {

View File

@ -76,10 +76,10 @@ html(lang="en")
table.table.table-bordered.table-striped(style="margin-top: 20px") table.table.table-bordered.table-striped(style="margin-top: 20px")
thead thead
tr tr
th#acp-users-id ID th.sort(data-key="id") ID
th#acp-users-name Name th.sort(data-key="name") Name
th#acp-users-rank Rank th.sort(data-key="global_rank") Rank
th#acp-users-email Email th.sort(data-key="email") Email
th Actions th Actions
#acp-channel-lookup.acp-panel.col-md-12(style="display: none") #acp-channel-lookup.acp-panel.col-md-12(style="display: none")
h3 Channels h3 Channels

View File

@ -161,7 +161,7 @@ socket.on("acp-list-users", function (users) {
generator: function (u, page, index) { generator: function (u, page, index) {
var tr = $("<tr/>").appendTo(tbl); var tr = $("<tr/>").appendTo(tbl);
tr.attr("title", u.name + " joined on " + new Date(u.time) + " from " + u.ip); tr.attr("title", u.name + " joined on " + new Date(u.time) + " from IP " + u.ip);
$("<td/>").text(u.id).appendTo(tr); $("<td/>").text(u.id).appendTo(tr);
$("<td/>").text(u.name).appendTo(tr); $("<td/>").text(u.name).appendTo(tr);
var rank = $("<td/>").text(u.global_rank).appendTo(tr); var rank = $("<td/>").text(u.global_rank).appendTo(tr);
@ -195,9 +195,10 @@ socket.on("acp-list-users", function (users) {
} }
socket.emit("acp-set-rank", { socket.emit("acp-set-rank", {
name: u.uname, name: u.name,
rank: parseInt(newrank) rank: parseInt(newrank)
}); });
}; };
editor.blur(save); editor.blur(save);
@ -216,7 +217,7 @@ socket.on("acp-list-users", function (users) {
return; return;
} }
socket.emit("acp-reset-password", { socket.emit("acp-reset-password", {
name: u.uname, name: u.name,
email: u.email email: u.email
}); });
}).appendTo(reset); }).appendTo(reset);
@ -224,6 +225,58 @@ socket.on("acp-list-users", function (users) {
}; };
p = Paginate(users, opts); p = Paginate(users, opts);
p.paginator.css("margin-top", "20px");
p.paginator.insertBefore(tbl); p.paginator.insertBefore(tbl);
tbl.data("paginator", p); tbl.data("paginator", p);
}); });
socket.on("acp-set-rank", function (data) {
var table = $("#acp-user-lookup table");
var p = table.data("paginator");
var e = table.data("entries");
if (e) {
for (var i = 0; i < e.length; i++) {
if (e[i].name === data.name) {
e[i].rank = data.rank;
break;
}
}
if (p) {
p.items = e;
}
}
table.find("td:contains('" + data.name + "')")
.parent()
.children()[2]
.innerHTML = data.rank;
});
/* Initialize keyed table sorts */
$("table").each(function () {
var table = $(this);
var sortable = table.find("th.sort");
sortable.each(function () {
var th = $(this);
th.click(function () {
var p = table.data("paginator");
if (!p) {
return;
}
var key = th.attr("data-key");
if (!key) {
return;
}
var asc = -1*(table.data("ascending") || -1);
table.data("ascending", asc);
var entries = table.data("entries") || [];
entries.sort(function (a, b) {
return a[key] === b[key] ? 0 : asc*(a[key] > b[key] ? 1 : -1);
});
table.data("entries", entries);
p.items = entries;
p.loadPage(0);
});
});
});