New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

larvituser

Package Overview
Dependencies
Maintainers
3
Versions
265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

larvituser - npm Package Compare versions

Comparing version 0.8.7 to 0.9.0

36

controllers/adminUsers/edit.js

@@ -6,3 +6,3 @@ 'use strict';

exports.run = function(req, res, cb) {
exports.run = function (req, res, cb) {
const tasks = [],

@@ -52,4 +52,4 @@ data = {'global': res.globalData};

// Check so username is not taken
tasks.push(function(cb) {
userLib.usernameAvailable(data.global.formFields.username.trim(), function(err, result) {
tasks.push(function (cb) {
userLib.usernameAvailable(data.global.formFields.username.trim(), function (err, result) {
if (err) { cb(err); return; }

@@ -68,6 +68,6 @@

// Create the user
tasks.push(function(cb) {
tasks.push(function (cb) {
if (data.global.errors.length) { return cb(); }
userLib.create(data.global.formFields.username, newPassword, userFields, function(err, result) {
userLib.create(data.global.formFields.username, newPassword, userFields, function (err, result) {
user = result;

@@ -78,4 +78,4 @@ cb(err);

} else {
tasks.push(function(cb) {
userLib.fromUuid(data.global.urlParsed.query.uuid, function(err, result) {
tasks.push(function (cb) {
userLib.fromUuid(data.global.urlParsed.query.uuid, function (err, result) {
user = result;

@@ -88,3 +88,3 @@ cb(err);

// Update username
tasks.push(function(cb) {
tasks.push(function (cb) {
if ( ! user) {

@@ -99,3 +99,3 @@ throw new Error('Ingen user?!??!');

userLib.usernameAvailable(data.global.formFields.username.trim(), function(err, result) {
userLib.usernameAvailable(data.global.formFields.username.trim(), function (err, result) {
if (err) { cb(err); return; }

@@ -111,3 +111,3 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
if (data.global.formFields.username.trim() === user.username) {

@@ -125,3 +125,3 @@ cb();

if (data.global.formFields.password.trim() !== '' || newPassword === false) {
tasks.push(function(cb) {
tasks.push(function (cb) {
if (data.global.errors.length) { return cb(); }

@@ -134,3 +134,3 @@

// Replace user fields
tasks.push(function(cb) {
tasks.push(function (cb) {
if (data.global.errors.length) { return cb(); }

@@ -141,3 +141,3 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
if (data.global.errors.length) { return cb(); }

@@ -154,4 +154,4 @@

if (data.global.formFields.rmUser !== undefined) {
tasks.push(function(cb) {
userLib.rmUser(data.global.urlParsed.query.uuid, function(err) {
tasks.push(function (cb) {
userLib.rmUser(data.global.urlParsed.query.uuid, function (err) {
if (err) { cb(err); return; }

@@ -168,4 +168,4 @@

if (data.global.urlParsed.query.uuid !== undefined) {
tasks.push(function(cb) {
userLib.fromUuid(data.global.urlParsed.query.uuid, function(err, user) {
tasks.push(function (cb) {
userLib.fromUuid(data.global.urlParsed.query.uuid, function (err, user) {
if (err) { cb(err); return; }

@@ -185,3 +185,3 @@

async.series(tasks, function(err) {
async.series(tasks, function (err) {
if (err && ! data.global.errors) {

@@ -188,0 +188,0 @@ cb(err, req, res, data);

@@ -6,3 +6,3 @@ 'use strict';

exports.run = function(req, res, cb) {
exports.run = function (req, res, cb) {
const tasks = [],

@@ -23,3 +23,3 @@ data = {'global': res.globalData};

tasks.push(function(cb) {
tasks.push(function (cb) {
const users = new userLib.Users();

@@ -39,3 +39,3 @@

users.get(function(err, result, totalElements) {
users.get(function (err, result, totalElements) {
data.users = result;

@@ -47,5 +47,5 @@ data.pagination.totalElements = totalElements;

async.series(tasks, function(err) {
async.series(tasks, function (err) {
cb(err, req, res, data);
});
};

@@ -5,4 +5,4 @@ 'use strict';

eventEmitter = new EventEmitter(),
dbmigration = require('larvitdbmigration')({'tableName': 'users_db_version', 'migrationScriptsPath': __dirname + '/dbmigration'}),
logPrefix = 'larvituser: ./dataWriter.js - ',
topLogPrefix = 'larvituser: ./dataWriter.js - ',
DbMigration = require('larvitdbmigration'),
helpers = require(__dirname + '/helpers.js'),

@@ -21,8 +21,9 @@ uuidLib = require('uuid'),

function addUserDataFields(params, deliveryTag, msgUuid, cb) {
const tasks = [],
const userUuidBuffer = lUtils.uuidToBuffer(params.userUuid),
logPrefix = topLogPrefix + 'addUserDataFields() - ',
dbValues = [],
userUuidBuffer = lUtils.uuidToBuffer(params.userUuid);
tasks = [];
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}

@@ -36,5 +37,4 @@

if (err) {
log.warn(logPrefix + 'addUserDataFields() - ' + err.message);
cb(err);
return;
log.warn(logPrefix + err.message);
return cb(err);
}

@@ -64,6 +64,5 @@

if (err) {
log.warn(logPrefix + 'addUserDataFields() - ' + err.message);
log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);
cb(err);
return;
return cb(err);
}

@@ -74,10 +73,9 @@

if (dbValues.length === 0) {
log.info(logPrefix + 'addUserDataFields() - ' + 'No fields or field data specifed');
log.info(logPrefix + 'No fields or field data specifed');
exports.emitter.emit(msgUuid);
cb();
return;
return cb();
}
db.query(sql, dbValues, function (err) {
if (err) { log.warn(logPrefix + ' addUserDataFields() - ' + err.message); }
if (err) { log.warn(topLogPrefix + ' addUserDataFields() - ' + err.message); }
exports.emitter.emit(msgUuid, err);

@@ -90,3 +88,4 @@ cb(err);

function addUserField(params, deliveryTag, msgUuid, cb) {
const uuid = params.uuid,
const logPrefix = topLogPrefix + 'addUserField() - ',
uuid = params.uuid,
name = params.name,

@@ -96,7 +95,7 @@ sql = 'INSERT IGNORE INTO user_data_fields (uuid, name) VALUES(?,?)';

if (typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}
db.query(sql, [lUtils.uuidToBuffer(uuid), name], function(err) {
if (err) log.warn(logPrefix + 'addUserField() - ' + err.message);
db.query(sql, [lUtils.uuidToBuffer(uuid), name], function (err) {
if (err) log.warn(logPrefix + err.message);

@@ -110,6 +109,7 @@ exports.emitter.emit(msgUuid, err);

function addUserFieldReq(params, deliveryTag, msgUuid, cb) {
const fieldName = params.name;
const logPrefix = topLogPrefix + 'addUserFieldReq() - ',
fieldName = params.name;
if (typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}

@@ -127,23 +127,23 @@

// Check if this is already set in the database
db.query('SELECT uuid FROM user_data_fields WHERE name = ?', [fieldName], function(err, rows) {
db.query('SELECT uuid FROM user_data_fields WHERE name = ?', [fieldName], function (err, rows) {
const options = {'exchange': exports.exchangeName},
sendObj = {};
if (err) { cb(err); return; }
if (err) return cb(err);
sendObj.action = 'addUserField';
sendObj.params = {};
sendObj.params.name = fieldName;
sendObj.params.name = fieldName;
sendObj.params.uuid = (rows.length) ? lUtils.formatUuid(rows[0].uuid) : uuidLib.v1();
exports.emitter.once('addedField_' + fieldName, function(err) {
if (err) { cb(err); return; }
exports.emitter.once('addedField_' + fieldName, function (err) {
if (err) return cb(err);
exports.addUserFieldReqRunning = false;
});
intercom.send(sendObj, options, function(err, msgUuid2) {
if (err) { cb(err); return; }
intercom.send(sendObj, options, function (err, msgUuid2) {
if (err) return cb(err);
exports.emitter.once(msgUuid2, function(err) {
if (err) { cb(err); return; }
exports.emitter.once(msgUuid2, function (err) {
if (err) return cb(err);

@@ -155,3 +155,2 @@ exports.emitter.emit(msgUuid, err);

});
});

@@ -161,3 +160,3 @@ }

} else {
log.debug(logPrefix + 'addUserFieldReq() - Ignoring since we are not master');
log.debug(logPrefix + 'Ignoring since we are not master');
}

@@ -167,7 +166,8 @@ }

function create(params, deliveryTag, msgUuid, cb) {
const dbFields = [],
const logPrefix = topLogPrefix + 'create() - ',
dbFields = [],
sql = 'INSERT IGNORE INTO user_users (uuid, username, password) VALUES(?,?,?);';
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}

@@ -182,10 +182,9 @@

log.warn(logPrefix + 'create() - ' + err.message);
log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);
cb(err);
return;
return cb(err);
}
db.query(sql, dbFields, function(err) {
if (err) log.warn(logPrefix + 'create() - ' + err.message);
db.query(sql, dbFields, function (err) {
if (err) log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);

@@ -197,3 +196,4 @@ cb(err);

function listenToQueue(retries, cb) {
const options = {'exchange': exports.exchangeName};
const logPrefix = topLogPrefix + 'listenToQueue() - ',
options = {'exchange': exports.exchangeName};

@@ -208,3 +208,3 @@ let listenMethod;

if (typeof cb !== 'function') {
cb = function(){};
cb = function (){};
}

@@ -226,3 +226,3 @@

const err = new Error('Invalid exports.mode. Must be either "master" or "slave"');
log.error(logPrefix + 'listenToQueue() - ' + err.message);
log.error(logPrefix + err.message);
cb(err);

@@ -236,3 +236,3 @@ return;

retries ++;
setTimeout(function() {
setTimeout(function () {
listenToQueue(retries, cb);

@@ -242,20 +242,20 @@ }, 50);

} else if ( ! (intercom instanceof require('larvitamintercom'))) {
log.error(logPrefix + 'listenToQueue() - Intercom is not set!');
log.error(logPrefix + 'Intercom is not set!');
return;
}
log.info(logPrefix + 'listenToQueue() - listenMethod: ' + listenMethod);
log.info(logPrefix + 'listenMethod: ' + listenMethod);
intercom.ready(function(err) {
intercom.ready(function (err) {
if (err) {
log.error(logPrefix + 'listenToQueue() - intercom.ready() err: ' + err.message);
log.error(logPrefix + 'intercom.ready() err: ' + err.message);
return;
}
intercom[listenMethod](options, function(message, ack, deliveryTag) {
exports.ready(function(err) {
intercom[listenMethod](options, function (message, ack, deliveryTag) {
exports.ready(function (err) {
ack(err); // Ack first, if something goes wrong we log it and handle it manually
if (err) {
log.error(logPrefix + 'listenToQueue() - intercom.' + listenMethod + '() - exports.ready() returned err: ' + err.message);
log.error(logPrefix + 'intercom.' + listenMethod + '() - exports.ready() returned err: ' + err.message);
return;

@@ -265,3 +265,3 @@ }

if (typeof message !== 'object') {
log.error(logPrefix + 'listenToQueue() - intercom.' + listenMethod + '() - Invalid message received, is not an object! deliveryTag: "' + deliveryTag + '"');
log.error(logPrefix + 'intercom.' + listenMethod + '() - Invalid message received, is not an object! deliveryTag: "' + deliveryTag + '"');
return;

@@ -273,3 +273,3 @@ }

} else {
log.warn(logPrefix + 'listenToQueue() - intercom.' + listenMethod + '() - Unknown message.action received: "' + message.action + '"');
log.warn(logPrefix + 'intercom.' + listenMethod + '() - Unknown message.action received: "' + message.action + '"');
}

@@ -285,3 +285,4 @@ });

function ready(retries, cb) {
const tasks = [];
const logPrefix = topLogPrefix + 'ready() - ',
tasks = [];

@@ -294,3 +295,3 @@ if (typeof retries === 'function') {

if (typeof cb !== 'function') {
cb = function(){};
cb = function (){};
}

@@ -302,3 +303,3 @@

if (isReady === true) { cb(); return; }
if (isReady === true) return cb();

@@ -314,3 +315,3 @@ if (readyInProgress === true) {

retries ++;
setTimeout(function() {
setTimeout(function () {
ready(retries, cb);

@@ -320,3 +321,3 @@ }, 50);

} else if ( ! (intercom instanceof require('larvitamintercom'))) {
log.error(logPrefix + 'ready() - Intercom is not set!');
log.error(logPrefix + 'Intercom is not set!');
return;

@@ -328,5 +329,5 @@ }

if (exports.mode === 'both' || exports.mode === 'slave') {
log.verbose(logPrefix + 'ready() - exports.mode: "' + exports.mode + '", so read');
log.verbose(logPrefix + 'exports.mode: "' + exports.mode + '", so read');
tasks.push(function(cb) {
tasks.push(function (cb) {
amsync.mariadb({'exchange': exports.exchangeName + '_dataDump'}, cb);

@@ -337,10 +338,22 @@ });

if (exports.mode === 'noSync') {
log.warn(logPrefix + 'ready() - exports.mode: "' + exports.mode + '", never run this mode in production!');
log.warn(logPrefix + 'exports.mode: "' + exports.mode + '", never run this mode in production!');
}
// Migrate database
tasks.push(function(cb) {
dbmigration(function(err) {
tasks.push(function (cb) {
const options = {};
let dbMigration;
log.debug(logPrefix + 'Waiting for dbmigration()');
options.dbType = 'larvitdb';
options.dbDriver = db;
options.tableName = 'users_db_version';
options.migrationScriptsPath = __dirname + '/dbmigration';
dbMigration = new DbMigration(options);
dbMigration.run(function (err) {
if (err) {
log.error(logPrefix + 'ready() - Database error: ' + err.message);
log.error(topLogPrefix + err.message);
}

@@ -352,3 +365,3 @@

async.series(tasks, function(err) {
async.series(tasks, function (err) {
if (err) {

@@ -373,6 +386,7 @@ return;

userUuidBuf = lUtils.uuidToBuffer(params.userUuid),
logPrefix = topLogPrefix + 'replaceFields() - ',
tasks = [];
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}

@@ -383,10 +397,9 @@

log.warn(logPrefix + 'replaceFields() - ' + err.message);
log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);
cb(err);
return;
return cb(err);
}
// Clean out previous data
tasks.push(function(cb) {
tasks.push(function (cb) {
db.query('DELETE FROM user_users_data WHERE userUuid = ?', [userUuidBuf], cb);

@@ -396,8 +409,8 @@ });

// Get field uuids
tasks.push(function(cb) {
tasks.push(function (cb) {
const tasks = [];
for (const fieldName of Object.keys(params.fields)) {
tasks.push(function(cb) {
helpers.getFieldUuid(fieldName, function(err, fieldUuid) {
tasks.push(function (cb) {
helpers.getFieldUuid(fieldName, function (err, fieldUuid) {
fieldNamesToUuidBufs[fieldName] = lUtils.uuidToBuffer(fieldUuid);

@@ -413,3 +426,3 @@ cb(err);

// Add new data
tasks.push(function(cb) {
tasks.push(function (cb) {
const dbFields = [];

@@ -419,6 +432,3 @@

if ( ! params.fields) {
cb();
return;
}
if ( ! params.fields) return cb();

@@ -442,6 +452,3 @@ for (const fieldName of Object.keys(params.fields)) {

if (dbFields.length === 0) {
cb();
return;
}
if (dbFields.length === 0) return cb();

@@ -451,4 +458,4 @@ db.query(sql, dbFields, cb);

async.series(tasks, function(err) {
if (err) log.warn(logPrefix + 'replaceFields() - ' + err.message);
async.series(tasks, function (err) {
if (err) log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);

@@ -460,9 +467,10 @@ cb(err);

function rmUser(params, deliveryTag, msgUuid, cb) {
const tasks = [];
const logPrefix = topLogPrefix + 'rmUser() - ',
tasks = [];
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}
tasks.push(function(cb) {
tasks.push(function (cb) {
const sql = 'DELETE FROM user_users_data WHERE userUuid = ?;';

@@ -473,3 +481,3 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
const sql = 'DELETE FROM user_users WHERE uuid = ?;';

@@ -480,4 +488,4 @@

async.series(tasks, function(err) {
if (err) log.warn(logPrefix + 'rmUser() - ' + err.message);
async.series(tasks, function (err) {
if (err) log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);

@@ -489,7 +497,9 @@ cb(err);

function rmUserField(params, deliveryTag, msgUuid, cb) {
const logPrefix = topLogPrefix + 'rmUserField() - ';
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}
helpers.getFieldUuid(params.fieldName, function(err, fieldUuid) {
helpers.getFieldUuid(params.fieldName, function (err, fieldUuid) {
const dbFields = [lUtils.uuidToBuffer(params.userUuid), lUtils.uuidToBuffer(fieldUuid)],

@@ -503,4 +513,4 @@ sql = 'DELETE FROM user_users_data WHERE userUuid = ? AND fieldUuid = ?';

db.query(sql, dbFields, function(err) {
if (err) log.warn(logPrefix + 'rmUserField() - ' + err.message);
db.query(sql, dbFields, function (err) {
if (err) log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);

@@ -550,7 +560,8 @@ cb(err);

function setPassword(params, deliveryTag, msgUuid, cb) {
const dbFields = [],
const logPrefix = topLogPrefix + 'setPassword() - ',
dbFields = [],
sql = 'UPDATE user_users SET password = ? WHERE uuid = ?;';
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}

@@ -565,4 +576,4 @@

dbFields.push(lUtils.uuidToBuffer(params.userUuid));
db.query(sql, dbFields, function(err) {
if (err) log.warn(logPrefix + 'setPassword() - ' + err.message);
db.query(sql, dbFields, function (err) {
if (err) log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);

@@ -574,11 +585,12 @@ cb(err);

function setUsername(params, deliveryTag, msgUuid, cb) {
const dbFields = [params.username, lUtils.uuidToBuffer(params.userUuid)],
const logPrefix = topLogPrefix + 'setUsername() - ',
dbFields = [params.username, lUtils.uuidToBuffer(params.userUuid)],
sql = 'UPDATE user_users SET username = ? WHERE uuid = ?;';
if (cb === undefined || typeof cb !== 'function') {
cb = function() {};
cb = function () {};
}
db.query(sql, dbFields, function(err) {
if (err) log.warn(logPrefix + 'setUsername() - ' + err.message);
db.query(sql, dbFields, function (err) {
if (err) log.warn(logPrefix + err.message);
exports.emitter.emit(msgUuid, err);

@@ -585,0 +597,0 @@ cb(err);

@@ -7,3 +7,3 @@ 'use strict';

exports = module.exports = function(cb) {
exports = module.exports = function (cb) {
const tasks = [];

@@ -14,9 +14,9 @@

let username = 'fomme';
tasks.push(function(cb) {
tasks.push(function (cb) {
db.query('INSERT INTO user_data_fields (name) VALUES(\'foo\'),(\'bar\');', cb);
});
tasks.push(function(cb) {
tasks.push(function (cb) {
db.query('INSERT INTO user_users (uuid, username, password) VALUES(UNHEX(?),?,?);', [userUuid.replace(/-/g, ''), username, 'false'], cb);
});
tasks.push(function(cb) {
tasks.push(function (cb) {
const sql = 'INSERT INTO user_users_data (userUuid, fieldId, data) SELECT UNHEX(\'' + userUuid.replace(/-/g, '') + '\'), id, \'mepp\' FROM user_data_fields WHERE name = \'foo\';';

@@ -26,3 +26,3 @@

});
tasks.push(function(cb) {
tasks.push(function (cb) {
const sql = 'INSERT INTO user_users_data (userUuid, fieldId, data) SELECT UNHEX(\'' + userUuid.replace(/-/g, '') + '\'), id, \'waff\' FROM user_data_fields WHERE name = \'bar\';';

@@ -34,8 +34,8 @@

// Migrate stuff
tasks.push(function(cb) {
tasks.push(function (cb) {
db.query('ALTER TABLE `user_data_fields` ADD `uuid` binary(16) NOT NULL FIRST;', cb);
});
tasks.push(function(cb) {
db.query('SELECT id, name FROM user_data_fields', function(err, rows) {
tasks.push(function (cb) {
db.query('SELECT id, name FROM user_data_fields', function (err, rows) {
const tasks = [];

@@ -48,3 +48,3 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
db.query('UPDATE user_data_fields SET uuid = UNHEX(?) WHERE id = ?;', [uuidLib.v1().replace(/-/g, ''), row.id], cb);

@@ -58,12 +58,12 @@ });

tasks.push(function(cb) { db.query('ALTER TABLE `user_users_data` ADD `fieldUuid` binary(16) NOT NULL AFTER `userUuid`;', cb); });
tasks.push(function(cb) { db.query('UPDATE user_users_data uud SET fieldUuid = (SELECT uuid FROM user_data_fields WHERE id = uud.fieldId)', cb); });
tasks.push(function(cb) { db.query('ALTER TABLE `user_users_data` DROP FOREIGN KEY `user_users_data_ibfk_2`;', cb); });
tasks.push(function(cb) { db.query('ALTER TABLE `user_users_data` DROP `id`, DROP `fieldId`;', cb); });
tasks.push(function(cb) { db.query('ALTER TABLE `user_data_fields` DROP `id`;', cb); });
tasks.push(function(cb) { db.query('ALTER TABLE `user_data_fields` ADD PRIMARY KEY `uuid` (`uuid`);', cb); });
tasks.push(function(cb) { db.query('ALTER TABLE `user_users_data` ADD FOREIGN KEY (`fieldUuid`) REFERENCES `user_data_fields` (`uuid`) ON DELETE NO ACTION ON UPDATE NO ACTION;', cb); });
tasks.push(function(cb) { db.query('ALTER TABLE `user_users_data` DROP INDEX `userUuid_fieldId`;', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` ADD `fieldUuid` binary(16) NOT NULL AFTER `userUuid`;', cb); });
tasks.push(function (cb) { db.query('UPDATE user_users_data uud SET fieldUuid = (SELECT uuid FROM user_data_fields WHERE id = uud.fieldId)', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` DROP FOREIGN KEY `user_users_data_ibfk_2`;', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` DROP `id`, DROP `fieldId`;', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_data_fields` DROP `id`;', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_data_fields` ADD PRIMARY KEY `uuid` (`uuid`);', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` ADD FOREIGN KEY (`fieldUuid`) REFERENCES `user_data_fields` (`uuid`) ON DELETE NO ACTION ON UPDATE NO ACTION;', cb); });
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` DROP INDEX `userUuid_fieldId`;', cb); });
async.series(tasks, cb);
};
'use strict';
const EventEmitter = require('events').EventEmitter,
eventEmitter = new EventEmitter(),
dbmigration = require('larvitdbmigration')({'tableName': 'users_db_version', 'migrationScriptsPath': __dirname + '/dbmigration'}),
lUtils = require('larvitutils'),
log = require('winston'),
const lUtils = require('larvitutils'),
db = require('larvitdb');
let readyInProgress = false,
isReady = false,
dataWriter,
let dataWriter,
intercom;

@@ -22,7 +16,7 @@

function getFieldName(uuid, cb) {
ready(function() {
ready(function () {
const dbFields = [lUtils.uuidToBuffer(uuid)],
sql = 'SELECT name FROM user_data_fields WHERE uuid = ?';
db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -46,3 +40,3 @@

function getFieldUuid(fieldName, cb) {
ready(function() {
ready(function () {
const dbFields = [],

@@ -54,3 +48,3 @@ sql = 'SELECT uuid FROM user_data_fields WHERE name = ?';

db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -68,6 +62,6 @@

intercom.send(sendObj, options, function(err) {
intercom.send(sendObj, options, function (err) {
if (err) { cb(err); return; }
dataWriter.emitter.once('addedField_' + fieldName, function(err) {
dataWriter.emitter.once('addedField_' + fieldName, function (err) {
if (err) { cb(err); return; }

@@ -83,29 +77,8 @@ getFieldUuid(fieldName, cb);

function ready(cb) {
if (isReady === true) { cb(); return; }
if (readyInProgress === true) {
eventEmitter.on('ready', cb);
return;
}
readyInProgress = true;
intercom = lUtils.instances.intercom; // We must do this here since it might not be instanciated on module load
// We are strictly in need of the intercom!
if ( ! (intercom instanceof require('larvitamintercom'))) {
const err = new Error('larvitutils.instances.intercom is not an instance of Intercom!');
log.error('larvituser: helpers.js - ' + err.message);
throw err;
}
dataWriter = require(__dirname + '/dataWriter.js'); // We must do this here since it might not be instanciated on module load
dbmigration(function(err) {
if (err) {
log.error('larvituser: helpers.js: Database error: ' + err.message);
return;
}
dataWriter.ready(function (err) {
if (err) return cb(err);
isReady = true;
eventEmitter.emit('ready');
intercom = lUtils.instances.intercom; // We must do this here since it might not be instanciated on module load

@@ -112,0 +85,0 @@ cb();

@@ -35,3 +35,3 @@ 'use strict';

function addUserDataFields(userUuid, fields, cb) {
dataWriter.ready(function(err) {
dataWriter.ready(function (err) {
if (err) { cb(err); return; }

@@ -47,3 +47,3 @@

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -65,3 +65,3 @@

bcrypt.compare(password, hash, function(err, result) {
bcrypt.compare(password, hash, function (err, result) {
if (err) {

@@ -97,3 +97,3 @@ log.error('larvituser: checkPassword() - ' + err.message);

} else if (cb === undefined) {
cb = function() {};
cb = function () {};
}

@@ -117,4 +117,4 @@

// Check for username availability
tasks.push(function(cb) {
usernameAvailable(username, function(err, result) {
tasks.push(function (cb) {
usernameAvailable(username, function (err, result) {
if (err) { cb(err); return; }

@@ -135,3 +135,3 @@

// Hash Password
tasks.push(function(cb) {
tasks.push(function (cb) {
if (password === false) {

@@ -144,3 +144,3 @@ log.debug('larvituser: ./index.js - create() - Password set to empty string for no-login, username: "' + username + '"');

hashPassword(password, function(err, hash) {
hashPassword(password, function (err, hash) {
if (err) { cb(err); return; }

@@ -155,7 +155,7 @@

// Create all fields
tasks.push(function(cb) {
tasks.push(function (cb) {
const tasks = [];
for (const fieldName of Object.keys(userData)) {
tasks.push(function(cb) {
tasks.push(function (cb) {
exports.getFieldUuid(fieldName, cb);

@@ -169,3 +169,3 @@ });

// Write new user via queue
tasks.push(function(cb) {
tasks.push(function (cb) {
const options = {'exchange': dataWriter.exchangeName},

@@ -180,3 +180,3 @@ sendObj = {};

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -189,10 +189,10 @@

// Write fields via queue
tasks.push(function(cb) {
tasks.push(function (cb) {
addUserDataFields(uuid, userData, cb);
});
async.series(tasks, function(err) {
async.series(tasks, function (err) {
if (err) { cb(err); return; }
fromUuid(uuid, function(err, user) {
fromUuid(uuid, function (err, user) {
if (err) {

@@ -218,3 +218,3 @@ log.error('larvituser: ./index.js - create() - ' + err.message);

function fromField(fieldName, fieldValue, cb) {
dataWriter.ready(function(err) {
dataWriter.ready(function (err) {
const dbFields = [fieldName.trim(), fieldValue.trim()],

@@ -229,3 +229,3 @@ sql = 'SELECT uud.userUuid\n' +

db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -251,3 +251,3 @@

function fromFields(fields, cb) {
dataWriter.ready(function(err) {
dataWriter.ready(function (err) {
const dbFields = [];

@@ -266,3 +266,3 @@

sql += 'LIMIT 1';
db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -299,7 +299,7 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
const dbFields = [username],
sql = 'SELECT uuid, password FROM user_users WHERE username = ?';
db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -319,3 +319,3 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
if ( ! hashedPassword) {

@@ -326,3 +326,3 @@ cb();

checkPassword(password, hashedPassword, function(err, res) {
checkPassword(password, hashedPassword, function (err, res) {
if (err) {

@@ -340,3 +340,3 @@ log.error('larvituser: fromUserAndPass() - ' + err.message);

fromUuid(lUtils.formatUuid(userUuid), function(err, result) {
fromUuid(lUtils.formatUuid(userUuid), function (err, result) {
userObj = result;

@@ -349,3 +349,3 @@ if (err) userObj = false;

async.series(tasks, function(err) {
async.series(tasks, function (err) {
cb(err, userObj);

@@ -368,6 +368,6 @@ });

dataWriter.ready(function(err) {
dataWriter.ready(function (err) {
if (err) { cb(err); return; }
db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -411,6 +411,6 @@

dataWriter.ready(function(err) {
dataWriter.ready(function (err) {
if (err) { cb(err); return; }
db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -459,3 +459,3 @@

function getFieldData(userUuid, fieldName, cb) {
exports.getFieldUuid(fieldName, function(err, fieldUuid) {
exports.getFieldUuid(fieldName, function (err, fieldUuid) {
const dbFields = [lUtils.uuidToBuffer(userUuid), lUtils.uuidToBuffer(fieldUuid)],

@@ -466,3 +466,3 @@ sql = 'SELECT data FROM user_users_data WHERE userUuid = ? AND fieldUuid = ?';

db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
const data = [];

@@ -490,3 +490,3 @@

bcrypt.hash(password, 10, function(err, hash) {
bcrypt.hash(password, 10, function (err, hash) {
if (err) {

@@ -517,3 +517,3 @@ log.error('larvituser: hashPassword() - ' + err.message);

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -539,3 +539,3 @@

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -563,3 +563,3 @@

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -583,5 +583,5 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
if (newPassword) {
hashPassword(newPassword.trim(), function(err, hash) {
hashPassword(newPassword.trim(), function (err, hash) {
hashedPassword = hash;

@@ -596,3 +596,3 @@ cb(err);

tasks.push(function(cb) {
tasks.push(function (cb) {
const options = {'exchange': dataWriter.exchangeName},

@@ -606,3 +606,3 @@ sendObj = {};

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -636,3 +636,3 @@

db.query('SELECT uuid FROM user_users WHERE username = ? AND uuid != ?', [newUsername, userUuidBuf], function(err, rows) {
db.query('SELECT uuid FROM user_users WHERE username = ? AND uuid != ?', [newUsername, userUuidBuf], function (err, rows) {
const options = {'exchange': dataWriter.exchangeName},

@@ -654,3 +654,3 @@ sendObj = {};

dataWriter.intercom.send(sendObj, options, function(err, msgUuid) {
dataWriter.intercom.send(sendObj, options, function (err, msgUuid) {
if (err) { cb(err); return; }

@@ -680,3 +680,3 @@

addUserDataField(returnObj.uuid, name, value, function(err) {
addUserDataField(returnObj.uuid, name, value, function (err) {
if (err) { cb(err); return; }

@@ -706,3 +706,3 @@

addUserDataFields(returnObj.uuid, fields, function(err) {
addUserDataFields(returnObj.uuid, fields, function (err) {
if (err) { cb(err); return; }

@@ -738,7 +738,7 @@

replaceUserFields(returnObj.uuid, fields, function(err) {
replaceUserFields(returnObj.uuid, fields, function (err) {
if (err) { cb(err); return; }
// Reload everything
fromUuid(returnObj.uuid, function(err, user) {
fromUuid(returnObj.uuid, function (err, user) {
if (err) { cb(err); return; }

@@ -759,3 +759,3 @@

rmUser(returnObj.uuid, function(err) {
rmUser(returnObj.uuid, function (err) {
if (err) { cb(err); return; }

@@ -784,3 +784,3 @@

rmUserField(returnObj.uuid, name, function(err) {
rmUserField(returnObj.uuid, name, function (err) {
if (err) { cb(err); return; }

@@ -793,3 +793,3 @@

returnObj.setPassword = function(newPassword, cb) {
returnObj.setPassword = function (newPassword, cb) {
if (returnObj.uuid === undefined) {

@@ -804,3 +804,3 @@ const err = new Error('Cannot set password; no user loaded');

returnObj.setUsername = function(newUsername, cb) {
returnObj.setUsername = function (newUsername, cb) {
if (returnObj.uuid === undefined) {

@@ -833,4 +833,4 @@ const err = new Error('Cannot set username; no user loaded');

tasks.push(function(cb) {
db.query('SELECT uuid FROM user_users WHERE username = ?', [username], function(err, rows) {
tasks.push(function (cb) {
db.query('SELECT uuid FROM user_users WHERE username = ?', [username], function (err, rows) {
if (err) { cb(err); return; }

@@ -848,3 +848,3 @@

async.series(tasks, function(err) {
async.series(tasks, function (err) {
if (err) { cb(err); return; }

@@ -851,0 +851,0 @@

{
"name": "larvituser",
"version": "0.8.7",
"version": "0.9.0",
"author": {

@@ -16,3 +16,3 @@ "name": "Mikael 'Lilleman' Göransson",

"larvitdb": "^1.0.0",
"larvitdbmigration": "^1.3.3",
"larvitdbmigration": "^2.0.0",
"larvitutils": "^1.0.4",

@@ -19,0 +19,0 @@ "uuid": "^3.0.0",

@@ -29,3 +29,3 @@ [![Build Status](https://travis-ci.org/larvit/larvituser.svg?branch=master)](https://travis-ci.org/larvit/larvituser) [![Dependencies](https://david-dm.org/larvit/larvituser.svg)](https://david-dm.org/larvit/larvituser.svg)

userLib.create('myUsername', 'myPassword', userData, function(err, user) {
userLib.create('myUsername', 'myPassword', userData, function (err, user) {
console.log('New user UUID: ' + user.uuid);

@@ -38,3 +38,3 @@ });

```javascript
userLib.fromUserAndPass('myUsername', 'myPassword', function(err, user) {
userLib.fromUserAndPass('myUsername', 'myPassword', function (err, user) {
if (err) {

@@ -57,3 +57,3 @@ throw err;

users.get(function(err, userList) {
users.get(function (err, userList) {
if (err) throw err;

@@ -70,3 +70,3 @@

users.getFieldData('fieldName', function(err, result) {
users.getFieldData('fieldName', function (err, result) {
if (err) throw err;

@@ -83,3 +83,3 @@

```javascript
userLib.addUserDataField(userUuid, fieldName, fieldValue, function(err) {
userLib.addUserDataField(userUuid, fieldName, fieldValue, function (err) {
// Field have been added

@@ -92,3 +92,3 @@ });

```javascript
userLib.checkPassword('passwordToTest', 'theHashToTestAgainst', function(err, result) {
userLib.checkPassword('passwordToTest', 'theHashToTestAgainst', function (err, result) {
// Result being either true or false

@@ -101,3 +101,3 @@ });

```javascript
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, function(err, user) {
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, function (err, user) {
console.log(user.uuid); // 91f15599-c1fa-4051-9e0e-906cab9819fe (or rather, a random Uuid)

@@ -110,3 +110,3 @@ });

```javascript
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, 'f9684592-b245-42fa-88c6-9f16b9236ac3', function(err, user) {
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, 'f9684592-b245-42fa-88c6-9f16b9236ac3', function (err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3

@@ -121,3 +121,3 @@ });

```javascript
userLib.fromField('firstname', 'John', function(err, user) {
userLib.fromField('firstname', 'John', function (err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3

@@ -132,3 +132,3 @@ });

```javascript
userLib.fromFields({'firstname': 'John', 'lastname': 'Smith'}, function(err, user) {
userLib.fromFields({'firstname': 'John', 'lastname': 'Smith'}, function (err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3

@@ -141,3 +141,3 @@ });

```javascript
userLib.fromUsername('username', function(err, user) {
userLib.fromUsername('username', function (err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 or user will be false if no user is found

@@ -150,3 +150,3 @@ });

```javascript
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function(err, user) {
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function (err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3

@@ -159,3 +159,3 @@ });

```javascript
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'firstname', function(err, data) {
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'firstname', function (err, data) {
console.log(data); // ['John'] - Observe this will always be an array with values, since a field can hold several values

@@ -170,7 +170,7 @@ });

```javascript
userLib.replaceUserFields('f9684592-b245-42fa-88c6-9f16b9236ac3', {'lastname': ['Smith', 'Johnsson']}, function(err) {
userLib.replaceUserFields('f9684592-b245-42fa-88c6-9f16b9236ac3', {'lastname': ['Smith', 'Johnsson']}, function (err) {
// The field "lastname" will now be replaced with the two values "Smith" and "Johnsson"
// And all other fields will be removed
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function(err, data) {
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function (err, data) {
console.log(data); // ['Smith', 'Johnsson']

@@ -184,4 +184,4 @@ });

```javascript
userLib.rmUserField('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function(err) {
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function(err, user) {
userLib.rmUserField('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function (err) {
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function (err, user) {
console.log(user.fields); // {'firstname': ['John']}

@@ -195,3 +195,3 @@ });

```javascript
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', 'newSuperSecretPwd', function(err) {
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', 'newSuperSecretPwd', function (err) {
// Now the users password is updated to "newSuperSecretPwd"

@@ -204,3 +204,3 @@ });

```javascript
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', false, function(err) {
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', false, function (err) {
// This user can no longer login

@@ -213,3 +213,3 @@ });

```javascript
userLib.setUsername('f9684592-b245-42fa-88c6-9f16b9236ac3', 'theNewUsername', function(err) {
userLib.setUsername('f9684592-b245-42fa-88c6-9f16b9236ac3', 'theNewUsername', function (err) {
// Now the users password is updated to "theNewUsername"

@@ -216,0 +216,0 @@ });

@@ -24,3 +24,3 @@ 'use strict';

before(function(done) {
before(function (done) {
this.timeout(10000);

@@ -30,3 +30,3 @@ const tasks = [];

// Run DB Setup
tasks.push(function(cb) {
tasks.push(function (cb) {
let confFile;

@@ -43,3 +43,3 @@

// First look for absolute path
fs.stat(confFile, function(err) {
fs.stat(confFile, function (err) {
if (err) {

@@ -49,3 +49,3 @@

confFile = __dirname + '/../config/' + confFile;
fs.stat(confFile, function(err) {
fs.stat(confFile, function (err) {
if (err) throw err;

@@ -65,4 +65,4 @@ log.verbose('DB config: ' + JSON.stringify(require(confFile)));

// Check for empty db
tasks.push(function(cb) {
db.query('SHOW TABLES', function(err, rows) {
tasks.push(function (cb) {
db.query('SHOW TABLES', function (err, rows) {
if (err) throw err;

@@ -79,3 +79,3 @@

// Setup intercom
tasks.push(function(cb) {
tasks.push(function (cb) {
let confFile;

@@ -92,3 +92,3 @@

// First look for absolute path
fs.stat(confFile, function(err) {
fs.stat(confFile, function (err) {
if (err) {

@@ -98,3 +98,3 @@

confFile = __dirname + '/../config/' + confFile;
fs.stat(confFile, function(err) {
fs.stat(confFile, function (err) {
if (err) throw err;

@@ -116,3 +116,3 @@ log.verbose('Intercom config: ' + JSON.stringify(require(confFile)));

// Migrating user db etc
tasks.push(function(cb) {
tasks.push(function (cb) {
userLib.ready(cb);

@@ -124,7 +124,7 @@ });

describe('User', function() {
describe('User', function () {
let createdUuid;
it('should check if a username is available', function(done) {
userLib.usernameAvailable('testuser', function(err, res) {
it('should check if a username is available', function (done) {
userLib.usernameAvailable('testuser', function (err, res) {
if (err) throw err;

@@ -136,7 +136,7 @@ assert.deepEqual(res, true);

describe('fields', function() {
describe('fields', function () {
let fieldUuid;
it('should return an UUID for the field we are asking for', function(done) {
userLib.getFieldUuid('firstname', function(err, result) {
it('should return an UUID for the field we are asking for', function (done) {
userLib.getFieldUuid('firstname', function (err, result) {
if (err) throw err;

@@ -150,4 +150,4 @@ fieldUuid = result;

it('shold return field name "firstname" for the UUID we created above', function(done) {
userLib.getFieldName(fieldUuid, function(err, fieldName) {
it('shold return field name "firstname" for the UUID we created above', function (done) {
userLib.getFieldName(fieldUuid, function (err, fieldName) {
if (err) throw err;

@@ -160,7 +160,7 @@ assert.deepEqual(fieldName, 'firstname');

describe('passwordHash', function() {
describe('passwordHash', function () {
let hashedPassword;
it('should create a hashed password', function(done) {
userLib.hashPassword('foobar', function(err, hash) {
it('should create a hashed password', function (done) {
userLib.hashPassword('foobar', function (err, hash) {
if (err) throw err;

@@ -172,4 +172,4 @@ hashedPassword = hash;

it('should check the hashed password back against the plain text password', function(done) {
userLib.checkPassword('foobar', hashedPassword, function(err, res) {
it('should check the hashed password back against the plain text password', function (done) {
userLib.checkPassword('foobar', hashedPassword, function (err, res) {
if (err) throw err;

@@ -182,5 +182,5 @@ assert.deepEqual(res, true);

describe('create', function() {
it('should create a new user with random uuid', function(done) {
userLib.create('lilleman', 'foobar', {'firstname': 'migal', 'lastname': ['Arvidsson', 'Göransson']}, function(err, user) {
describe('create', function () {
it('should create a new user with random uuid', function (done) {
userLib.create('lilleman', 'foobar', {'firstname': 'migal', 'lastname': ['Arvidsson', 'Göransson']}, function (err, user) {
if (err) throw err;

@@ -197,4 +197,4 @@

it('should try to create a new user with the same username and fail', function(done) {
userLib.create('lilleman', 'foobar', {'firstname': 'migal', 'lastname': ['Arvidsson', 'Göransson']}, function(err, user) {
it('should try to create a new user with the same username and fail', function (done) {
userLib.create('lilleman', 'foobar', {'firstname': 'migal', 'lastname': ['Arvidsson', 'Göransson']}, function (err, user) {
assert.notEqual(err, null);

@@ -206,4 +206,4 @@ assert.equal(user, undefined);

it('should try to create a user with a field that is undefined', function(done) {
userLib.create('trams', false, {'firstname': undefined, 'lastname': ['biff', 'baff']}, function(err, user) {
it('should try to create a user with a field that is undefined', function (done) {
userLib.create('trams', false, {'firstname': undefined, 'lastname': ['biff', 'baff']}, function (err, user) {
if (err) throw err;

@@ -217,5 +217,5 @@ assert(user.uuid !== undefined);

describe('logins', function() {
it('should log the created user in by username', function(done) {
userLib.fromUsername('lilleman', function(err, user) {
describe('logins', function () {
it('should log the created user in by username', function (done) {
userLib.fromUsername('lilleman', function (err, user) {
if (err) throw err;

@@ -228,4 +228,4 @@ assert(user.uuid !== undefined, 'uuid should be set');

it('should log the created user in by username and password', function(done) {
userLib.fromUserAndPass('lilleman', 'foobar', function(err, user) {
it('should log the created user in by username and password', function (done) {
userLib.fromUserAndPass('lilleman', 'foobar', function (err, user) {
if (err) throw err;

@@ -237,4 +237,4 @@ assert(user.uuid === createdUuid, 'uuid should match the earlier created uuid');

it('should fail to log the created user in by username and password', function(done) {
userLib.fromUserAndPass('lilleman', 'nisse', function(err, user) {
it('should fail to log the created user in by username and password', function (done) {
userLib.fromUserAndPass('lilleman', 'nisse', function (err, user) {
if (err) throw err;

@@ -246,4 +246,4 @@ assert(user === false, 'user should be false');

it('should fail to log in a non existing user by username and password', function(done) {
userLib.fromUserAndPass('does_not_exist', 'foobar', function(err, user) {
it('should fail to log in a non existing user by username and password', function (done) {
userLib.fromUserAndPass('does_not_exist', 'foobar', function (err, user) {
if (err) throw err;

@@ -255,4 +255,4 @@ assert(user === false, 'user should be false');

it('should log in user by field', function(done) {
userLib.fromField('firstname', 'migal', function(err, user) {
it('should log in user by field', function (done) {
userLib.fromField('firstname', 'migal', function (err, user) {
if (err) throw err;

@@ -264,4 +264,4 @@ assert.notDeepEqual(user, false);

it('should fail to log in user by an errorous field', function(done) {
userLib.fromField('firstname', 'mupp', function(err, user) {
it('should fail to log in user by an errorous field', function (done) {
userLib.fromField('firstname', 'mupp', function (err, user) {
if (err) throw err;

@@ -273,4 +273,4 @@ assert.deepEqual(user, false);

it('should log in user by multiple fields', function(done) {
userLib.fromFields({'firstname': 'migal', 'lastname': 'Arvidsson'}, function(err, user) {
it('should log in user by multiple fields', function (done) {
userLib.fromFields({'firstname': 'migal', 'lastname': 'Arvidsson'}, function (err, user) {
if (err) throw err;

@@ -282,4 +282,4 @@ assert.notDeepEqual(user, false);

it('should fail to log in user by multiple fields when one is wrong', function(done) {
userLib.fromFields({'firstname': 'migal', 'lastname': 'no its not'}, function(err, user) {
it('should fail to log in user by multiple fields when one is wrong', function (done) {
userLib.fromFields({'firstname': 'migal', 'lastname': 'no its not'}, function (err, user) {
if (err) throw err;

@@ -292,8 +292,8 @@ assert.deepEqual(user, false);

describe('fields on logged in user', function() {
it('should remove a field from a logged in user', function(done) {
userLib.fromUsername('lilleman', function(err, user) {
describe('fields on logged in user', function () {
it('should remove a field from a logged in user', function (done) {
userLib.fromUsername('lilleman', function (err, user) {
if (err) throw err;
assert.deepEqual(user.fields.firstname, ['migal']);
user.rmField('firstname', function() {
user.rmField('firstname', function () {
assert.deepEqual(user.fields.firstname, undefined);

@@ -303,3 +303,3 @@ assert.deepEqual(user.fields.lastname[0], 'Arvidsson');

// Trying to load the user again to be sure
userLib.fromUsername('lilleman', function(err, user) {
userLib.fromUsername('lilleman', function (err, user) {
if (err) throw err;

@@ -314,6 +314,6 @@ assert.deepEqual(user.fields.firstname, undefined);

it('should set a field on a logged in user', function(done) {
userLib.fromUsername('lilleman', function(err, user) {
it('should set a field on a logged in user', function (done) {
userLib.fromUsername('lilleman', function (err, user) {
if (err) throw err;
user.addField('cell', 46709771337, function(err) {
user.addField('cell', 46709771337, function (err) {
if (err) throw err;

@@ -328,4 +328,4 @@

it('should replace fields with new data', function(done) {
userLib.fromUsername('lilleman', function(err, user) {
it('should replace fields with new data', function (done) {
userLib.fromUsername('lilleman', function (err, user) {
const newFields = {

@@ -338,3 +338,3 @@ 'foo': 'bar',

user.replaceFields(newFields, function(err) {
user.replaceFields(newFields, function (err) {
if (err) throw err;

@@ -347,3 +347,3 @@

// Reload user to make sure the fields are saved in database correctly
userLib.fromUsername('lilleman', function(err, secondUser) {
userLib.fromUsername('lilleman', function (err, secondUser) {
if (err) throw err;

@@ -361,7 +361,7 @@

it('should get field data from any user', function(done) {
userLib.fromUsername('lilleman', function(err, user) {
it('should get field data from any user', function (done) {
userLib.fromUsername('lilleman', function (err, user) {
if (err) throw err;
userLib.getFieldData(user.uuid, 'foo', function(err, data) {
userLib.getFieldData(user.uuid, 'foo', function (err, data) {
if (err) throw err;

@@ -374,4 +374,4 @@ assert.deepEqual(data, ['bar']);

it('should set a new password for a user', function(done) {
userLib.fromUsername('lilleman', function(err, user) {
it('should set a new password for a user', function (done) {
userLib.fromUsername('lilleman', function (err, user) {
if (err) throw err;

@@ -381,6 +381,6 @@

user.setPassword('biffelbaffel', function(err) {
user.setPassword('biffelbaffel', function (err) {
if (err) throw err;
userLib.fromUserAndPass('lilleman', 'biffelbaffel', function(err, user) {
userLib.fromUserAndPass('lilleman', 'biffelbaffel', function (err, user) {
if (err) throw err;

@@ -390,6 +390,6 @@

user.setPassword('BOOM', function(err) {
user.setPassword('BOOM', function (err) {
if (err) throw err;
userLib.fromUserAndPass('lilleman', 'biffelbaffel', function(err, user) {
userLib.fromUserAndPass('lilleman', 'biffelbaffel', function (err, user) {
if (err) throw err;

@@ -424,7 +424,7 @@

describe('set new username', function() {
it('should set a new username', function(done) {
describe('set new username', function () {
it('should set a new username', function (done) {
let userUuid;
userLib.create('habblabang', false, {}, function(err, user) {
userLib.create('habblabang', false, {}, function (err, user) {
if (err)

@@ -435,7 +435,7 @@ assert( ! err, 'Err should be negative, but is: ' + err.message);

userLib.setUsername(userUuid, 'blambadam', function(err) {
userLib.setUsername(userUuid, 'blambadam', function (err) {
if (err)
assert( ! err, 'Err should be negative, but is: ' + err.message);
userLib.fromUsername('blambadam', function(err, user) {
userLib.fromUsername('blambadam', function (err, user) {
if (err)

@@ -452,7 +452,7 @@ assert( ! err, 'Err should be negative, but is: ' + err.message);

describe('set new password', function() {
describe('set new password', function () {
let user;
it('should log the created user in by username', function(done) {
userLib.fromUsername('lilleman', function(err, result) {
it('should log the created user in by username', function (done) {
userLib.fromUsername('lilleman', function (err, result) {
assert.equal(result.username, 'lilleman');

@@ -464,4 +464,4 @@ user = result;

it('should set new password', function(done) {
userLib.setPassword(user.uuid, 'secretpassword', function(err) {
it('should set new password', function (done) {
userLib.setPassword(user.uuid, 'secretpassword', function (err) {
if (err) throw err;

@@ -472,4 +472,4 @@ done();

it('should log the user in by the new password', function(done) {
userLib.fromUserAndPass(user.username, 'secretpassword', function(err, result) {
it('should log the user in by the new password', function (done) {
userLib.fromUserAndPass(user.username, 'secretpassword', function (err, result) {
if (err) throw err;

@@ -482,8 +482,8 @@ assert(user.uuid === result.uuid, 'uuid should match the earlier created uuid');

describe('remove user', function() {
it('should remove a user', function(done) {
userLib.rmUser(createdUuid, function(err) {
describe('remove user', function () {
it('should remove a user', function (done) {
userLib.rmUser(createdUuid, function (err) {
if (err) throw err;
db.query('SELECT * FROM user_users WHERE uuid = ?', [lUtils.uuidToBuffer(createdUuid)], function(err, rows) {
db.query('SELECT * FROM user_users WHERE uuid = ?', [lUtils.uuidToBuffer(createdUuid)], function (err, rows) {
if (err) throw err;

@@ -583,4 +583,4 @@

after(function(done) {
after(function (done) {
db.removeAllTables(done);
});

@@ -34,3 +34,3 @@ 'use strict';

Users.prototype.get = function(cb) {
Users.prototype.get = function (cb) {
const tasks = [],

@@ -44,3 +44,3 @@ that = this;

tasks.push(function(cb) {
tasks.push(function (cb) {
const dbFields = [];

@@ -67,3 +67,3 @@

db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -87,3 +87,3 @@

tasks.push(function(cb) {
tasks.push(function (cb) {
const dbFields = [];

@@ -103,3 +103,3 @@

db.query(sql, dbFields, function(err, rows) {
db.query(sql, dbFields, function (err, rows) {
if (err) { cb(err); return; }

@@ -113,3 +113,3 @@

async.parallel(tasks, function(err) {
async.parallel(tasks, function (err) {
cb(err, result, totalElements);

@@ -116,0 +116,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc