mirror of https://github.com/calzoneman/sync.git
finish refactoring acp (kind of -- depends on auth
This commit is contained in:
parent
6d84222871
commit
c4d5b1cd1d
66
acp.js
66
acp.js
|
@ -70,30 +70,23 @@ module.exports = function (Server) {
|
|||
user.socket.on("acp-reset-password", function(data) {
|
||||
if(Auth.getGlobalRank(data.name) >= user.global_rank)
|
||||
return;
|
||||
try {
|
||||
var hash = Server.db.generatePasswordReset(user.ip, data.name, data.email);
|
||||
ActionLog.record(user.ip, user.name, "acp-reset-password", data.name);
|
||||
}
|
||||
catch(e) {
|
||||
user.socket.emit("acp-reset-password", {
|
||||
success: false,
|
||||
error: e
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(hash) {
|
||||
user.socket.emit("acp-reset-password", {
|
||||
success: true,
|
||||
hash: hash
|
||||
});
|
||||
}
|
||||
else {
|
||||
user.socket.emit("acp-reset-password", {
|
||||
success: false,
|
||||
error: "Reset failed"
|
||||
});
|
||||
|
||||
db.genPasswordReset(user.ip, data.name, data.email,
|
||||
function (err, hash) {
|
||||
var pkt = {
|
||||
success: !err
|
||||
};
|
||||
|
||||
if(err) {
|
||||
pkt.error = err;
|
||||
} else {
|
||||
pkt.hash = hash;
|
||||
}
|
||||
|
||||
user.socket.emit("acp-reset-password", pkt);
|
||||
ActionLog.record(user.ip, user.name,
|
||||
"acp-reset-password", data.name);
|
||||
});
|
||||
});
|
||||
|
||||
user.socket.on("acp-set-rank", function(data) {
|
||||
|
@ -103,22 +96,14 @@ module.exports = function (Server) {
|
|||
if(Auth.getGlobalRank(data.name) >= user.global_rank)
|
||||
return;
|
||||
|
||||
var db = Server.db.getConnection();
|
||||
if(!db)
|
||||
return;
|
||||
|
||||
ActionLog.record(user.ip, user.name, "acp-set-rank", data);
|
||||
var query = Server.db.createQuery(
|
||||
"UPDATE registrations SET global_rank=? WHERE uname=?",
|
||||
[data.rank, data.name]
|
||||
);
|
||||
|
||||
var res = db.querySync(query);
|
||||
if(!res)
|
||||
return;
|
||||
db.setGlobalRank(data.name, data.rank, function (err, res) {
|
||||
|
||||
ActionLog.record(user.ip, user.name, "acp-set-rank",
|
||||
data);
|
||||
if(!err)
|
||||
user.socket.emit("acp-set-rank", data);
|
||||
});
|
||||
});
|
||||
|
||||
user.socket.on("acp-list-loaded", function() {
|
||||
var chans = [];
|
||||
|
@ -174,13 +159,10 @@ module.exports = function (Server) {
|
|||
});
|
||||
|
||||
user.socket.on("acp-view-stats", function () {
|
||||
var db = Server.db.getConnection();
|
||||
if(!db)
|
||||
return;
|
||||
var query = "SELECT * FROM stats ORDER BY time ASC";
|
||||
var results = db.querySync(query);
|
||||
if(results)
|
||||
user.socket.emit("acp-view-stats", results.fetchAllSync());
|
||||
db.listStats(function (err, res) {
|
||||
if(!err)
|
||||
user.socket.emit("acp-view-stats", res);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
25
database.js
25
database.js
|
@ -38,6 +38,9 @@ Database.prototype.query = function (query, sub, callback) {
|
|||
sub = false;
|
||||
}
|
||||
|
||||
if(typeof callback !== "function")
|
||||
callback = blackHole;
|
||||
|
||||
var self = this;
|
||||
self.pool.getConnection(function (err, conn) {
|
||||
if(err) {
|
||||
|
@ -667,6 +670,17 @@ Database.prototype.searchUser = function (name, callback) {
|
|||
self.query(query, [name], callback);
|
||||
};
|
||||
|
||||
/* rank */
|
||||
|
||||
Database.prototype.setGlobalRank = function (name, rank, callback) {
|
||||
var self = this;
|
||||
if(typeof callback !== "function")
|
||||
callback = blackHole;
|
||||
|
||||
var query = "UPDATE registrations SET global_rank=? WHERE uname=?";
|
||||
self.query(query, [rank, name], callback);
|
||||
};
|
||||
|
||||
/* email and profile */
|
||||
|
||||
Database.prototype.getUserProfile = function (name, callback) {
|
||||
|
@ -983,4 +997,15 @@ Database.prototype.listIPsForName = function (name, callback) {
|
|||
};
|
||||
|
||||
/* END REGION */
|
||||
|
||||
/* REGION stats */
|
||||
|
||||
Database.prototype.listStats = function (callback) {
|
||||
var self = this;
|
||||
if(typeof callback !== "function")
|
||||
return;
|
||||
|
||||
var query = "SELECT * FROM stats ORDER BY time ASC";
|
||||
self.query(query, callback);
|
||||
};
|
||||
module.exports = Database;
|
||||
|
|
Loading…
Reference in New Issue