Hello everyone, I am creating a simple java script website using handlebars to (hopefully create a theme and link to other sites on the page. for example, a messages page would be messages.handlebars, home.handlebars, questions.handlebars, and project.handlebars.) These are in my Views->Layouts->Folder.The site needs some sort of of authentication such as Google Oauth (I think thats what it is called) as well as a feature for returning users.Here is my current code below:If anybody could help me out I'd love you forever!index.js*//////////////////////////////////////* // first, set up the express app. //////////////////////////////var express = require ('express');var app = express();app.set('port', process.env.PORT || 3000);////////////////////second, load other required modules///////////var handlebars = require('express-handlebars').create({defaultLayout: 'main'});app.engine('handlebars', handlebars.engine);app.set('view engine',** 'handlebars**');var passport = require('passport'), LocalStrategy = require('passport-local').Strategy, ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;// these serialize// deserialize function put the whole user object into the session.// see https://ift.tt/2wm7Vkz for a better approach when using a databasepassport.serializeUser(function(user, done) {done(null, user);});passport.deserializeUser(function(user, done) {done(null, user);});passport.use(new LocalStrategy(function(username,password,done) {// username and password are strings entered by the user// done is a function to all with the first parameter an error// object or null if no error; the second parameter is false if// login failed or an object representing the user.console.log("Attempting local login for "+username);if(password===**"password"**) {return done(null, {name: username});// why, yes... "password" is my password; I'm an idiot!}else {return done(null,** fals**e*);//not logged *in}}));//////////// third//////////app.use(express.static(__dirname + '/public'));app.use(require('body-parser').urlencoded({ extended**: tr**ue }));app.use(function (req, res, next) {if (app.get('env') !== 'production' && req.query.test **== **'1') {res.locals.showTests = true;}next();});app.get("/newitem"****,function(req, res){res.render('newitem');});////////////////fourth, the specific pages///////////////app.get('/',** functio**n(req,res) {res.render('home');});app.get('/messages',** functio**n (req, res) {res.render('messages', {fortune: fortune.getFortune(),pageTestScript: '/qa/tests-about.js'});});/\* Error Handling*\ ///////*\/*app.use(function (req, res) {//res.type('text/plain');res.status(404);res.render('404');});/\**\ An app.use callback with FOUR (4) parameters is an*\ error handler; the err is in the first*\ parameter to the function.*\ This lets you gracefully catch errors in your*\ code without crashing your whole application*\/*app.use(function (err, req, res, next) {console.log(err.stack);//res.type('text/plain');res.status(500); // server errorres.render("500");});app.listen(app.get('port'), function() { console.log('Express started on http://localhost:' + app**.get('port')+ "; press Ctrl+C to** end."); })**;**********
Submitted May 07, 2018 at 03:29PM by Spanish_Trampoline
No comments:
Post a Comment