|
|
@ -18,13 +18,10 @@ var passportFacebook = require('../auth/facebook');
|
|
|
|
var passportGoogle = require('../auth/google');
|
|
|
|
var passportGoogle = require('../auth/google');
|
|
|
|
var passportGitHub = require('../auth/github');
|
|
|
|
var passportGitHub = require('../auth/github');
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
//var router = express.Router([options]);
|
|
|
|
//var router = express.Router([options]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
>>>>>>> 98b837065bd51764d8da85c7972979c9fcf214dc
|
|
|
|
|
|
|
|
/* creation Token */
|
|
|
|
/* creation Token */
|
|
|
|
getToken = function (headers) {
|
|
|
|
getToken = function (headers) {
|
|
|
|
if (headers && headers.authorization) {
|
|
|
|
if (headers && headers.authorization) {
|
|
|
@ -52,36 +49,36 @@ const storage = multer.diskStorage({
|
|
|
|
|
|
|
|
|
|
|
|
/* GET home page. */
|
|
|
|
/* GET home page. */
|
|
|
|
router.get('/', function(req, res, next) {
|
|
|
|
router.get('/', function(req, res, next) {
|
|
|
|
res.send('Express RESTful API');
|
|
|
|
res.send('Express RESTful API');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/signup', function(req, res) {
|
|
|
|
router.post('/signup', function(req, res) {
|
|
|
|
if (!req.body.username || !req.body.password) {
|
|
|
|
if (!req.body.username || !req.body.password) {
|
|
|
|
res.json({success: false, msg: 'Please pass username and password.'});
|
|
|
|
res.json({success: false, msg: 'Please pass username and password.'});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var newUser = new User({
|
|
|
|
var newUser = new User({
|
|
|
|
username: req.body.username,
|
|
|
|
username: req.body.username,
|
|
|
|
password: req.body.password
|
|
|
|
password: req.body.password
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// save the user
|
|
|
|
// save the user
|
|
|
|
newUser.save(function(err) {
|
|
|
|
newUser.save(function(err) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
return res.json({success: false, msg: 'Username already exists.'});
|
|
|
|
return res.json({success: false, msg: 'Username already exists.'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.json({success: true, msg: 'Successful created new user.'});
|
|
|
|
res.json({success: true, msg: 'Successful created new user.'});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* SAVE FILE */
|
|
|
|
/* SAVE FILE */
|
|
|
|
router.post('/uploadFileMongo', function(req, res, next) {
|
|
|
|
router.post('/uploadFileMongo', function(req, res, next) {
|
|
|
|
FileMongo.create(req.body, function (err, post) {
|
|
|
|
FileMongo.create(req.body, function (err, post) {
|
|
|
|
if (err){
|
|
|
|
if (err){
|
|
|
|
return next(err);
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.json(post);
|
|
|
|
res.json(post);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* SAVE URL FILE */
|
|
|
|
/* SAVE URL FILE */
|
|
|
@ -110,15 +107,15 @@ router.post('/createFolder', function(req, res, next) {
|
|
|
|
|
|
|
|
|
|
|
|
/* DELETE FILE */
|
|
|
|
/* DELETE FILE */
|
|
|
|
router.post('/deleteFileMongo', function(req, res, next) {
|
|
|
|
router.post('/deleteFileMongo', function(req, res, next) {
|
|
|
|
FileMongo.remove(req.body, function (err, post) {
|
|
|
|
FileMongo.remove(req.body, function (err, post) {
|
|
|
|
if (err){
|
|
|
|
if (err){
|
|
|
|
return next(err);
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Delete file multer dans Public
|
|
|
|
//Delete file multer dans Public
|
|
|
|
fs.unlink('./public/' + req.body._id);
|
|
|
|
fs.unlink('./public/' + req.body._id);
|
|
|
|
res.json(post);
|
|
|
|
res.json(post);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* DELETE FOLDER */
|
|
|
|
/* DELETE FOLDER */
|
|
|
@ -233,28 +230,28 @@ router.post('/getFileList', function(req, res) {
|
|
|
|
|
|
|
|
|
|
|
|
/* Login */
|
|
|
|
/* Login */
|
|
|
|
router.post('/signin', function(req, res) {
|
|
|
|
router.post('/signin', function(req, res) {
|
|
|
|
User.findOne({
|
|
|
|
User.findOne({
|
|
|
|
username: req.body.username
|
|
|
|
username: req.body.username
|
|
|
|
}, function(err, user) {
|
|
|
|
}, function(err, user) {
|
|
|
|
if (err) throw err;
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
if (!user) {
|
|
|
|
res.status(401).send({success: false, msg: 'Authentication failed. User not found.'});
|
|
|
|
res.status(401).send({success: false, msg: 'Authentication failed. User not found.'});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// check if password matches
|
|
|
|
|
|
|
|
user.comparePassword(req.body.password, function (err, isMatch) {
|
|
|
|
|
|
|
|
if (isMatch && !err) {
|
|
|
|
|
|
|
|
console.log('req.user.username log : ' + JSON.stringify(user));
|
|
|
|
|
|
|
|
// if user is found and password is right create a token
|
|
|
|
|
|
|
|
var token = jwt.sign(user.toJSON(), config.secret);
|
|
|
|
|
|
|
|
// return the information including token as JSON
|
|
|
|
|
|
|
|
res.json({success: true, token: 'JWT ' + token});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.status(401).send({success: false, msg: 'Authentication failed. Wrong password.'});
|
|
|
|
// check if password matches
|
|
|
|
|
|
|
|
user.comparePassword(req.body.password, function (err, isMatch) {
|
|
|
|
|
|
|
|
if (isMatch && !err) {
|
|
|
|
|
|
|
|
console.log('req.user.username log : ' + JSON.stringify(user));
|
|
|
|
|
|
|
|
// if user is found and password is right create a token
|
|
|
|
|
|
|
|
var token = jwt.sign(user.toJSON(), config.secret);
|
|
|
|
|
|
|
|
// return the information including token as JSON
|
|
|
|
|
|
|
|
res.json({success: true, token: 'JWT ' + token});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
res.status(401).send({success: false, msg: 'Authentication failed. Wrong password.'});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -265,13 +262,13 @@ router.post('/upload' , multer({storage: storage, limits: {fileSize: 30000000000
|
|
|
|
|
|
|
|
|
|
|
|
/* Get utilisateur courant */
|
|
|
|
/* Get utilisateur courant */
|
|
|
|
router.get('/getCurrentUser', passport.authenticate('jwt', { session: false}), function(req, res) {
|
|
|
|
router.get('/getCurrentUser', passport.authenticate('jwt', { session: false}), function(req, res) {
|
|
|
|
var token = getToken(req.headers);
|
|
|
|
var token = getToken(req.headers);
|
|
|
|
|
|
|
|
|
|
|
|
if (token) {
|
|
|
|
if (token) {
|
|
|
|
res.json(req.user);
|
|
|
|
res.json(req.user);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return res.status(403).send({success: false, msg: 'Unauthorized.'});
|
|
|
|
return res.status(403).send({success: false, msg: 'Unauthorized.'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -293,20 +290,15 @@ function ensureAuthenticated(req, res, next) {
|
|
|
|
/* FACEBOOK ROUTER */
|
|
|
|
/* FACEBOOK ROUTER */
|
|
|
|
router.get('/facebook', passportFacebook.authenticate('facebook'));
|
|
|
|
router.get('/facebook', passportFacebook.authenticate('facebook'));
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
///////////////////
|
|
|
|
router.get('/facebook/callback',
|
|
|
|
router.get('/facebook/callback',
|
|
|
|
passportFacebook.authenticate('facebook', { failureRedirect: 'api/' }),
|
|
|
|
passportFacebook.authenticate('facebook', { failureRedirect: 'api/' }),
|
|
|
|
function(req, res) {
|
|
|
|
function(req, res) {
|
|
|
|
console.log('faceeeeboookk !!');
|
|
|
|
console.log('faceeeeboookk !!');
|
|
|
|
=======
|
|
|
|
|
|
|
|
router.get('/facebook/callback', passportFacebook.authenticate('facebook', { successRedirect : '/', failureRedirect: '/login' }), function(req, res) {
|
|
|
|
|
|
|
|
>>>>>>> 98b837065bd51764d8da85c7972979c9fcf214dc
|
|
|
|
|
|
|
|
// Successful authentication, redirect home.
|
|
|
|
// Successful authentication, redirect home.
|
|
|
|
res.redirect('/api/main');
|
|
|
|
res.redirect('/api/main');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
// router.get('/facebook/callback/:id', passport.authenticate('facebook'), function(req, res, err, user, info){
|
|
|
|
// router.get('/facebook/callback/:id', passport.authenticate('facebook'), function(req, res, err, user, info){
|
|
|
|
// console.log('faceeeeboookk !!');
|
|
|
|
// console.log('faceeeeboookk !!');
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -356,49 +348,27 @@ router.get('/facebook/callback', passportFacebook.authenticate('facebook', { suc
|
|
|
|
// router.get('/facebook',
|
|
|
|
// router.get('/facebook',
|
|
|
|
// passportFacebook.authenticate('facebook', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
// passportFacebook.authenticate('facebook', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
// );
|
|
|
|
// );
|
|
|
|
=======
|
|
|
|
|
|
|
|
router.get('/facebook',
|
|
|
|
|
|
|
|
passport.authenticate('facebook', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
>>>>>>> 98b837065bd51764d8da85c7972979c9fcf214dc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GOOGLE ROUTER */
|
|
|
|
/* GOOGLE ROUTER */
|
|
|
|
router.get('/google', passportGoogle.authenticate('google', { scope: 'https://www.google.com/m8/feeds' }));
|
|
|
|
router.get('/google', passportGoogle.authenticate('google', { scope: 'https://www.google.com/m8/feeds' }));
|
|
|
|
|
|
|
|
|
|
|
|
router.get('/google/callback', passportGoogle.authenticate('google', { successRedirect : '/', failureRedirect: '/login' }), function(req, res) {
|
|
|
|
router.get('/google/callback', passportGoogle.authenticate('google', { successRedirect : '/', failureRedirect: '/login' }), function(req, res) {
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
res.redirect('/');
|
|
|
|
res.redirect('/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
router.get('/google',
|
|
|
|
router.get('/google',
|
|
|
|
passport.authenticate('google', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
passport.authenticate('google', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
);
|
|
|
|
);
|
|
|
|
=======
|
|
|
|
|
|
|
|
res.redirect('/');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/google',
|
|
|
|
|
|
|
|
passport.authenticate('google', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
>>>>>>> 98b837065bd51764d8da85c7972979c9fcf214dc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GITHUB ROUTER */
|
|
|
|
/* GITHUB ROUTER */
|
|
|
|
router.get('/github', passportGitHub.authenticate('github', { scope: [ 'user:email' ] }));
|
|
|
|
router.get('/github', passportGitHub.authenticate('github', { scope: [ 'user:email' ] }));
|
|
|
|
|
|
|
|
|
|
|
|
router.get('/auth/github/callback', passportGitHub.authenticate('github', { successRedirect : '/', failureRedirect: '/login' }), function(req, res) {
|
|
|
|
router.get('/auth/github/callback', passportGitHub.authenticate('github', { successRedirect : '/', failureRedirect: '/login' }), function(req, res) {
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
// Successful authentication, redirect home.
|
|
|
|
// Successful authentication, redirect home.
|
|
|
|
res.redirect('/');
|
|
|
|
res.redirect('/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
router.get('/github',
|
|
|
|
router.get('/github',
|
|
|
|
passport.authenticate('github', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
passport.authenticate('github', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
);
|
|
|
|
);
|
|
|
|
=======
|
|
|
|
|
|
|
|
// Successful authentication, redirect home.
|
|
|
|
|
|
|
|
res.redirect('/');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/github',
|
|
|
|
|
|
|
|
passport.authenticate('github', { scope: ['read_stream', 'publish_actions'] })
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
>>>>>>> 98b837065bd51764d8da85c7972979c9fcf214dc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|
|
|
|
module.exports = router;
|
|
|
|