app.get('/user', function(req, res) {
if(req.isAuthenticated() && req.user.role == 'user')
res.render('user');
});
app.post('/changeRole', function(req, res){
console.log(req.body);
pg.connect(connectionString, function(err, client, done){
console.log(req);
if(err){
return console.error('error feetching client from pool', err);
}
client.query('UPDATE items SET role=($1), change=($2) WHERE name=($3)', [req.body.role,
req.body.role == 'user' ? 'true' : 'false', req.body.name]);
done();
});
});
module.exports.getUser = (req, res) => {
if (req.isAuthenticated() && req.user.role == 'user')
res.render('user');
}
module.exports.postChangeRole = (req, res) => {
console.log(req.body);
pg.connect(connectionString, function (err, client, done) {
console.log(req);
if (err) {
return console.error('error feetching client from pool', err);
}
client.query('UPDATE items SET role=($1), change=($2) WHERE name=($3)', [req.body.role,
req.body.role == 'user' ? 'true' : 'false', req.body.name]);
done();
});
}
var handlers=require('./handlers');
app.get('/user', handlers.getUser);
app.post('/changeRole',handlers.postChangeRole);
function(req, res) {
if(req.isAuthenticated() && req.user.role == 'user')
res.render('user');
module.expotrts = function(req, res) {
if(req.isAuthenticated() && req.user.role == 'user')
res.render('user');
};
foo.js
app.get('/user', require('./foo'));