From 16b6c49b1e1c811cceb78cf5284aefefe337d417 Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Wed, 5 Sep 2018 12:05:49 -0400 Subject: [PATCH] kill old user if not found --- authentication.js | 21 ++++++++++++++------- config/user_config.js | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/authentication.js b/authentication.js index 0cba457..52419cd 100644 --- a/authentication.js +++ b/authentication.js @@ -51,7 +51,7 @@ exports.configure = function(){ if(!data.isAdmin){ return done(null, false, { message: 'Must be admin' }); } - + console.log('configure'); var user = { 'username': username, 'password': data.password, @@ -109,6 +109,7 @@ exports.configure = function(){ }; var addUser = function(username,password,callback){ + console.log('adduser'); config.user.add(username,password,function(err,user){ if(err){ callback(err); @@ -209,6 +210,7 @@ var modifyUser = function(username, user_fields,callback){ } } config.user.update(newData, function(err,user){ + console.log('hey'); if(user)user.password=undefined; // don't transmit the password back callback(err,user); return; @@ -233,13 +235,17 @@ passport.serializeUser(function(user, done) { passport.deserializeUser(function(username, done) { config.user.findOne(username, function(err, data) { - var user = { - 'username': username, - 'password': data.password, - 'isAdmin' : data.isAdmin, - 'created_at': data.created_at + if(err) { + done(null, false, { message: 'User does not exist' }); + }else { + var user = { + 'username': username, + 'password': data.password, + 'isAdmin' : data.isAdmin, + 'created_at': data.created_at + } + done(err, user); } - done(err, user); }); }); @@ -254,6 +260,7 @@ exports.deleteUser = deleteUser; exports.passport = passport; exports.getUserById = function(username,cb){ + console.log('getUserById'); config.user.findOne(username, function(err, data) { var user = { 'username': username, diff --git a/config/user_config.js b/config/user_config.js index 8bae3c4..5accde2 100644 --- a/config/user_config.js +++ b/config/user_config.js @@ -174,7 +174,7 @@ UserConfig.prototype.add = function(username,password,callback){ //Maybe move this to the routes or whatever UserConfig.prototype.findOne = function(username,callback){ - username in this._cache ? callback(null, this._cache[username]) : callback(null, null); + username in this._cache ? callback(null, this._cache[username]) : callback('no user', null); } UserConfig.prototype.getAll = function(callback){