-
-
Save azamsharp/97e8b990b904d344e5bf724ad6f8fccb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
var session = require('express-session') | |
const mustacheExpress = require('mustache-express') | |
const bodyParser = require('body-parser') | |
var app = express() | |
app.engine('mustache',mustacheExpress()) | |
app.use(bodyParser.urlencoded({extended :true})) | |
app.set('views','./views') | |
app.set('view engine','mustache') | |
// setup middleware to use sessions | |
app.use(session({ | |
secret : 'cat' | |
})) | |
app.get('/logout',function(req,res){ | |
req.session.destroy() | |
res.redirect("login") | |
}) | |
app.get('/admin',function(req,res){ | |
if(req.session.username) { | |
res.render("admin") | |
} else { | |
res.render("error") | |
} | |
}) | |
app.post('/login',function(req,res){ | |
console.log(req.body.username) | |
let username = req.body.username | |
req.session.username = username | |
res.end() | |
}) | |
app.get('/login',function(req,res){ | |
res.render('login') | |
}) | |
app.listen(3000,function(){ | |
console.log("app is running on port 3000") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment