<commit_before>var LocalStrategy = require('passport-local').Strategy;
var bCrypt = require('bcrypt-nodejs');
const db = require("../../models");

module.exports = function(passport) {

  var Guest = db.Guest;
  var Admin = db.Manager;

  passport.serializeUser(function(user, done) {
    var isAdmin = user.isAdmin === 0 || user.isAdmin === 1;
    return done(null, { id: user.id, isAdmin: isAdmin });
  });

  passport.deserializeUser(function(id, done) {
    if (id) {
      if (!id.isAdmin) {
        Guest.findById(id.id).then(function(user) {
          if (user) {
            done(null, user.get());
          }
          else{
            done(user.errors, null);
          }
        });
      }
      else if (id.isAdmin) {
        Admin.findById(id.id).then(function(user) {
          if (user) {
            done(null, user.get());
          }
          else{
            done(user.errors, null);
          }
        });
      }
    }
  });

  // Guest Signup
  passport.use('local-signup', new LocalStrategy ({
    usernameField : 'email',
    passwordField : '<PASSWORD>',
    passReqToCallback : true
  }, 
  function(req, email, lastname, done) {
    var data = {
      first_name: req.body.firstname,
      last_name: lastname,
      phone: req.body.phone,
      email: email,
      room_number: req.body.room,
      checkin: req.body.checkin,
      checkout: req.body.checkout
    };
<commit_msg>Fix passport<commit_after>var LocalStrategy = require('passport-local').Strategy;
var bCrypt = require('bcrypt-nodejs');
const db = require("../../models");

module.exports = function(passport) {

  var Guest = db.Guest;
  var Admin = db.Manager;

  passport.serializeUser(function(user, done) {
    return done(null, { id: user.id, isAdmin: user.isAdmin });
  });

  passport.deserializeUser(function(id, done) {
    if (!id.isAdmin) {
      Guest.findById(id.id).then(function(user) {
        if (user) {
          done(null, user.get());
        }
      }).catch(function (err) {
        console.log(err);
      });
    }
    else if (id.isAdmin) {
      Admin.findById(id.id).then(function(user) {
        if (user) {
          done(null, user.get());
        }
      }).catch(function (err) {
        console.log(err);
      });
    }
  });

  // Guest Signup
  passport.use('local-signup', new LocalStrategy ({
    usernameField : 'email',
    passwordField : '<PASSWORD>',
    passReqToCallback : true
  }, 
  function(req, email, lastname, done) {
    var data = {
      first_name: req.body.firstname,
      last_name: lastname,
      phone: req.body.phone,
      email: email,
      room_number: req.body.room,
      checkin: req.body.checkin,
      checkout: req.body.checkout
    };

{'fraction_non_alphanumeric': 0.15398818316100443, 'fraction_numerical': 0.0007385524372230429, 'mean_word_length': 2.2443113772455088, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '488558', 'n_tokens_mistral': 897, 'n_tokens_neox': 877, 'n_words': 167}