From 895a72f2419be6e558f39b4d387ca351ad1919a3 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Mon, 10 Aug 2015 20:53:09 -0500 Subject: [PATCH] Removing Bcrypt to make Windows builds easier. --- api/controllers/login.controller.js | 3 +- api/routes/auth.routes.js | 2 +- api/server.js | 16 +++++++- api/services/data.js | 59 +++++++++++++---------------- package.json | 1 - 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/api/controllers/login.controller.js b/api/controllers/login.controller.js index 4f4a0c5..7ecc946 100644 --- a/api/controllers/login.controller.js +++ b/api/controllers/login.controller.js @@ -1,6 +1,5 @@ var Q = require('q'); var Boom = require('boom'); -var Bcrypt = require('bcrypt'); var db = require('../services/db'); var props = require('../properties'); @@ -47,7 +46,7 @@ function login (request, reply) { } function validate (password, userPassword) { - return Q.ninvoke(Bcrypt, 'compare', password, userPassword); + return Q(password === userPassword); } function setSession (request, sid, cacheObject) { diff --git a/api/routes/auth.routes.js b/api/routes/auth.routes.js index d377647..dd7511f 100644 --- a/api/routes/auth.routes.js +++ b/api/routes/auth.routes.js @@ -11,7 +11,7 @@ exports.register = function (server, options, next) { server.route([ {method: 'POST', path: login, config: {handler: loginController.login, auth: false}}, {method: 'GET', path: login, config: {handler: loginController.index, auth: false}}, - {method: 'POST', path: logout, handler: logoutController.logout} + {method: 'GET', path: logout, config: {handler: logoutController.logout, auth: false}} ]); return next(); diff --git a/api/server.js b/api/server.js index 92ef476..f341359 100644 --- a/api/server.js +++ b/api/server.js @@ -28,6 +28,21 @@ server.views({ path: Path.join(__dirname, 'views') }); +server.register(cookie, function (err) { + server.auth.strategy('session', 'cookie', true, { + password: props.security.cookieSecret, + isSecure: false, + validateFunc: function (request, session, callback) { + cache.get(session.sid, function (err, cached) { + if (err || !cached) { + return callback(err, false); + } + return callback(null, true, cached.user); + }); + } + }); +}); + // register the routes server.register([ require('./routes/file.route'), @@ -35,7 +50,6 @@ server.register([ require('./routes/projects.routes'), require('./routes/users.routes'), require('./routes/index.route') - ], function (err) { if (err) console.log('Error registering routes: ' + err); }); diff --git a/api/services/data.js b/api/services/data.js index 4a3219c..347d58c 100644 --- a/api/services/data.js +++ b/api/services/data.js @@ -1,7 +1,6 @@ var _ = require('lodash'), db = require('./db'), - Q = require('q'), - bcrypt = require('bcrypt'); + Q = require('q'); exports.init = init; @@ -36,45 +35,41 @@ function seed() { _.forEach(users, function (user) { console.log("Seeding " + user.username); - bcrypt.hash(user.password, 10, function (err, hash) { - user.password = hash; + db.insert('users', user) + .then(function (newUser) { - db.insert('users', user) - .then(function (newUser) { + console.log("Created " + newUser.username); - console.log("Created " + newUser.username); + var timesheets = user.username === "admin" ? adminTimesheets: userTimesheets; - var timesheets = user.username === "admin" ? adminTimesheets: userTimesheets; + _.forEach(timesheets, function (timesheet) { + var timesheetModel = _.omit(timesheet, 'timeunits'); + timesheetModel.user_id = newUser._id; - _.forEach(timesheets, function (timesheet) { - var timesheetModel = _.omit(timesheet, 'timeunits'); - timesheetModel.user_id = newUser._id; + db.insert('timesheets', timesheetModel) + .then(function (newTimesheet) { - db.insert('timesheets', timesheetModel) - .then(function (newTimesheet) { + console.log("Seeding timeunits : " + timesheet.timeunits.length); - console.log("Seeding timeunits : " + timesheet.timeunits.length); + _.forEach(timesheet.timeunits, function (timeunit) { + timeunit.timesheet_id = newTimesheet._id; - _.forEach(timesheet.timeunits, function (timeunit) { - timeunit.timesheet_id = newTimesheet._id; - - console.log("Attempting to seed timeunit : " + timeunit.project); - db.findOne('projects', {name: timeunit.project}) - .then(function (project) { - timeunit.project_id = project._id; - return db.insert('timeunits', timeunit); - }) - .then(function (newTimeunit) { - console.log("Created timeunit for " + newTimeunit.dateWorked); - }) - .fail(function (err) { - console.log("Error : " + err); - }); - }); + console.log("Attempting to seed timeunit : " + timeunit.project); + db.findOne('projects', {name: timeunit.project}) + .then(function (project) { + timeunit.project_id = project._id; + return db.insert('timeunits', timeunit); + }) + .then(function (newTimeunit) { + console.log("Created timeunit for " + newTimeunit.dateWorked); + }) + .fail(function (err) { + console.log("Error : " + err); + }); }); - }); + }); }); - }); + }); }); }) diff --git a/package.json b/package.json index 597cc5e..cb2c1ed 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "browserify-shim": "./config/shims.js", "dependencies": { "axios": "^0.5.4", - "bcrypt": "^0.8.4", "better-console": "^0.2.4", "boom": "^2.8.0", "classnames": "^2.1.3",