diff --git a/README.md b/README.md new file mode 100644 index 0000000..33f7795 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Article Knowledgebase Application + +This is a knowledgebase app used in the "Node.js & Express From Scratch" Youtube series. + +## Technologies +* Node.js +* Express +* Express Messages, Session, Connect Flash & Validation +* MongoDB & Mongoose +* Pug Templating +* Passport.js Authentication +* BCrypt Hashing + +### Version +2.0.0 + +## Usage + + +### Installation + +Install the dependencies + +```sh +$ npm install +``` +Run app + +```sh +$ npm start +``` diff --git a/app.js b/app.js new file mode 100644 index 0000000..e55487e --- /dev/null +++ b/app.js @@ -0,0 +1,83 @@ +const express = require('express'); +const path = require('path'); +const expressHbs = require('express-handlebars'); +const mongoose = require('mongoose'); +const bodyParser = require('body-parser'); +const expressValidator = require('express-validator'); +const session = require('express-session'); +const passport = require('passport'); +const hbs = require('handlebars'); +const moment = require('moment'); + +mongoose.connect('mongodb://localhost:27017/roomsdb'); +//================================================================================================ +const app = express(); +app.set('views',path.join(__dirname,'views')) +app.engine('.hbs', expressHbs({defaultLayout: 'layout', extname: '.hbs'})); +app.set('view engine', '.hbs'); +//HANDLEBARS====================================================================================== +hbs.registerHelper('ifEquals', function(a, b, options) { + if (a === b) { + return options.fn(this); + } + return options.inverse(this); +}); +//================================================================================================ +app.use(bodyParser.urlencoded({ extended: false })); +app.use(bodyParser.json()); +app.use(express.static('public')); +//EXPRESS-SESSION================================================================================= +app.use(session({ + secret: 'keyboard cat', + resave: true, + saveUninitialized: true +})); + +app.use(function (req, res, next) { + res.locals.messages = require('express-messages')(req, res); + next(); +}); + +app.use(expressValidator({ + errorFormatter: function(param, msg, value) { + var namespace = param.split('.') + , root = namespace.shift() + , formParam = root; + + while(namespace.length) { + formParam += '[' + namespace.shift() + ']'; + } + return { + param : formParam, + msg : msg, + value : value + }; + } +})); +//PASSPORT======================================================================================== +require('./config/passport')(passport); +app.use(passport.initialize()); +app.use(passport.session()); +app.get('*', function(req, res, next){ + res.locals.user = req.user || null; + next(); +}); +//================================================================================================ +let index = require('./routes/index'); +let users = require('./routes/users'); +let rooms = require('./routes/rooms'); +let admin = require('./routes/admin'); +app.use('/', index); +app.use('/user', users); +app.use('/room', rooms); +app.use('/admin', admin); +//================================================================================================ +app.post('/endpoint', function(req, res){ + var obj = {}; + console.log('body: ' + JSON.stringify(req.body)); + res.send(req.body); +}); + +app.listen(3000, function(){ + console.log('Server started on port 3000...'); +}); \ No newline at end of file diff --git a/config/config.js b/config/config.js new file mode 100644 index 0000000..6efec22 --- /dev/null +++ b/config/config.js @@ -0,0 +1,8 @@ +module.exports = { + database:'mongodb://localhost:27017/roomsdb', + eservice: 'gmail', + esecret: 'asdf1093KMnzxcvnkljvasdu09123nlasdasdf', + email: 'nenor96test@gmail.com', + epass: 'somethingwrong' + } + \ No newline at end of file diff --git a/config/passport.js b/config/passport.js new file mode 100644 index 0000000..02ad7ed --- /dev/null +++ b/config/passport.js @@ -0,0 +1,34 @@ +const LocalStrategy = require('passport-local').Strategy; +const User = require('../models/user'); +const bcrypt = require('bcryptjs'); + +module.exports = function(passport){ + passport.use(new LocalStrategy(function(username, password, done){ + let query = {username:username}; + User.findOne(query, function(err, user){ + if(err) throw err; + if(!user){ + return done(null, false, {message: 'No user found'}); + } + + bcrypt.compare(password, user.password, function(err, isMatch){ + if(err) throw err; + if(isMatch){ + return done(null, user); + } else { + return done(null, false, {message: 'Wrong password'}); + } + }); + }); + })); + + passport.serializeUser(function(user, done) { + done(null, user.id); + }); + + passport.deserializeUser(function(id, done) { + User.findById(id, function(err, user) { + done(err, user); + }); + }); +} diff --git a/models/reservation.js b/models/reservation.js new file mode 100644 index 0000000..48244e6 --- /dev/null +++ b/models/reservation.js @@ -0,0 +1,12 @@ +const mongoose = require('mongoose'); +// const User = require('../models/user'); + +const ReservationSchema = new mongoose.Schema({ + user: { type: mongoose.Schema.Types.ObjectId, required: true}, + room: { type: mongoose.Schema.Types.ObjectId, required: true}, + from: { type: String, required: true}, + to: { type: String, required: true}, + state: {type: Number, required: true} +}); + +const Reservation = module.exports = mongoose.model('Reservation', ReservationSchema); \ No newline at end of file diff --git a/models/room.js b/models/room.js new file mode 100644 index 0000000..bba9e61 --- /dev/null +++ b/models/room.js @@ -0,0 +1,14 @@ +const mongoose = require('mongoose'); + +const RoomSchema = new mongoose.Schema({ + type:{ type: String, required: true }, + number:{ type: Number, required: true }, + beds:{ type: Number, required: true }, + capacity:{ type: Number, required: true }, + cost:{ type: Number, required: true }, + reservation: [ {type: mongoose.Schema.Types.ObjectId, required: false} ], + img: { type: String, required: true }, + images: [ {type: String, required: false} ] +}); + +const Room = module.exports = mongoose.model('Room', RoomSchema); diff --git a/models/user.js b/models/user.js new file mode 100644 index 0000000..8e848e0 --- /dev/null +++ b/models/user.js @@ -0,0 +1,12 @@ +const mongoose = require('mongoose'); + +const UserSchema = mongoose.Schema({ + name:{ type: String, required: true }, + email:{ type: String, required: true }, + username:{ type: String, required: true }, + password:{ type: String, required: true }, + admin:{ type: Boolean, required: false }, + img:{ type: String, required: true } +}); + +const User = module.exports = mongoose.model('User', UserSchema); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..47dd9cd --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1251 @@ +{ + "name": "simpleapp", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/bluebird": { + "version": "3.5.20", + "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.20.tgz", + "integrity": "sha512-Wk41MVdF+cHBfVXj/ufUHJeO3BlIQr1McbHZANErMykaCWeDSZbH5erGjNBw2/3UlRdSxZbLfSuQTzFmPOYFsA==" + }, + "@types/body-parser": { + "version": "1.16.8", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.16.8.tgz", + "integrity": "sha512-BdN2PXxOFnTXFcyONPW6t0fHjz2fvRZHVMFpaS0wYr+Y8fWEaNOs4V8LEu/fpzQlMx+ahdndgTaGTwPC+J/EeA==", + "requires": { + "@types/express": "4.0.39", + "@types/node": "9.6.2" + } + }, + "@types/events": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", + "integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==" + }, + "@types/express": { + "version": "4.0.39", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.0.39.tgz", + "integrity": "sha512-dBUam7jEjyuEofigUXCtublUHknRZvcRgITlGsTbFgPvnTwtQUt2NgLakbsf+PsGo/Nupqr3IXCYsOpBpofyrA==", + "requires": { + "@types/body-parser": "1.16.8", + "@types/express-serve-static-core": "4.11.1", + "@types/serve-static": "1.13.1" + } + }, + "@types/express-serve-static-core": { + "version": "4.11.1", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.11.1.tgz", + "integrity": "sha512-EehCl3tpuqiM8RUb+0255M8PhhSwTtLfmO7zBBdv0ay/VTd/zmrqDfQdZFsa5z/PVMbH2yCMZPXsnrImpATyIw==", + "requires": { + "@types/events": "1.2.0", + "@types/node": "9.6.2" + } + }, + "@types/mime": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.0.tgz", + "integrity": "sha512-A2TAGbTFdBw9azHbpVd+/FkdW2T6msN1uct1O9bH3vTerEHKZhTXJUQXy+hNq1B0RagfU8U+KBdqiZpxjhOUQA==" + }, + "@types/node": { + "version": "9.6.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.2.tgz", + "integrity": "sha512-UWkRY9X7RQHp5OhhRIIka58/gVVycL1zHZu0OTsT5LI86ABaMOSbUjAl+b0FeDhQcxclrkyft3kW5QWdMRs8wQ==" + }, + "@types/serve-static": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.1.tgz", + "integrity": "sha512-jDMH+3BQPtvqZVIcsH700Dfi8Q3MIcEx16g/VdxjoqiGR/NntekB10xdBpirMKnPe9z2C5cBmL0vte0YttOr3Q==", + "requires": { + "@types/express-serve-static-core": "4.11.1", + "@types/mime": "2.0.0" + } + }, + "accepts": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", + "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", + "requires": { + "mime-types": "2.1.18", + "negotiator": "0.6.1" + } + }, + "align-text": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", + "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", + "requires": { + "kind-of": "3.2.2", + "longest": "1.0.1", + "repeat-string": "1.6.1" + } + }, + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" + }, + "append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY=" + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" + }, + "async": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.1.4.tgz", + "integrity": "sha1-LSFgx3iAMuTdbL4lAvH5osj2zeQ=", + "requires": { + "lodash": "4.17.5" + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "bcryptjs": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", + "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms=" + }, + "bluebird": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", + "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" + }, + "body-parser": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", + "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "1.0.4", + "debug": "2.6.9", + "depd": "1.1.2", + "http-errors": "1.6.3", + "iconv-lite": "0.4.19", + "on-finished": "2.3.0", + "qs": "6.5.1", + "raw-body": "2.3.2", + "type-is": "1.6.16" + } + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "bson": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.6.tgz", + "integrity": "sha512-D8zmlb46xfuK2gGvKmUjIklQEouN2nQ0LEHHeZ/NoHM2LDiMk2EYzZ5Ntw/Urk+bgMDosOZxaRzXxvhI5TcAVQ==" + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" + }, + "busboy": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz", + "integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=", + "requires": { + "dicer": "0.2.5", + "readable-stream": "1.1.14" + } + }, + "bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + }, + "camelcase": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", + "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", + "optional": true + }, + "center-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", + "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", + "optional": true, + "requires": { + "align-text": "0.1.4", + "lazy-cache": "1.0.4" + } + }, + "cliui": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", + "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", + "optional": true, + "requires": { + "center-align": "0.1.3", + "right-align": "0.1.3", + "wordwrap": "0.0.2" + }, + "dependencies": { + "wordwrap": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", + "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", + "optional": true + } + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "requires": { + "buffer-from": "1.1.1", + "inherits": "2.0.3", + "readable-stream": "2.3.6", + "typedarray": "0.0.6" + }, + "dependencies": { + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.1", + "string_decoder": "1.1.1", + "util-deprecate": "1.0.2" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "5.1.1" + } + } + } + }, + "connect-flash": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/connect-flash/-/connect-flash-0.1.1.tgz", + "integrity": "sha1-2GMPJtlaf4UfmVax6MxnMvO2qjA=" + }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "crc": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz", + "integrity": "sha1-naHpgOO9RPxck79as9ozeNheRms=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "optional": true + }, + "define-properties": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz", + "integrity": "sha1-g6c/L+pWmJj7c3GTyPhzyvbUXJQ=", + "requires": { + "foreach": "2.0.5", + "object-keys": "1.0.11" + } + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "dicer": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz", + "integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=", + "requires": { + "readable-stream": "1.1.14", + "streamsearch": "0.1.2" + } + }, + "ecdsa-sig-formatter": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz", + "integrity": "sha1-HFlQAPBKiJffuFAAiSoPTDOvhsM=", + "requires": { + "safe-buffer": "5.1.1" + } + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "express": { + "version": "4.16.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.16.3.tgz", + "integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=", + "requires": { + "accepts": "1.3.5", + "array-flatten": "1.1.1", + "body-parser": "1.18.2", + "content-disposition": "0.5.2", + "content-type": "1.0.4", + "cookie": "0.3.1", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "1.1.2", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "finalhandler": "1.1.1", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "1.1.2", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "path-to-regexp": "0.1.7", + "proxy-addr": "2.0.3", + "qs": "6.5.1", + "range-parser": "1.2.0", + "safe-buffer": "5.1.1", + "send": "0.16.2", + "serve-static": "1.13.2", + "setprototypeof": "1.1.0", + "statuses": "1.4.0", + "type-is": "1.6.16", + "utils-merge": "1.0.1", + "vary": "1.1.2" + }, + "dependencies": { + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" + } + } + }, + "express-handlebars": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/express-handlebars/-/express-handlebars-3.0.0.tgz", + "integrity": "sha1-gKBwu4GbCeSvLKbQeA91zgXnXC8=", + "requires": { + "glob": "6.0.4", + "graceful-fs": "4.1.11", + "handlebars": "4.0.11", + "object.assign": "4.1.0", + "promise": "7.3.1" + } + }, + "express-messages": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/express-messages/-/express-messages-1.0.1.tgz", + "integrity": "sha1-mYGoWl0rEYx5/DP1K0GDT/7paFo=" + }, + "express-session": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.15.6.tgz", + "integrity": "sha512-r0nrHTCYtAMrFwZ0kBzZEXa1vtPVrw0dKvGSrKP4dahwBQ1BJpF2/y1Pp4sCD/0kvxV4zZeclyvfmw0B4RMJQA==", + "requires": { + "cookie": "0.3.1", + "cookie-signature": "1.0.6", + "crc": "3.4.4", + "debug": "2.6.9", + "depd": "1.1.2", + "on-headers": "1.0.1", + "parseurl": "1.3.2", + "uid-safe": "2.1.5", + "utils-merge": "1.0.1" + } + }, + "express-validator": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/express-validator/-/express-validator-3.2.1.tgz", + "integrity": "sha1-RWA+fu5pMYXCGY+969QUkl/9NSQ=", + "requires": { + "@types/bluebird": "3.5.20", + "@types/express": "4.0.39", + "bluebird": "3.5.1", + "lodash": "4.17.5", + "validator": "6.2.1" + } + }, + "finalhandler": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", + "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", + "requires": { + "debug": "2.6.9", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "statuses": "1.4.0", + "unpipe": "1.0.0" + }, + "dependencies": { + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" + } + } + }, + "foreach": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" + }, + "forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "glob": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", + "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", + "requires": { + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "handlebars": { + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", + "integrity": "sha1-Ywo13+ApS8KB7a5v/F0yn8eYLcw=", + "requires": { + "async": "1.5.2", + "optimist": "0.6.1", + "source-map": "0.4.4", + "uglify-js": "2.8.29" + }, + "dependencies": { + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" + } + } + }, + "has-symbols": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", + "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=" + }, + "http-errors": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", + "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", + "requires": { + "depd": "1.1.2", + "inherits": "2.0.3", + "setprototypeof": "1.1.0", + "statuses": "1.5.0" + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "ipaddr.js": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.6.0.tgz", + "integrity": "sha1-4/o1e3c9phnybpXwSdBVxyeW+Gs=" + }, + "is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "jsonwebtoken": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.4.0.tgz", + "integrity": "sha512-coyXjRTCy0pw5WYBpMvWOMN+Kjaik2MwTUIq9cna/W7NpO9E+iYbumZONAz3hcr+tXFJECoQVrtmIoC3Oz0gvg==", + "requires": { + "jws": "3.2.1", + "lodash.includes": "4.3.0", + "lodash.isboolean": "3.0.3", + "lodash.isinteger": "4.0.4", + "lodash.isnumber": "3.0.3", + "lodash.isplainobject": "4.0.6", + "lodash.isstring": "4.0.1", + "lodash.once": "4.1.1", + "ms": "2.1.1" + }, + "dependencies": { + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + } + } + }, + "jwa": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.2.0.tgz", + "integrity": "sha512-Grku9ZST5NNQ3hqNUodSkDfEBqAmGA1R8yiyPHOnLzEKI0GaCQC/XhFmsheXYuXzFQJdILbh+lYBiliqG5R/Vg==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.10", + "safe-buffer": "5.1.1" + } + }, + "jws": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.1.tgz", + "integrity": "sha512-bGA2omSrFUkd72dhh05bIAN832znP4wOU3lfuXtRBuGTbsmNmDXMQg28f0Vsxaxgk4myF5YkKQpz6qeRpMgX9g==", + "requires": { + "jwa": "1.2.0", + "safe-buffer": "5.1.1" + } + }, + "kareem": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.0.6.tgz", + "integrity": "sha512-/C+l8gABdHsAIfNpykJNWmYodpTnDRyn+JhORkP2VgEf1GgdAc+oTHjVADwISwCJKta031EOIwY6+Hki5z8SpQ==" + }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "requires": { + "is-buffer": "1.1.6" + } + }, + "lazy-cache": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", + "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", + "optional": true + }, + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, + "longest": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", + "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", + "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" + }, + "mime-db": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", + "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==" + }, + "mime-types": { + "version": "2.1.18", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", + "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==", + "requires": { + "mime-db": "1.33.0" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + } + } + }, + "moment": { + "version": "2.22.2", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz", + "integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y=" + }, + "mongodb": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.6.tgz", + "integrity": "sha512-nEg7SnzcyobArDTXEqvI1BasY6Z45h1lyBtVMCS9gRTkbtwrDn6WcLRa+MVRYufrJXxQPkAiYJQ94eCUzit0EQ==", + "requires": { + "mongodb-core": "3.0.6" + } + }, + "mongodb-core": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.6.tgz", + "integrity": "sha512-EIaEyA4DEft4je4Hfa+CDswKdFhlev9V9o5KJo/nITgG6KNKz5Rxg5ZuMGEjGkMwFkydFQ3Kz0CxZ18AXhRrEg==", + "requires": { + "bson": "1.0.6", + "require_optional": "1.0.1" + } + }, + "mongoose": { + "version": "5.0.15", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.0.15.tgz", + "integrity": "sha512-S37I7V8nZE7JgPExgqb7zOKqezhvQP3JNa60rQEfVESvPkuan2gk/KoYeww7UK/gkKii8mR7OLyuzfRTa7rxxQ==", + "requires": { + "async": "2.1.4", + "bson": "1.0.6", + "kareem": "2.0.6", + "lodash.get": "4.4.2", + "mongodb": "3.0.6", + "mongoose-legacy-pluralize": "1.0.2", + "mpath": "0.4.1", + "mquery": "3.0.0", + "ms": "2.0.0", + "regexp-clone": "0.0.1", + "sliced": "1.0.1" + } + }, + "mongoose-legacy-pluralize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", + "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==" + }, + "mpath": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.4.1.tgz", + "integrity": "sha512-NNY/MpBkALb9jJmjpBlIi6GRoLveLUM0pJzgbp9vY9F7IQEb/HREC/nxrixechcQwd1NevOhJnWWV8QQQRE+OA==" + }, + "mquery": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.0.0.tgz", + "integrity": "sha512-WL1Lk8v4l8VFSSwN3yCzY9TXw+fKVYKn6f+w86TRzOLSE8k1yTgGaLBPUByJQi8VcLbOdnUneFV/y3Kv874pnQ==", + "requires": { + "bluebird": "3.5.0", + "debug": "2.6.9", + "regexp-clone": "0.0.1", + "sliced": "0.0.5" + }, + "dependencies": { + "bluebird": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", + "integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=" + }, + "sliced": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz", + "integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8=" + } + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "multer": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.1.tgz", + "integrity": "sha512-zzOLNRxzszwd+61JFuAo0fxdQfvku12aNJgnla0AQ+hHxFmfc/B7jBVuPr5Rmvu46Jze/iJrFpSOsD7afO8SDw==", + "requires": { + "append-field": "1.0.0", + "busboy": "0.2.14", + "concat-stream": "1.6.2", + "mkdirp": "0.5.1", + "object-assign": "4.1.1", + "on-finished": "2.3.0", + "type-is": "1.6.16", + "xtend": "4.0.1" + } + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, + "nodemailer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-5.1.1.tgz", + "integrity": "sha512-hKGCoeNdFL2W7S76J/Oucbw0/qRlfG815tENdhzcqTpSjKgAN91mFOqU2lQUflRRxFM7iZvCyaFcAR9noc/CqQ==" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "object-keys": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.11.tgz", + "integrity": "sha1-xUYBd4rVYPEULODgG8yotW0TQm0=" + }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "requires": { + "define-properties": "1.1.2", + "function-bind": "1.1.1", + "has-symbols": "1.0.0", + "object-keys": "1.0.11" + } + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "on-headers": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz", + "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1.0.2" + } + }, + "optimist": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", + "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "requires": { + "minimist": "0.0.10", + "wordwrap": "0.0.3" + } + }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, + "passport": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.3.2.tgz", + "integrity": "sha1-ndAJ+RXo/glbASSgG4+C2gdRAQI=", + "requires": { + "passport-strategy": "1.0.0", + "pause": "0.0.1" + } + }, + "passport-local": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/passport-local/-/passport-local-1.0.0.tgz", + "integrity": "sha1-H+YyaMkudWBmJkN+O5BmYsFbpu4=", + "requires": { + "passport-strategy": "1.0.0" + } + }, + "passport-strategy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", + "integrity": "sha1-tVOaqPwiWj0a0XlHbd8ja0QPUuQ=" + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10=" + }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" + }, + "promise": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", + "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", + "requires": { + "asap": "2.0.6" + } + }, + "proxy-addr": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.3.tgz", + "integrity": "sha512-jQTChiCJteusULxjBp8+jftSQE5Obdl3k4cnmLA6WXtK6XFuWRnvVL7aCiBqaLPM8c4ph0S4tKna8XvmIwEnXQ==", + "requires": { + "forwarded": "0.1.2", + "ipaddr.js": "1.6.0" + } + }, + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + }, + "random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs=" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "raw-body": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", + "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "unpipe": "1.0.0" + }, + "dependencies": { + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "requires": { + "depd": "1.1.1", + "inherits": "2.0.3", + "setprototypeof": "1.0.3", + "statuses": "1.5.0" + } + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + } + } + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "0.0.1", + "string_decoder": "0.10.31" + } + }, + "regexp-clone": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz", + "integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk=" + }, + "repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" + }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", + "requires": { + "resolve-from": "2.0.0", + "semver": "5.5.0" + } + }, + "resolve-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", + "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" + }, + "right-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", + "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", + "optional": true, + "requires": { + "align-text": "0.1.4" + } + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + }, + "send": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", + "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", + "requires": { + "debug": "2.6.9", + "depd": "1.1.2", + "destroy": "1.0.4", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "fresh": "0.5.2", + "http-errors": "1.6.3", + "mime": "1.4.1", + "ms": "2.0.0", + "on-finished": "2.3.0", + "range-parser": "1.2.0", + "statuses": "1.4.0" + }, + "dependencies": { + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" + } + } + }, + "serve-static": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", + "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", + "requires": { + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "parseurl": "1.3.2", + "send": "0.16.2" + } + }, + "setprototypeof": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", + "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" + }, + "sliced": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", + "integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E=" + }, + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "requires": { + "amdefine": "1.0.1" + } + }, + "statuses": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" + }, + "streamsearch": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz", + "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=" + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "type-is": { + "version": "1.6.16", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", + "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "2.1.18" + } + }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" + }, + "uglify-js": { + "version": "2.8.29", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", + "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "optional": true, + "requires": { + "source-map": "0.5.7", + "uglify-to-browserify": "1.0.2", + "yargs": "3.10.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "optional": true + } + } + }, + "uglify-to-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", + "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", + "optional": true + }, + "uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==", + "requires": { + "random-bytes": "1.0.0" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + }, + "validator": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/validator/-/validator-6.2.1.tgz", + "integrity": "sha1-vFdbeNFb6y4zimZbqVMMf0Ce9mc=" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + }, + "window-size": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", + "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", + "optional": true + }, + "wordwrap": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", + "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + }, + "yargs": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", + "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", + "optional": true, + "requires": { + "camelcase": "1.2.1", + "cliui": "2.1.0", + "decamelize": "1.2.0", + "window-size": "0.1.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..114e641 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "simpleapp", + "version": "1.0.0", + "description": "Simple knowledgebase app", + "main": "app.js", + "scripts": { + "start": "node app" + }, + "author": "Nedeljko Ružić", + "license": "ISC", + "dependencies": { + "bcryptjs": "^2.4.3", + "body-parser": "^1.17.2", + "connect-flash": "^0.1.1", + "express": "^4.15.3", + "express-handlebars": "^3.0.0", + "express-messages": "^1.0.1", + "express-session": "^1.15.3", + "express-validator": "^3.2.0", + "handlebars": "^4.0.11", + "jsonwebtoken": "^8.4.0", + "moment": "^2.22.2", + "mongoose": "^5.0.15", + "multer": "^1.4.1", + "nodemailer": "^5.1.1", + "passport": "^0.3.2", + "passport-local": "^1.0.0" + } +} diff --git a/public/images/profiles/1550341200213-download.jpg b/public/images/profiles/1550341200213-download.jpg new file mode 100644 index 0000000..b0e14f8 Binary files /dev/null and b/public/images/profiles/1550341200213-download.jpg differ diff --git a/public/images/room.jpg b/public/images/room.jpg new file mode 100644 index 0000000..19be12c Binary files /dev/null and b/public/images/room.jpg differ diff --git a/public/images/rooms/jednokrevetna-img1.jpg b/public/images/rooms/jednokrevetna-img1.jpg new file mode 100644 index 0000000..9f9dde1 Binary files /dev/null and b/public/images/rooms/jednokrevetna-img1.jpg differ diff --git a/public/images/rooms/jednokrevetna-img2.jpg b/public/images/rooms/jednokrevetna-img2.jpg new file mode 100644 index 0000000..61b72ed Binary files /dev/null and b/public/images/rooms/jednokrevetna-img2.jpg differ diff --git a/public/js/main.js b/public/js/main.js new file mode 100644 index 0000000..e2a3aef --- /dev/null +++ b/public/js/main.js @@ -0,0 +1,17 @@ +$(document).ready(function(){ + $('.delete-user').on('click', function(e){ + $target = $(e.target); + const id = $target.attr('data-id'); + $.ajax({ + type:'DELETE', + url: '/user/'+id, + success: function(response){ + alert('deleting user'); + window.location.href='/'; + }, + error: function(err){ + console.log(err); + } + }); + }); +}); diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css new file mode 100644 index 0000000..2a81f04 --- /dev/null +++ b/public/stylesheets/style.css @@ -0,0 +1,88 @@ +body { + background-image: url("https://carrickswan.com/wp-content/uploads/2016/04/site-background.jpg"); + height: auto; + background-position: center; + background-repeat: no-repeat; + background-size: cover; +} + +.footer { + margin-top: 10px; + border-radius: 0px; + border: none; + border-top: 3px solid rgb(79, 171, 233); + border-color: rgb(79, 171, 233); + background-color: rgb(255, 255, 255); +} + +.navbar { + border-radius: 10px; + border: none; + border-bottom: 3px solid rgb(79, 171, 233); + border-color: rgb(79, 171, 233); + background-color: rgb(255, 255, 255); +} + +.card { + width: 190px; + margin-left: 10px; + margin-top: 20px; + border-style: solid; + border-color: rgb(79, 171, 233); + background-color: rgba(255, 255, 255, 0.808); +} + +.card img { + height: 150px; +} + +a { + color: #000000; +} + +a:hover { + color: rgb(79, 171, 233); + text-decoration: none; +} + + +.wrapper { + margin-top: 80px; + margin-bottom: 80px; +} + +.form-signin { + max-width: 380px; + padding: 15px 35px 45px; + margin: 0 auto; + background-color: #fff; + border: 1px solid rgba(0,0,0,0.1); +} + + .form-signin-heading, + .checkbox { + margin-bottom: 30px; + } + + .checkbox { + font-weight: normal; + } + + .form-control { + position: relative; + font-size: 16px; + height: auto; + padding: 10px; + } + + input[type="text"] { + margin-bottom: -1px; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + } + + input[type="password"] { + margin-bottom: 20px; + border-top-left-radius: 0; + border-top-right-radius: 0; + } diff --git a/routes/admin.js b/routes/admin.js new file mode 100644 index 0000000..f444a14 --- /dev/null +++ b/routes/admin.js @@ -0,0 +1,75 @@ +const express = require('express'); +const router = express.Router(); +const fs = require('fs'), path = require('path'); +const Room = require('../models/room'); +const Reservation = require('../models/reservation'); + +router.get('/', ensureAuthenticated, function (err, res) { + Room.find({}, function (err, room) { + if (err) return res.send('no rooms found'); + Reservation.find({}, function (err, reservation) { + if (err) return res.send('something went wrong'); + if (!reservation) return res.send('no reservations found'); + res.render("admin", { rooms: room, reservation: reservation }); + }); + }); +}); +//================================================================================================ +router.get('/room', ensureAuthenticated, function (req, res) { + res.render("rooms/add_room"); +}); + +router.post('/room', ensureAuthenticated, function (req, res) { + Room.count().then((count) => { + let newRoom = new Room({ + number: count + 1, + beds: req.body.beds, + capacity: req.body.capacity, + cost: req.body.cost, + type: req.body.type, + }); + fromDir('./public/images/rooms', req.body.type).then(function (imgs) { + imgs.map(function (img) { + img = img.replace(/\\/g, "/").replace(/public/g, "") + if (img.includes("img1")) { newRoom.img = img; } + else { newRoom.images.push(img); } + }); + }).then(newRoom.save(function (err) { + if (err) { console.log(err); return; } + else { res.redirect('/room/reservation/' + newRoom._id); } + })); + }); +}); +//================================================================================================ +function fromDir(startPath, filter) { + if (!fs.existsSync(startPath)) { + console.log("no dir ", startPath); + return; + } + var data = []; + var files = fs.readdirSync(startPath); + for (var i = 0; i < files.length; i++) { + var filename = path.join(startPath, files[i]); + var stat = fs.lstatSync(filename); + if (stat.isDirectory()) { + fromDir(filename, filter); + } + else if (filename.indexOf(filter) >= 0) { + data.push(filename); + }; + }; + return new Promise((resolve, reject) => { + resolve(data); + }); +} + + +function ensureAuthenticated(req, res, next) { + if (req.isAuthenticated()) { + return next(); + } else { + res.redirect('/user/login'); + } +} + +module.exports = router; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..325ec93 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,37 @@ +const express = require('express'); +const router = express.Router(); +const jwt = require('jsonwebtoken'); +const Room = require('../models/room'); +const Reservation = require('../models/reservation'); +const config = require('../config/config'); +router.get('/', function(req, res) { + Room.find({}, function(err, room) { + if(err) return res.send('no rooms found'); + var sobe = []; + var mjera = 3; + for (var i = 0; i < room.length; i += mjera) { + sobe.push(room.slice(i, i + mjera)); + } + res.render("index", { rooms: sobe }); + }); +}); + +router.get('/confirmation/:token', ensureAuthenticated, function(req, res) { + jwt.verify(req.params.token, config.esecret, function(err, tok) { + if(err) throw err; + Reservation.findByIdAndUpdate(tok.reserv, { state: 1 }, function(err, reserv){ + res.redirect('/user/profile/' + req.user._id); + }); + }); +}); + + +function ensureAuthenticated(req, res, next){ + if(req.isAuthenticated()){ + return next(); + } else { + res.redirect('/user/login'); + } + } + +module.exports = router; \ No newline at end of file diff --git a/routes/rooms.js b/routes/rooms.js new file mode 100644 index 0000000..7569949 --- /dev/null +++ b/routes/rooms.js @@ -0,0 +1,209 @@ +const express = require('express'); +const router = express.Router(); +const moment = require('moment'); +const nodemailer = require('nodemailer'); +const jwt = require('jsonwebtoken'); +const Room = require('../models/room'); +const Reservation = require('../models/reservation'); +const config = require('../config/config'); +//================================================================================================ +router.get('/reservation/:id', function (req, res) { + Room.findById(req.params.id).exec(function (err, room) { + if (err) throw err; + if (!room) return res.send('room doesnt exist'); + var state = false; + var imgs = []; + room.images.forEach(element => { + imgs.push(element); + }); + if (!req.query.start && !req.query.end) { + res.render('rooms/room', { room: room, state: state, imgs: imgs }); + } + else { + state = true; + res.render('rooms/room', { room: room, state: state, imgs: imgs, start: req.query.start, end: req.query.end }); + } + }); +}); + +router.post('/reservation', ensureAuthenticated, function (req, res) { + var start = req.body.start.split("-").reverse().join("-"); + var end = req.body.end.split("-").reverse().join("-"); + var brRez = 0, bezRez = 0; + Room.findById(req.body.room, function (err, room) { + if (room.reservation.length > 0) { + Reservation.find({ room: room._id, state: { $gt: 0 } }, function (err, reservs) { + brRez += reservs.length; + }).then(reservs => reservs.map(function (reserv) { + var date = dateRange(start, end, reserv.from, reserv.to); + if (date == true) { + res.send("zauzeta"); + return true; + } + else { + bezRez++; + } + console.log(brRez + " " + bezRez); + if (bezRez == brRez) { + arrangeReservation(room, req.user, start, end); + res.send("go and check your email to confirm reservation"); + } + })); + } + else { + arrangeReservation(room, req.user, start, end); + res.send("go and check your email to confirm reservation"); + } + }); +}); +//================================================================================================ +router.get('/search', function (req, res) { + res.render("rooms/ser_room"); +}); + +router.post('/search', function (req, res) { + var start = req.body.start.split("-").reverse().join("-"); + var end = req.body.end.split("-").reverse().join("-"); + var soba = 0, load = 0, brRez = 0, bezRez = 0; + var arr = []; + Room.find({}).exec().then(rooms => rooms.map(function (room) { + if (room.reservation.length > 0) { + soba++; + Reservation.find({ room: room._id, state: { $gt: 0 } }, function (err, reservs) { + soba--; brRez += reservs.length; + }).then(reservs => reservs.map(function (reserv) { + var date = dateRange(start, end, reserv.from, reserv.to); + if (date == true) { + load++; + arr.push(room._id); + } + else { + if (calculateDays(reserv.to, getFormattedDate(new Date())) > 0) { + reserv.state = 0; + reserv.save(function (err) { + if (err) throw err; + }); + } + bezRez++; + } + console.log(brRez + " " + load + " " + bezRez); + if (load + bezRez == brRez && soba == 0) { + var unique = arr.filter(onlyUnique); + getData(rooms, unique).then(function (val) { + var sobe = [], mjera = 3; + for (var i = 0; i < val.length; i += mjera) { + sobe.push(val.slice(i, i + mjera)); + } + res.render("rooms/ser_rooms", { rooms: sobe, start: req.body.start, end: req.body.end }); + }); + } + })); + } + })); +}); +//=============================================================================================== +function getData(rooms, ids) { + return new Promise((resolve, reject) => { + ids.map(function (num) { + var sob = findIndexByID(rooms, num); + rooms.splice(sob, 1); + }); + resolve(rooms); + }); +} + +function onlyUnique(value, index, self) { + return self.indexOf(value) === index; +} + +function arrangeReservation(room, user, start, end) { + let reservation = new Reservation({ + user: user._id, + room: room._id, + from: start, + to: end, + state: 2, + }); + room.reservation.push(reservation._id); + reservation.save(function (err) { + if (err) throw error; + room.save(function (err) { + if (err) throw error; + let token = jwt.sign({ username: user.username, reserv: reservation._id }, config.esecret, { expiresIn: '24h' }); + const url = `http://localhost:3000/confirmation/` + token; + mailOptions.text = "Please click this email to confirm your email: " + url; + mailOptions.to = user.email; + transporter.sendMail(mailOptions, function (error, info) { + if (error) { + console.log(error); + } else { + console.log('Email sent: ' + info.response); + } + }); + }); + }); +} + +var transporter = nodemailer.createTransport({ + service: config.eservice, + auth: { + user: config.email, + pass: config.epass + } +}); + +var mailOptions = { + from: config.email, + to: 'nenor1995@gmail.com', + subject: 'Reservation confirmation', + text: '' +}; + +function getFormattedDate(date) { + var year = date.getFullYear(); + var month = (1 + date.getMonth()).toString(); + month = month.length > 1 ? month : '0' + month; + var day = date.getDate().toString(); + day = day.length > 1 ? day : '0' + day; + + return day + '-' + month + '-' + year; +} + +function dateRange(start1, end1, start2, end2) { + var dur = calculateDays(end2, start1); + var dur1 = calculateDays(end1, start2); + if (dur < 0 && dur1 < 0) { + return true; + } + else if (dur > 0) { + return null; + } +} + +function findIndexByID(array, id) { + for (var i = 0; i < array.length; i++) { + if (array[i]._id.equals(id)) { + console.log(i + " " + id); + return i; + } + } + return null; +} + +function calculateDays(startDate, endDate) { + var start_date = moment(startDate, 'DD-MM-YYYY'); + var end_date = moment(endDate, 'DD-MM-YYYY'); + var duration = moment.duration(end_date.diff(start_date)); + var days = duration.asDays(); + return days; +} + +function ensureAuthenticated(req, res, next) { + if (req.isAuthenticated()) { + return next(); + } else { + res.redirect('/user/login'); + } +} + +module.exports = router; \ No newline at end of file diff --git a/routes/users.js b/routes/users.js new file mode 100644 index 0000000..c86c80b --- /dev/null +++ b/routes/users.js @@ -0,0 +1,130 @@ +const express = require('express'); +const router = express.Router(); +const bcrypt = require('bcryptjs'); +const passport = require('passport'); +const multer = require('multer'); +const fs = require('fs'); + +let User = require('../models/user'); + +const storage = multer.diskStorage({ + destination: 'public/images/profiles', + filename: function(req, file, next){ + next(null, Date.now() + '-' + file.originalname); + }, + fileFilter: function (req, file, callback) { + var ext = path.extname(file.originalname); + if(ext !== '.png' && ext !== '.jpg' && ext !== '.gif' && ext !== '.jpeg') { + return callback(new Error('only images are allowed')) + } + callback(null, true) + }, + limits:{ + fileSize: 1024 * 1024 + } +}); + +const upload = multer({ storage: storage}); +//================================================================================================ +router.get('/register', function(req, res){ + res.render('users/register'); +}); + +router.post('/register', function(req, res){ + const name = req.body.name; + const email = req.body.email; + const username = req.body.username; + const password = req.body.password; + + req.checkBody('name', 'Name is required').notEmpty(); + req.checkBody('email', 'Email is required').notEmpty(); + req.checkBody('email', 'Email is not valid').isEmail(); + req.checkBody('username', 'Username is required').notEmpty(); + req.checkBody('password', 'Password is required').notEmpty(); + + let errors = req.validationErrors(); + + if(errors){ + res.render('users/register', { + errors:errors + }); + } else { + let newUser = new User({ + img: "/images/user.png", + name:name, + email:email, + username:username, + password:password + }); + + bcrypt.genSalt(10, function(err, salt){ + bcrypt.hash(newUser.password, salt, function(err, hash){ + if(err){ + console.log(err); + } + newUser.password = hash; + newUser.save(function(err){ + if(err){ + console.log(err); + return; + } else { + res.redirect('/user/login'); + } + }); + }); + }); + } +}); +//================================================================================================ +router.get('/login', function(req, res){ + res.render('users/login'); +}); + +router.post('/login', function(req, res, next){ + passport.authenticate('local', { + successRedirect:'/', + failureRedirect:'/user/login', + failureFlash: true + })(req, res, next); +}); + +router.get('/logout', function(req, res){ + req.logout(); + res.redirect('/user/login'); +}); +//================================================================================================ +router.get('/profile/:id', function(req, res){ + User.findById(req.params.id, function(err, user) + { + if(err) { return console.log("user not found"); } + res.render('users/profile', { users: user}); + }); +}); + +router.post('/profile/:id', upload.single('myImage'), function(req, res){ + let user = new User(); + user = req.user; + user.email = req.body.email; + if(req.file){ + fs.unlink('./public' + user.img, function(err){ + if(err) return console.log(err); + console.log('file deleted successfully'); + }); + var path = req.file.path; + path = path.replace(/\\/g, "/").replace(/public/g, "") + user.img = path; + } + user.admin = true; + + let query = {_id:req.params.id}; + User.update(query, user, function(err){ + if(err){ + console.log(err); return; + } else { + res.redirect('/user/profile/' + query._id); + } + }); +}); + + +module.exports = router; diff --git a/views/admin.hbs b/views/admin.hbs new file mode 100644 index 0000000..9f98160 --- /dev/null +++ b/views/admin.hbs @@ -0,0 +1,46 @@ +
Rooms
+ID | +Number | +Beds | +Cost | +
---|---|---|---|
{{this._id}} | +{{this.number}} | +{{this.beds}} | +{{this.cost}} | +
Reservations
+ID | +Room | +From | +To | +
---|---|---|---|
{{this._id}} | +{{this.room}} | +{{this.from}} | +{{this.to}} | +
{{this.type}}
+{{room.type}}
+{{this.type}}
+{{users.email}}
+