Created
January 24, 2017 17:53
-
-
Save higordiego/c69b8afea6ead7700b4f071b593aff2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const router = express.Router() | |
const passport = require('passport') | |
const Controller = require("./organism") | |
const authenticate = require('./_organelles/organelles-validate-login') | |
// Create | |
router.post('/', Controller.add) | |
// get current user | |
router.get('/currentuser', isLoggedIn, Controller.getCurrentUserEmpresas) | |
// (req, res) => { | |
// // console.log('global.user', global.user) | |
// // const user = JSON.stringify(global.user) | |
// res.json(global.user) | |
// }) | |
// logout | |
router.post('/logout', (req, res) => { | |
req.logout() | |
res.status(200).send('Ok') | |
}) | |
router.get('/filter', Controller.findByFilters) | |
router.get('/get/:id', Controller.getById) | |
// Retrieve | |
router.get('/', Controller.findAllByPage) | |
router.get('/:page', Controller.findAllByPage) | |
// get one | |
router.post('/find', Controller.get) | |
// Update | |
router.put('/:id', Controller.modify) | |
// Delete | |
router.delete('/:id', Controller.delete) | |
// login | |
router.post('/login', authenticate(app); | |
router.post('/setCompany', Controller.saveTempCompany, function(req, res){ | |
res.json(req.body); | |
res.end(); | |
}); | |
router.get('/loginFailure', function(req, res, next) { | |
res.send('Failed to authenticate'); | |
}); | |
router.get('/loginSuccess', function(req, res, next) { | |
res.send('Successfully authenticated'); | |
}); | |
function isLoggedIn(req, res, next){ | |
// console.log('global.user', global.user) | |
if(typeof global.user == "undefined") return res.status(403).send('User not logged in. Try again') | |
return next() | |
} | |
module.exports = router |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment