text: const passport = require('passport');
  const localStrategy = require('passport-local').Strategy;
  const mongoose = require('mongoose');
  var JwtStrategy = require('passport-jwt').Strategy,
      ExtractJwt = require('passport-jwt').ExtractJwt;
  
  var User = mongoose.model('User');
  
  passport.use(
      new localStrategy({ usernameField: 'email' },
          (username, password, done) => {
              User.findOne({ email: username },
                  (err, user) => {
                      if (err)
                          return done(err);
                      // unknown user
                      else if (!user)
                          return done(null, false, { message: 'Email is not registered' });
                      // wrong password
                      else if (!user.verifyPassword(password))
                          return done(null, false, { message: 'Wrong password.' });
                      // authentication succeeded
                      else
                          return done(null, user);
                  });
          })
  );
  var User = require('../models/user');
  var config = require('../config/config');
  
  module.exports = function(passport) {
    var opts = {};
    opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
    opts.secretOrKey = config.secret;
    passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
      User.findOne({id: jwt_payload.id}, function(err, user) {
            if (err) {
                return done(err, false);
            }
            if (user) {
                done(null, user);
            } else {
                done(null, false);
            }
        });
    }));
  };