-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
77 lines (62 loc) · 2.26 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var workgroupController = require('./controller/workgroup.js'),
taskController = require('./controller/task.js'),
userController = require('./controller/user.js');
var mongoose = require('mongoose');
var User = mongoose.model('user');
var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy;
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user)
{
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password))
{
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, false, { message: 'Incorrect password.' });
});
}
));
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
module.exports = function(app){
app.get('/', (req, res) => {
res.redirect('workgroups');
});
app.get('/users', userController.list);
app.post('/users', userController.create);
app.get('/users/:id', userController.read);
app.put('/users/:id', userController.update);
app.delete('/users/:id', userController.delete);
app.post('/addMember', workgroupController.addUser);
app.post('/addJudge', workgroupController.addJudge);
app.get('/workgroups', workgroupController.list);
app.post('/workgroups', workgroupController.create);
app.get('/workgroups/:id', workgroupController.read);
app.put('/workgroups/:id', workgroupController.update);
app.delete('/workgroups/:id', workgroupController.delete);
app.get('/tasks', taskController.list);
app.post('/tasks', taskController.create);
app.get('/tasks/:id', taskController.read);
app.put('/tasks/:id', taskController.update);
app.delete('/tasks/:id', taskController.delete);
app.get('/html', (req, res) =>{
res.send('This is a sample html page');
});
app.get('/login', (req, res) => {
res.render('login');
});
app.post('/login',
passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login', failureFlash: true })
);
}