var mongoose = require('mongoose');
module.exports = mongoose.model('Admin',{
username: String,
password: String,
role: { type: String, default: "user" },
soft_token: { type: String, default: 0 }
});
var isAuthenticated = function (req, res, next) {
var currentUserId = req.user ? req.user.id : false;
if(!currentUserId){
res.redirect('/');
return;
}
Admin.findById(currentUserId,function (err, user) {
if(!user || user.role !== "admin"){
res.redirect('/');
}else{
next();
}
})
}
router.get('/admin', isAuthenticated, function(req, res, next) {
res.end();
});