Split out user data from auth-code & add auth code to repo.
This commit is contained in:
		
							parent
							
								
									ec95ba46a5
								
							
						
					
					
						commit
						cb2a59eb52
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,4 +1,4 @@
 | 
			
		||||
/db/*
 | 
			
		||||
/db/users.js
 | 
			
		||||
/assets/*
 | 
			
		||||
/CodeMirror/*
 | 
			
		||||
/codemirror/*
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								db/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								db/index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
exports.users = require('./users');
 | 
			
		||||
exports.utils = require('./utils');
 | 
			
		||||
							
								
								
									
										32
									
								
								db/utils.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								db/utils.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
var users = require('./users');
 | 
			
		||||
 | 
			
		||||
exports.findById = function(id, cb) {
 | 
			
		||||
  process.nextTick(function() {
 | 
			
		||||
    var idx = id - 1;
 | 
			
		||||
    if (users.records[idx]) {
 | 
			
		||||
      cb(null, users.records[idx]);
 | 
			
		||||
    } else {
 | 
			
		||||
      cb(new Error('User ' + id + ' does not exist'));
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.findByUsername = function(username, cb) {
 | 
			
		||||
  process.nextTick(function() {
 | 
			
		||||
    for (var i = 0, len = users.records.length; i < len; i++) {
 | 
			
		||||
      var record = users.records[i];
 | 
			
		||||
      if (record.username === username) {
 | 
			
		||||
        return cb(null, record);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return cb(null, null);
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.userIdArray = function() {
 | 
			
		||||
    var userIdArray = [];
 | 
			
		||||
    for (var i = 0, len = users.records.length; i < len; i++) {
 | 
			
		||||
        userIdArray.push(users.records[i].id);
 | 
			
		||||
    }
 | 
			
		||||
    return userIdArray;
 | 
			
		||||
}
 | 
			
		||||
@ -36,9 +36,9 @@ app.set('trust proxy', true);
 | 
			
		||||
// will be set at `req.user` in route handlers after authentication.
 | 
			
		||||
passport.use(new Strategy(
 | 
			
		||||
  function(username, password, cb) {
 | 
			
		||||
    db.users.findByUsername(username, function(err, user) {
 | 
			
		||||
    db.utils.findByUsername(username, function(err, user) {
 | 
			
		||||
      winston.info('trying to lookup user.');
 | 
			
		||||
      if (err) { winston.info('db.users.findByUsername error.'); return cb(err); }
 | 
			
		||||
      if (err) { winston.info('db.utils.findByUsername error.'); return cb(err); }
 | 
			
		||||
      if (!user) { winston.info('bad user'); return cb(null, false); }
 | 
			
		||||
      if (user.password != password) { winston.info('bad pw'); return cb(null, false); }
 | 
			
		||||
      return cb(null, user);
 | 
			
		||||
@ -56,7 +56,7 @@ passport.serializeUser(function(user, cb) {
 | 
			
		||||
  cb(null, user.id);
 | 
			
		||||
});
 | 
			
		||||
passport.deserializeUser(function(id, cb) {
 | 
			
		||||
  db.users.findById(id, function (err, user) {
 | 
			
		||||
  db.utils.findById(id, function (err, user) {
 | 
			
		||||
    if (err) { return cb(err); }
 | 
			
		||||
    cb(null, user);
 | 
			
		||||
  });
 | 
			
		||||
@ -188,7 +188,7 @@ setInterval(
 | 
			
		||||
    function() {
 | 
			
		||||
        //winston.info('setInterval fired.');
 | 
			
		||||
        var exec = require('child_process').exec;
 | 
			
		||||
        const userIdArray = db.users.userIdArray();
 | 
			
		||||
        const userIdArray = db.utils.userIdArray();
 | 
			
		||||
        for (const userId of userIdArray) { 
 | 
			
		||||
            var noteDir;
 | 
			
		||||
            if (userId === 1) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user