mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-07-24 12:50:10 +08:00
Auth- Added Back-end Logic
removed personal details
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
module.exports.mongoose = mongoose;
|
||||
module.exports.Schema = Schema;
|
||||
|
||||
// Connect to cloud database
|
||||
//https://mongolab.com/
|
||||
var username = "throwaway"
|
||||
var password = "throwaway1";//
|
||||
var address = '@ds037637.mongolab.com:37637/throwaway_db';
|
||||
connect();
|
||||
|
||||
|
||||
// Connect to mongo
|
||||
function connect() {
|
||||
|
||||
var url = 'mongodb://' + username + ':' + password + address;
|
||||
try { mongoose.connect(url); }
|
||||
catch(err) { console.log("Error: Sign In to MongoLab") }
|
||||
console.log("error caught");
|
||||
|
||||
}
|
||||
function disconnect() {
|
||||
mongoose.disconnect()
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
module.exports = function(app, passport) {
|
||||
|
||||
app.get('/', function(req, res) { res.render('index'); } );
|
||||
|
||||
// route for logging out
|
||||
app.get('/logout', function(req, res) {
|
||||
req.logout();
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email'] }));
|
||||
|
||||
// the callback after google has authenticated the user
|
||||
app.get('/auth/google/callback',
|
||||
passport.authenticate('google', {
|
||||
successRedirect : '/profile',
|
||||
failureRedirect : '/'
|
||||
}));
|
||||
};
|
||||
|
||||
// route middleware to make sure a user is logged in
|
||||
function isLoggedIn(req, res, next) {
|
||||
|
||||
// if user is authenticated in the session, carry on
|
||||
if (req.isAuthenticated())
|
||||
return next();
|
||||
|
||||
// if they aren't redirect them to the home page
|
||||
res.redirect('/');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // route for login form
|
||||
// // route for processing the login form
|
||||
// // route for signup form
|
||||
// // route for processing the signup form
|
||||
|
||||
// // route for showing the profile page
|
||||
// app.get('/profile', isLoggedIn, function(req, res) {
|
||||
// res.render('profile.ejs', {
|
||||
// user : req.user // get the user out of session and pass to template
|
||||
// });
|
||||
// });
|
||||
|
||||
// // facebook routes
|
||||
// // twitter routes
|
||||
|
||||
// // =====================================
|
||||
// // GOOGLE ROUTES =======================
|
||||
// // =====================================
|
||||
// // send to google to do the authentication
|
||||
// // profile gets us their basic information including their name
|
||||
// // email gets their emails
|
||||
Reference in New Issue
Block a user