Basic login and redirects working.
This commit is contained in:
		
							parent
							
								
									37d11e888c
								
							
						
					
					
						commit
						5af49362ad
					
				
							
								
								
									
										13
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								server.js
									
									
									
									
									
								
							@ -60,8 +60,19 @@ var notePath = __dirname + '/note-data/allNotes.txt';
 | 
				
			|||||||
app.use(passport.initialize());
 | 
					app.use(passport.initialize());
 | 
				
			||||||
app.use(passport.session());
 | 
					app.use(passport.session());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// As with any middleware it is quintessential to call next() if the user is authenticated
 | 
				
			||||||
 | 
					var isAuthenticated = function (req, res, next) {
 | 
				
			||||||
 | 
					    if (req.isAuthenticated()) {
 | 
				
			||||||
 | 
					        return next();
 | 
				
			||||||
 | 
					        res.redirect('/');
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        // If user NOT authenticated, redirect to login page, do not call next().
 | 
				
			||||||
 | 
					        res.redirect('/login');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//app.get('/', require('connect-ensure-login').ensureLoggedIn(), function(req, res){
 | 
					//app.get('/', require('connect-ensure-login').ensureLoggedIn(), function(req, res){
 | 
				
			||||||
app.get('/', function(req, res){
 | 
					app.get('/', isAuthenticated, function(req, res){
 | 
				
			||||||
    winston.info("GET /");
 | 
					    winston.info("GET /");
 | 
				
			||||||
    // Get curent text from allNotes.txt and pass that data to handlebars template.
 | 
					    // Get curent text from allNotes.txt and pass that data to handlebars template.
 | 
				
			||||||
    fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
 | 
					    fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user