Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var fortune = require('fortune')
, orm = require('orm')
, RSVP = fortune.RSVP
, _ = fortune._;
var adapter = {};
adapter._init = function(options) {
var _this = this;
// Setup ORM instance.
this.orm = orm.connect({
host: options.host,
database: options.db,
protocol: options.adapter,
user: options.username,
password: options.password,
port: options.port,
query: options.flags
}, function(e) {
fortune.RSVP.rethrow(e);
console.error("error authenticating user: ", e);
res.send(500);
});
}
sittings: ['sitting']
}).transform(auth.before, auth.after).
resource("sitting", {
startedAt: Date,
endedAt: Date,
requestedBy: 'family',
performedBy: {ref: 'family', inverse: 'sittings'}
}).
resource("token", {
owner: 'family',
value: String
});
fortune.RSVP.configure("onerror", function(error) {
if(error) {
console.error("error resolving promise: ", error.stack);
}
});
var pbkdf2 = {
iterations: Math.pow(2, 16),
keylen: Math.pow(2, 8)
};
function authentication(req, res, next) {
if(!req.path.match(/sessions/i)) return next();
if(!req.header('content-type').match(/^application\/json/)) {
return res.send(412);
}
function checkUser(user, compareToken) {
return new fortune.RSVP.Promise(function(resolve, reject) {
if(!compareToken) return reject();
global.app.adapter.findMany('token', user.links.tokens).then(function(tokens) {
var tokenFound = false;
tokens.forEach(function(token) {
if(token.value == compareToken) {
tokenFound = true;
resolve(user);
}
});
if(!tokenFound) reject("token not found");
}, function() {