-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
2,389 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const express = require('express'); | ||
const path = require('path'); | ||
const logger = require('morgan'); | ||
const cookieParser = require('cookie-parser'); | ||
const bodyParser = require('body-parser'); | ||
const session = require('express-session'); | ||
const FileStore = require('session-file-store')(session); | ||
const passport = require('passport'); | ||
// const authenticate = require('./authenticate'); | ||
const config = require('./config'); | ||
|
||
const index = require('./routes/index'); | ||
const userRouter = require('./routes/userRouter'); | ||
const dishRouter = require('./routes/dishRouter'); | ||
const promoRouter = require('./routes/promoRouter'); | ||
const leaderRouter = require('./routes/leaderRouter'); | ||
|
||
const mongoose = require('mongoose'); | ||
mongoose.Promise = require('bluebird'); | ||
|
||
// Connection URL | ||
const url = config.mongoUrl; | ||
const connect = mongoose.connect(url, { | ||
useNewUrlParser: true, | ||
useCreateIndex: true, | ||
useUnifiedTopology: true | ||
}); | ||
|
||
connect.then((db) => { | ||
console.log("Connected correctly to server"); | ||
}, (err) => { console.log(err); }); | ||
|
||
var app = express(); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'pug'); | ||
|
||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(passport.initialize()); | ||
|
||
app.use('/', index); | ||
app.use('/users', userRouter); | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))); // serves static data from public folder | ||
|
||
app.use('/dishes', dishRouter); | ||
app.use('/promotions', promoRouter); | ||
app.use('/leaders', leaderRouter); | ||
|
||
// error handler | ||
app.use(function (err, request, response, next) { | ||
// set locals, only providing error in development | ||
response.locals.message = err.message; | ||
response.locals.error = request.app.get('env') === 'development' ? err : {}; | ||
|
||
// render the error page | ||
response.status(err.status || 500); | ||
response.render('error'); | ||
}); | ||
|
||
module.exports = app; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const passport = require('passport'); | ||
const LocalStrategy = require('passport-local').Strategy; | ||
const User = require('./models/user'); | ||
const JwtStrategy = require('passport-jwt').Strategy; | ||
const ExtractJwt = require('passport-jwt').ExtractJwt; | ||
const jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens | ||
|
||
const config = require('./config.js'); | ||
|
||
passport.use(new LocalStrategy(User.authenticate())); | ||
passport.serializeUser(User.serializeUser()); | ||
passport.deserializeUser(User.deserializeUser()); | ||
|
||
exports.getToken = (user) => { | ||
return jwt.sign(user, config.secretKey, | ||
{ expiresIn: 3600 }); | ||
}; | ||
|
||
var opts = {}; | ||
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken(); | ||
opts.secretOrKey = config.secretKey; | ||
|
||
exports.jwtPassport = passport.use(new JwtStrategy(opts, | ||
(jwt_payload, done) => { | ||
console.log("JWT payload: ", jwt_payload); | ||
User.findOne({ _id: jwt_payload._id }, (err, user) => { | ||
if (err) { | ||
return done(err, false); | ||
} | ||
else if (user) { | ||
return done(null, user); | ||
} | ||
else { | ||
return done(null, false); | ||
} | ||
}); | ||
})); | ||
|
||
exports.verifyUser = passport.authenticate('jwt', { session: false }); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app'); | ||
var debug = require('debug')('confusionserver:server'); | ||
var http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || '3000'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
|
||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
|
||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' | ||
? 'Pipe ' + port | ||
: 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'secretKey': '12345-67890-09876-54321', | ||
'mongoUrl' : 'mongodb://localhost:27017/conFusion' | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
require('mongoose-currency').loadType(mongoose); | ||
var Currency = mongoose.Types.Currency; | ||
|
||
var commentSchema = new Schema({ | ||
rating: { | ||
type: Number, | ||
min: 1, | ||
max: 5, | ||
required: true | ||
}, | ||
comment: { | ||
type: String, | ||
required: true | ||
}, | ||
author: { | ||
type: String, | ||
required: true | ||
} | ||
}, { | ||
timestamps: true | ||
}); | ||
|
||
var dishSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
image: { | ||
type: String, | ||
required: true | ||
}, | ||
category: { | ||
type: String, | ||
required: true | ||
}, | ||
label: { | ||
type: String, | ||
default: '' | ||
}, | ||
price: { | ||
type: Currency, | ||
required: true, | ||
min: 0 | ||
}, | ||
featured: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
comments: [commentSchema] | ||
}, { | ||
timestamps: true | ||
}); | ||
var Dishes = mongoose.model('Dish', dishSchema); | ||
|
||
module.exports = Dishes; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
var leaderSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
image: { | ||
type: String, | ||
required: true | ||
}, | ||
designation: { | ||
type: String, | ||
required: true | ||
}, | ||
abbr: { | ||
type: String, | ||
required: true | ||
}, | ||
featured: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, { | ||
timestamps: true | ||
}); | ||
var Leaders = mongoose.model('Leader', leaderSchema); | ||
|
||
module.exports = Leaders; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
require('mongoose-currency').loadType(mongoose); | ||
var Currency = mongoose.Types.Currency; | ||
|
||
var promotionSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
image: { | ||
type: String, | ||
required: true | ||
}, | ||
label: { | ||
type: String, | ||
default: '' | ||
}, | ||
price: { | ||
type: Currency, | ||
required: true, | ||
min: 0 | ||
}, | ||
featured: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, { | ||
timestamps: true | ||
}); | ||
var Promotions = mongoose.model('Promotion', promotionSchema); | ||
|
||
module.exports = Promotions; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
const passportLocalMongoose = require('passport-local-mongoose'); | ||
|
||
const User = new Schema({ | ||
admin: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}); | ||
User.plugin(passportLocalMongoose); | ||
|
||
module.exports = mongoose.model('User', User); |
Oops, something went wrong.