Fix profile/rank for bot logins

This commit is contained in:
Calvin Montgomery 2016-10-06 23:01:42 -07:00
parent 99760b6989
commit ad4ee4bd02
3 changed files with 21 additions and 11 deletions

View file

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.23.0", "version": "3.23.1",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View file

@ -334,6 +334,12 @@ Channel.prototype.joinUser = function (user, data) {
if (!error) { if (!error) {
user.setChannelRank(rank); user.setChannelRank(rank);
user.setFlag(Flags.U_HAS_CHANNEL_RANK); user.setFlag(Flags.U_HAS_CHANNEL_RANK);
if (user.inChannel()) {
self.broadcastAll("setUserRank", {
name: user.getName(),
rank: rank
});
}
} }
}); });
}); });

View file

@ -16,6 +16,17 @@ function wildcardSimilarChars(name) {
return name.replace(/_/g, "\\_").replace(/[Il1oO0]/g, "_"); return name.replace(/_/g, "\\_").replace(/[Il1oO0]/g, "_");
} }
function parseProfile(data) {
try {
var profile = JSON.parse(data.profile);
profile.image = profile.image || "";
profile.text = profile.text || "";
data.profile = profile;
} catch (error) {
data.profile = { image: "", text: "" };
}
}
module.exports = { module.exports = {
init: function () { init: function () {
}, },
@ -83,15 +94,7 @@ module.exports = {
return callback("User does not exist"); return callback("User does not exist");
} }
try { parseProfile(rows[0]);
var profile = JSON.parse(rows[0].profile);
profile.image = profile.image || "";
profile.text = profile.text || "";
rows[0].profile = profile;
} catch (error) {
rows[0].profile = { image: "", text: "" };
}
callback(null, rows[0]); callback(null, rows[0]);
}); });
}, },
@ -216,7 +219,7 @@ module.exports = {
the hashes match. the hashes match.
*/ */
db.query("SELECT name,password,global_rank,time FROM `users` WHERE name=?", db.query("SELECT * FROM `users` WHERE name=?",
[name], [name],
function (err, rows) { function (err, rows) {
if (err) { if (err) {
@ -235,6 +238,7 @@ module.exports = {
} else if (!match) { } else if (!match) {
callback("Invalid username/password combination", null); callback("Invalid username/password combination", null);
} else { } else {
parseProfile(rows[0]);
callback(null, rows[0]); callback(null, rows[0]);
} }
}); });