Fixed MySQL User loading

This commit is contained in:
Soner Sayakci 2016-08-16 23:45:25 +02:00
parent fdc2318023
commit 28805445c9
No known key found for this signature in database
GPG Key ID: 9BA8CD75FEAAC81D
3 changed files with 12 additions and 3 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea
node_modules/

View File

@ -101,8 +101,11 @@ export function createTable(name) {
export function getUserByEmail(email) {
return new Promise((resolve) => {
this.db.instance.query(`SELECT * FROM ${CFG.SERVER_MYSQL_TABLE} WHERE email=? LIMIT 1`, [email], (e, rows, fields) => {
if (e) console.log(e);
else resolve(rows);
if (e) {
console.log(e);
} else {
resolve(rows[0]);
}
});
});
}

View File

@ -77,7 +77,11 @@ class Player {
updateByObject(obj) {
for (let key in obj) {
if (this.hasOwnProperty(key)) {
this[key] = obj[key];
if (key == 'send_marketing_emails' || key == 'send_push_notifications') {
this[key] = !!obj[key];
} else {
this[key] = obj[key];
}
}
};
}
@ -283,6 +287,7 @@ export function loginPlayer() {
return new Promise((resolve) => {
this.getUserByEmail(player.email).then((doc) => {
console.log(doc);
player.updateByObject(doc);
buffer = GetPlayer(player).encode();
resolve(buffer);