Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
let app = {
id: this.appId,
hash: this.hash,
version: this.version,
langCode: DEFAULT_LANGUAGE_CODE,
deviceModel: '(n/a)',
systemVersion: '(n/a)',
authKey: this.authKey
};
this.client = tg.createClient(app, this.dataCenter, (e) => {
if (e) {
return reject(e);
}
if (this.client.isReady()) {
// Nothing else to do.
return resolve();
}
// Create MTProto auth key before resolving.
this.client.createAuthKey((authKey) => {
this.authKey = authKey;
resolve();
});
});
});
offset: req.query.offset || undefined,
limit: req.query.limit || 100,
sort: {
updatedAt: -1
}
};
if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
//non root user limitations
select.deleted = -1;
select.loginCounter = -1;
select.settings = -1;
select.beerCounter = -1;
select.lastLogin = -1;
select.lastIp = -1;
select["telegram.id"] = -1;
select["telegram.enabled"] = 1;
select["telegram.username"] = -1;
select["telegram.first_name"] = -1;
select["telegram.last_name"] = -1;
select["telegram.language_code"] = -1;
query.deleted = false;
}
if (!id) {
DB.User.find(query, select, options, (err, users) => {
if (err) {
console.error(err);
return res.sendStatus(500);
}
res.send(users);
});
} else {
query._id = id;
DB.User.findOneAndUpdate(query, data, options, (err, user) => {
if (err) {
console.error(err);
return res.sendStatus(500);
} else if (!user) {
return res.sendStatus(404);
}
if (!user.telegram.enabled && data.$set && data.$set["telegram.enabled"] == true && data.sendNotification) {
botNotifications.accountEnabledDisabled(user, true);
bot.broadcastMessage("User *" + user.email + "* enabled by *" + req.user.email + "*", accessLevels.admin, null, true);
} else if (user.telegram.enabled && data.$set && data.$set["telegram.enabled"] == false && data.sendNotification) {
botNotifications.accountEnabledDisabled(user, false);
bot.broadcastMessage("User *" + user.email + "* disabled by *" + req.user.email + "*", accessLevels.admin, null, true);
}
res.sendStatus(200);
});
sort: {
updatedAt: -1
}
};
if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
//non root user limitations
select.deleted = -1;
select.loginCounter = -1;
select.settings = -1;
select.beerCounter = -1;
select.lastLogin = -1;
select.lastIp = -1;
select["telegram.id"] = -1;
select["telegram.enabled"] = 1;
select["telegram.username"] = -1;
select["telegram.first_name"] = -1;
select["telegram.last_name"] = -1;
select["telegram.language_code"] = -1;
query.deleted = false;
}
if (!id) {
DB.User.find(query, select, options, (err, users) => {
if (err) {
console.error(err);
return res.sendStatus(500);
}
res.send(users);
});
} else {
query._id = id;
DB.User.findOne(query, select, (err, user) => {
if (err) {
options = {
offset: req.query.offset || undefined,
limit: req.query.limit || 100,
sort: {
updatedAt: -1
}
};
if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
//non root user limitations
select.deleted = -1;
select.loginCounter = -1;
select.settings = -1;
select.beerCounter = -1;
select.lastLogin = -1;
select.lastIp = -1;
select["telegram.id"] = -1;
select["telegram.enabled"] = 1;
select["telegram.username"] = -1;
select["telegram.first_name"] = -1;
select["telegram.last_name"] = -1;
select["telegram.language_code"] = -1;
query.deleted = false;
}
if (!id) {
DB.User.find(query, select, options, (err, users) => {
if (err) {
console.error(err);
return res.sendStatus(500);
}
res.send(users);
});
} else {
}
};
if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
//non root user limitations
select.deleted = -1;
select.loginCounter = -1;
select.settings = -1;
select.beerCounter = -1;
select.lastLogin = -1;
select.lastIp = -1;
select["telegram.id"] = -1;
select["telegram.enabled"] = 1;
select["telegram.username"] = -1;
select["telegram.first_name"] = -1;
select["telegram.last_name"] = -1;
select["telegram.language_code"] = -1;
query.deleted = false;
}
if (!id) {
DB.User.find(query, select, options, (err, users) => {
if (err) {
console.error(err);
return res.sendStatus(500);
}
res.send(users);
});
} else {
query._id = id;
DB.User.findOne(query, select, (err, user) => {
if (err) {
console.error(err);
return res.sendStatus(500);
updatedAt: -1
}
};
if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
//non root user limitations
select.deleted = -1;
select.loginCounter = -1;
select.settings = -1;
select.beerCounter = -1;
select.lastLogin = -1;
select.lastIp = -1;
select["telegram.id"] = -1;
select["telegram.enabled"] = 1;
select["telegram.username"] = -1;
select["telegram.first_name"] = -1;
select["telegram.last_name"] = -1;
select["telegram.language_code"] = -1;
query.deleted = false;
}
if (!id) {
DB.User.find(query, select, options, (err, users) => {
if (err) {
console.error(err);
return res.sendStatus(500);
}
res.send(users);
});
} else {
query._id = id;
DB.User.findOne(query, select, (err, user) => {
if (err) {
console.error(err);
constructor(appId, hash, version, dataCenter, encryptedAuthKey) {
this.appId = appId;
this.hash = hash;
this.version = version;
if (dataCenter) {
let dcPieces = dataCenter.split(':');
this.dataCenter = {
host: dcPieces[0],
port: dcPieces.length > 1 ? dcPieces[1] : DEFAULT_DATACENTER_PORT
};
} else {
this.dataCenter = tg.PROD_PRIMARY_DC;
}
if (encryptedAuthKey) {
this.authKey = tg.retrieveAuthKey(new Buffer(encryptedAuthKey, 'hex'), hash);
}
}
this.appId = appId;
this.hash = hash;
this.version = version;
if (dataCenter) {
let dcPieces = dataCenter.split(':');
this.dataCenter = {
host: dcPieces[0],
port: dcPieces.length > 1 ? dcPieces[1] : DEFAULT_DATACENTER_PORT
};
} else {
this.dataCenter = tg.PROD_PRIMARY_DC;
}
if (encryptedAuthKey) {
this.authKey = tg.retrieveAuthKey(new Buffer(encryptedAuthKey, 'hex'), hash);
}
}
limit: req.query.limit || 100,
sort: {
updatedAt: -1
}
};
if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
//non root user limitations
select.deleted = -1;
select.loginCounter = -1;
select.settings = -1;
select.beerCounter = -1;
select.lastLogin = -1;
select.lastIp = -1;
select["telegram.id"] = -1;
select["telegram.enabled"] = 1;
select["telegram.username"] = -1;
select["telegram.first_name"] = -1;
select["telegram.last_name"] = -1;
select["telegram.language_code"] = -1;
query.deleted = false;
}
if (!id) {
DB.User.find(query, select, options, (err, users) => {
if (err) {
console.error(err);
return res.sendStatus(500);
}
res.send(users);
});
} else {
query._id = id;
DB.User.findOne(query, select, (err, user) => {