mirror of https://github.com/calzoneman/sync.git
Finish users interface on ACP
This commit is contained in:
parent
7b9162f890
commit
bde57973c3
76
lib/acp.js
76
lib/acp.js
|
@ -12,6 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
var Logger = require("./logger");
|
||||
var Server = require("./server");
|
||||
var db = require("./database");
|
||||
var util = require("./utilities");
|
||||
var Config = require("./config");
|
||||
|
||||
function handleAnnounce(user, data) {
|
||||
var sv = Server.getServer();
|
||||
|
@ -105,11 +107,85 @@ function handleListUsers(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) {
|
||||
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) {
|
||||
|
|
|
@ -76,10 +76,10 @@ html(lang="en")
|
|||
table.table.table-bordered.table-striped(style="margin-top: 20px")
|
||||
thead
|
||||
tr
|
||||
th#acp-users-id ID
|
||||
th#acp-users-name Name
|
||||
th#acp-users-rank Rank
|
||||
th#acp-users-email Email
|
||||
th.sort(data-key="id") ID
|
||||
th.sort(data-key="name") Name
|
||||
th.sort(data-key="global_rank") Rank
|
||||
th.sort(data-key="email") Email
|
||||
th Actions
|
||||
#acp-channel-lookup.acp-panel.col-md-12(style="display: none")
|
||||
h3 Channels
|
||||
|
|
|
@ -161,7 +161,7 @@ socket.on("acp-list-users", function (users) {
|
|||
|
||||
generator: function (u, page, index) {
|
||||
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.name).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", {
|
||||
name: u.uname,
|
||||
name: u.name,
|
||||
rank: parseInt(newrank)
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
editor.blur(save);
|
||||
|
@ -216,7 +217,7 @@ socket.on("acp-list-users", function (users) {
|
|||
return;
|
||||
}
|
||||
socket.emit("acp-reset-password", {
|
||||
name: u.uname,
|
||||
name: u.name,
|
||||
email: u.email
|
||||
});
|
||||
}).appendTo(reset);
|
||||
|
@ -224,6 +225,58 @@ socket.on("acp-list-users", function (users) {
|
|||
};
|
||||
|
||||
p = Paginate(users, opts);
|
||||
p.paginator.css("margin-top", "20px");
|
||||
p.paginator.insertBefore(tbl);
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue