text: module.exports = function(app, passport, db) {
  
  const multer = require('multer');//needed for image upload
  
  // normal routes ===============================================================
  
      // show the home page (will also have our login links)
      app.get('/', function(req, res) {
          db.collection('book').find().toArray((err, result) => {
            if (err) return console.log(err)
            res.render('book.ejs', {
              user : req.user,
              comment : result
            })
          })
      });
  
      // show the home page (will also have our login links)
      app.get('/index', function(req, res) {
          res.render('index.ejs');
      });
  
      // PROFILE SECTION =========================
      app.get('/profile', isLoggedIn, function(req, res) {
          db.collection('book').find().toArray((err, result) => {
            if (err) return console.log(err)
            res.render('profile.ejs', {
              user : req.user,
              comment : result
            })
          })
      });
  
      // LOGOUT ==============================
      app.get('/logout', function(req, res) {
          req.logout();
          res.redirect('/');
      });
  
  // message board routes ===============================================================
  
      app.post('/comment', (req, res) => {
        db.collection('book').save({img:req.body.image, name: req.body.name, comment: req.body.comment, thumbUp: 0, thumbDown:0}, (err, result) => {
          if (err) return console.log(err)
          console.log('saved to database')
          res.redirect('/profile')
        })
      })
  
  //---------------------------------------
  // IMAGE CODE
  //---------------------------------------
  var storage = multer.diskStorage({
      destination: (req, file, cb) => {
        cb(null, 'public/images/uploads')
      },
      filename: (req, file, cb) => {
        cb(null, file.fieldname + '-' + Date.now())
      }
  });
  var upload = multer({storage: storage});
  
  app.post('/up', upload.single('file-to-upload'), (req, res, next) => {
        debugger
        console.log(req);
      insertDocuments(db, 'public/img/uploads/' + req.file.filename, () => {
          db.close();
          res.json({'message': 'File uploaded successfully'});
          next.redirect('/profile')
      });
  });
  
  var insertDocuments = function(db, filePath, callback) {
      var collection = db.collection('user');
      collection.insertOne({'imagePath' : filePath }, (err, result) => {
          //assert.equal(err, null);
          callback(result);
      });
  }
  //---------------------------------------
  // IMAGE CODE END
  //---------------------------------------
  
  
      app.put('/messages', (req, res) => {
        db.collection('book')
        .findOneAndUpdate({name: req.body.name, comment: req.body.comment}, {
          $set: {
            thumbUp:req.body.thumbUp + 1
          }
        }, {
          sort: {_id: -1},
          upsert: true
        }, (err, result) => {
          if (err) return res.send(err)
          res.send(result)
        })
      })
  
      app.put('/messages2', (req, res) => {
        db.collection('book')
        .findOneAndUpdate({name: req.body.name, comment: req.body.comment}, {
          $set: {
            thumbDown:req.body.thumbDown + 1
          }
        }, {
          sort: {_id: -1},
          upsert: true
        }, (err, result) => {
          if (err) return res.send(err)
          res.send(result)
        })
      })
  
      app.delete('/messages', (req, res) => {
        db.collection('book').findOneAndDelete({name: req.body.name, comment: req.body.comment}, (err, result) => {
          if (err) return res.send(500, err)
          res.send('Message deleted!')
        })
      })
  
  // =============================================================================
  // AUTHENTICATE (FIRST LOGIN) ==================================================
  // =============================================================================
  
      // locally --------------------------------
          // LOGIN ===============================
          // show the login form
          app.get('/login', function(req, res) {
              res.render('login.ejs', { message: req.flash('loginMessage') });
          });
  
          // process the login form
          app.post('/login', passport.authenticate('local-login', {
              successRedirect : '/profile', // redirect to the secure profile section
              failureRedirect : '/login', // redirect back to the signup page if there is an error
              failureFlash : true // allow flash messages
          }));
  
          // SIGNUP =================================
          // show the signup form
          app.get('/signup', function(req, res) {
              res.render('signup.ejs', { message: req.flash('signupMessage') });
          });
  
          // process the signup form
          app.post('/signup', passport.authenticate('local-signup', {
              successRedirect : '/profile', // redirect to the secure profile section
              failureRedirect : '/signup', // redirect back to the signup page if there is an error
              failureFlash : true // allow flash messages
          }));
  
  // =============================================================================
  // UNLINK ACCOUNTS =============================================================
  // =============================================================================
  // used to unlink accounts. for social accounts, just remove the token
  // for local account, remove email and password
  // user account will stay active in case they want to reconnect in the future
  
      // local -----------------------------------
      app.get('/unlink/local', isLoggedIn, function(req, res) {
          var user            = req.user;
          user.local.email    = undefined;
          user.local.password = undefined;
          user.save(function(err) {
              res.redirect('/profile');
          });
      });
  
  };
  
  // route middleware to ensure user is logged in
  function isLoggedIn(req, res, next) {
      if (req.isAuthenticated())
          return next();
  
      res.redirect('/');
  }
  