-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
43 lines (32 loc) · 1.22 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
const express = require('express');
const passport = require('passport');
require('./src/config/auth')(passport);
const routes = express.Router();
const UserRegisterControl = require('./src/controllers/UserRegisterControl');
const UserAddDeviceControl = require('./src/controllers/UserAddDeviceControl');
const Controlls = require('./src/controllers/Controls');
routes.post('/:userId/add/device', UserAddDeviceControl.store);
routes.post('/user/register', UserRegisterControl.store);
routes.delete('/:userId/delete/:deviceId', Controlls.delete);
routes.put('/:userId/put/:deviceId', Controlls.update);
routes.get('/user/logout', (req, res) => {
req.logout();
res.json({ msg: 'Successfully logged out' });
});
//req.params.user
routes.get('/user/login/failure', (req, res) => {
res.json({ msg: 'Error LogIn' });
});
routes.get('/user/login/success', (req, res) => {
res.json({ msg: req.user });
});
routes.post('/user/login', (req, res, next) => {
if (req.user === undefined) {
return passport.authenticate('local', {
successRedirect: '/user/login/success',
failureRedirect: '/user/login/failure'
})(req, res, next);
}
res.json({ msg: 'You are already logged in' });
});
module.exports = routes;