-
Notifications
You must be signed in to change notification settings - Fork 2
/
routes.js
62 lines (53 loc) · 2.28 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express = require('express');
const router = express.Router();
const multer = require('multer');
const passport = require('passport');
const homeController = require('./controllers/home.controller');
const uploadController = require('./controllers/upload.controller');
const userController = require('./controllers/user.controller');
const opsController = require('./controllers/ops.controller');
const { is_authenticated } = require('./config/passport');
require('./config/passport');
// file upload setup
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'controllers/uploads');
},
filename: (req, file, cb) => {
const { originalname } = file;
cb(null, `${Date.now()}_${originalname}`);
},
});
const upload = multer({ storage });
router.get('/', homeController.getHome);
router.get('/hrms', homeController.getHome);
router.get('/login', userController.getLogin);
router.get('/signup', userController.getSignup);
router.get('/logout', userController.logout);
// router.post('/login', userController.postLogin);
// router.post('/signup', userController.postSignup);
router.post('/api/upload/doc/local', upload.single('doc_ops'), uploadController.local);
router.get('/api/ope', is_authenticated, uploadController.getAfterDocPostLoggedIn);
router.post('/api/ope', is_authenticated, uploadController.afterDocPostLoggedIn);
router.get('/api/ope/:filename', uploadController.getAfterDocPostLoggedOut);
router.post('/api/ope/:filename', uploadController.afterDocPostLoggedOut);
// router.post('/api/upload/doc/S3', uploadController.S3);
router.get('/api/upload/:filename', opsController.docOpsResponse);
router.get('/auth/success', is_authenticated, (req, res, next) => {
req.flash('success', { msg: `Successfully authenticated using OAuth Accounts`});
res.redirect('/');
});
router.get('/auth/failure', is_authenticated, (req, res, next) => {
req.flash('danger', { msg: 'Somthing went wrong, authentication failed!'});
res.redirect('/');
});
router.get('/auth/google',
passport.authenticate('google', {scope: ['email', 'profile']}),
);
router.get('/auth/google/callback',
passport.authenticate('google', {
successRedirect: '/auth/success',
failureRedirect: '/auth/failure',
}),
);
module.exports = router;