-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
96 lines (81 loc) · 2.29 KB
/
router.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var express = require('express');
var router = express.Router();
var controller = require('./controller');
var passport = require('passport');
//router.get('/', function(req,res){console.log("mazinger sa7y!"); res.send("Mazinger Sa7y!!");});
/*router.get
(
'/',
function(req,res)
{
res.sendFile(__dirname + "/staticDir/index.htm");
}
);*/
router.get('/test', function(req,res){res.send("backend works!")});
router.post('/register', controller.register);
//router.post('/login', controller.login);
router.post('/sendmessage', controller.authorise, controller.sendMessage);
//router.post('/sendmessage', controller.sendMessage);
router.post('/authenticate', controller.authenticate);
router.get('/getallusers', controller.authorise, controller.getAllUsers);
router.post('/fetchconversation', controller.authorise, controller.fetchConversation);
//router.get('/');
/*router.post
(
'/login',
passport.authenticate('local', {successRedirect:'/sr', failureRedirect:'/fr'}),
function(req,res){console.log("You're logged in!");res.redirect('/');}
);
router.get('/test',passport.authenticate('jwt', { session: false }), function(req,res){console.log("you're good");});
router.get('/sr',function(req,res){console.log("success redirect!!!!!!")});
router.get('/fr',function(req,res){console.log("failure redirect :c")});
passport.use
(
new LocalStrategy
(
function(Username, password, done)
{
User.findOne
(
{Username:Username},
function(err, user)
{
if(err)
throw err;
if(!user)
return done(null, false, {message: 'Unknown User'});
User.comparePassword
(
password,
user.password,
function(err, isMatch)
{
if(err)
throw err;
if(isMatch)
return done(null, user);
else
return done(null, false, {message: 'Invalid password'});
}
);
}
);
}
)
);
passport.serializeUser(function(user, done){done(null, user.Username);});
passport.deserializeUser
(
function(Username, done)
{
User.findOne
(
{Username:Username},
function(err, user)
{
done(err, user);
}
);
}
);*/
module.exports = router;