diff options
author | lowercasename <raphaelkabo@gmail.com> | 2019-07-25 17:20:44 +0100 |
---|---|---|
committer | lowercasename <raphaelkabo@gmail.com> | 2019-07-25 17:20:44 +0100 |
commit | 26af40f50b02a487b3eff842fdfc5409477a88d2 (patch) | |
tree | 918c3a67ae3bdad04a271c8aa8af110f36f0caf8 | |
parent | 2675eb32179ad29fb79599c8abb78a9c6bf0825e (diff) |
Many bugfixes
-rwxr-xr-x | .gitignore | 3 | ||||
-rwxr-xr-x | models/User.js | 43 | ||||
-rwxr-xr-x | models/passport.js | 19 | ||||
-rwxr-xr-x | package.json | 3 | ||||
-rw-r--r-- | public/images/-uM2C4w60.jpg | bin | 24435 -> 0 bytes | |||
-rwxr-xr-x | public/images/._example-event.jpg | bin | 4096 -> 0 bytes | |||
-rw-r--r-- | public/images/2aDitGZP0.jpg | bin | 102485 -> 0 bytes | |||
-rw-r--r-- | public/images/2l0j1mgRi.jpg | bin | 38976 -> 0 bytes | |||
-rw-r--r-- | public/images/76r5zFOME.jpg | bin | 83155 -> 0 bytes | |||
-rw-r--r-- | public/images/9nNZLv4SE.jpg | bin | 53092 -> 0 bytes | |||
-rw-r--r-- | public/images/Edl8knpyj.jpg | bin | 28882 -> 0 bytes | |||
-rw-r--r-- | public/images/FgMoe7UH1.jpg | bin | 46625 -> 0 bytes | |||
-rw-r--r-- | public/images/JO-XJd-_8.jpg | bin | 138481 -> 0 bytes | |||
-rw-r--r-- | public/images/KD3IkClNG.jpg | bin | 41279 -> 0 bytes | |||
-rw-r--r-- | public/images/KNvt-8y2G.jpg | bin | 37129 -> 0 bytes | |||
-rw-r--r-- | public/images/KkMmanmXM.jpg | bin | 101168 -> 0 bytes | |||
-rwxr-xr-x | public/images/LX4Iii8T0.jpg | bin | 93425 -> 0 bytes | |||
-rw-r--r-- | public/images/M42Hpaxe-.jpg | bin | 152480 -> 0 bytes | |||
-rwxr-xr-x | public/images/MuzMJn0WL.jpg | bin | 35079 -> 0 bytes | |||
-rw-r--r-- | public/images/NWu22eM3N.jpg | bin | 183771 -> 0 bytes | |||
-rw-r--r-- | public/images/PGPLMmrLx.jpg | bin | 69211 -> 0 bytes | |||
-rw-r--r-- | public/images/QStowNxrG.jpg | bin | 20903 -> 0 bytes | |||
-rw-r--r-- | public/images/Qc8yD9Czc.jpg | bin | 133292 -> 0 bytes | |||
-rw-r--r-- | public/images/RIfjBFkNM.jpg | bin | 39546 -> 0 bytes | |||
-rw-r--r-- | public/images/T4vKC9AST.jpg | bin | 97741 -> 0 bytes | |||
-rwxr-xr-x | public/images/WJg5kmqxO.jpg | bin | 104281 -> 0 bytes | |||
-rw-r--r-- | public/images/eDJLiKAlq.jpg | bin | 30386 -> 0 bytes | |||
-rw-r--r-- | public/images/eTr44-GcM.jpg | bin | 135518 -> 0 bytes | |||
-rw-r--r-- | public/images/g-DXzAYja.jpg | bin | 84083 -> 0 bytes | |||
-rw-r--r-- | public/images/jh4cSZE5f.jpg | bin | 43785 -> 0 bytes | |||
-rw-r--r-- | public/images/mI5wTGFf0.jpg | bin | 73048 -> 0 bytes | |||
-rw-r--r-- | public/images/p87zSi832.jpg | bin | 209659 -> 0 bytes | |||
-rw-r--r-- | public/images/pABmKJwq9.jpg | bin | 60135 -> 0 bytes | |||
-rw-r--r-- | public/images/pDiyR1X02.jpg | bin | 49875 -> 0 bytes | |||
-rwxr-xr-x | public/images/pUWua-OvO.jpg | bin | 57873 -> 0 bytes | |||
-rw-r--r-- | public/images/s6knwgTzC.jpg | bin | 144552 -> 0 bytes | |||
-rw-r--r-- | public/images/tLpBN00Dr.jpg | bin | 46441 -> 0 bytes | |||
-rw-r--r-- | public/images/yUYmHHpYY.jpg | bin | 158780 -> 0 bytes | |||
-rwxr-xr-x | routes.js | 40 | ||||
-rwxr-xr-x | start.js | 11 | ||||
-rwxr-xr-x | views/event.handlebars | 4 |
41 files changed, 38 insertions, 85 deletions
@@ -3,7 +3,8 @@ # gathio custom config/api.js -config/database.js +config/database.js +public/events/* # Logs logs diff --git a/models/User.js b/models/User.js deleted file mode 100755 index 9391c35..0000000 --- a/models/User.js +++ /dev/null @@ -1,43 +0,0 @@ -const mongoose = require('mongoose'); -const crypto = require('crypto'); -const jwt = require('jsonwebtoken'); - -const { Schema } = mongoose; - -const UserSchema = new Schema({ - email: String, - hash: String, - salt: String, -}); - -UserSchema.methods.setPassword = function(password) { - this.salt = crypto.randomBytes(16).toString('hex'); - this.hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex'); -}; - -UserSchema.methods.validatePassword = function(password) { - const hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex'); - return this.hash === hash; -}; - -UserSchema.methods.generateJWT = function() { - const today = new Date(); - const expirationDate = new Date(today); - expirationDate.setDate(today.getDate() + 60); - - return jwt.sign({ - email: this.email, - id: this._id, - exp: parseInt(expirationDate.getTime() / 1000, 10), - }, 'secret'); -} - -UserSchema.methods.toAuthJSON = function() { - return { - _id: this._id, - email: this.email, - token: this.generateJWT(), - }; -}; - -mongoose.model('User', UserSchema);
\ No newline at end of file diff --git a/models/passport.js b/models/passport.js deleted file mode 100755 index 15020a7..0000000 --- a/models/passport.js +++ /dev/null @@ -1,19 +0,0 @@ -const mongoose = require('mongoose'); -const passport = require('passport'); -const LocalStrategy = require('passport-local'); - -const User = mongoose.model('User'); - -passport.use(new LocalStrategy({ - usernameField: 'user[email]', - passwordField: 'user[password]', -}, (email, password, done) => { - User.findOne({ email }) - .then((user) => { - if(!user || !user.validatePassword(password)) { - return done(null, false, { errors: { 'Email or password': 'is invalid' } }); - } - - return done(null, user); - }).catch(done); -}));
\ No newline at end of file diff --git a/package.json b/package.json index d81fc89..8996b13 100755 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "dependencies": { "@sendgrid/mail": "^6.3.1", "body-parser": "^1.18.3", - "connect-ensure-login": "^0.1.1", "cors": "^2.8.5", "dotenv": "^6.1.0", "express": "^4.16.4", @@ -31,8 +30,6 @@ "mongoose": "^5.3.13", "multer": "^1.4.1", "node-schedule": "^1.3.1", - "passport": "^0.4.0", - "passport-local": "^1.0.0", "randomstring": "^1.1.5", "shortid": "^2.2.14" }, diff --git a/public/images/-uM2C4w60.jpg b/public/images/-uM2C4w60.jpg Binary files differdeleted file mode 100644 index 3010c35..0000000 --- a/public/images/-uM2C4w60.jpg +++ /dev/null diff --git a/public/images/._example-event.jpg b/public/images/._example-event.jpg Binary files differdeleted file mode 100755 index 8346511..0000000 --- a/public/images/._example-event.jpg +++ /dev/null diff --git a/public/images/2aDitGZP0.jpg b/public/images/2aDitGZP0.jpg Binary files differdeleted file mode 100644 index 9aaed2c..0000000 --- a/public/images/2aDitGZP0.jpg +++ /dev/null diff --git a/public/images/2l0j1mgRi.jpg b/public/images/2l0j1mgRi.jpg Binary files differdeleted file mode 100644 index 4c17a15..0000000 --- a/public/images/2l0j1mgRi.jpg +++ /dev/null diff --git a/public/images/76r5zFOME.jpg b/public/images/76r5zFOME.jpg Binary files differdeleted file mode 100644 index de21eec..0000000 --- a/public/images/76r5zFOME.jpg +++ /dev/null diff --git a/public/images/9nNZLv4SE.jpg b/public/images/9nNZLv4SE.jpg Binary files differdeleted file mode 100644 index 39be770..0000000 --- a/public/images/9nNZLv4SE.jpg +++ /dev/null diff --git a/public/images/Edl8knpyj.jpg b/public/images/Edl8knpyj.jpg Binary files differdeleted file mode 100644 index 37d6421..0000000 --- a/public/images/Edl8knpyj.jpg +++ /dev/null diff --git a/public/images/FgMoe7UH1.jpg b/public/images/FgMoe7UH1.jpg Binary files differdeleted file mode 100644 index 854ddfd..0000000 --- a/public/images/FgMoe7UH1.jpg +++ /dev/null diff --git a/public/images/JO-XJd-_8.jpg b/public/images/JO-XJd-_8.jpg Binary files differdeleted file mode 100644 index 5433d03..0000000 --- a/public/images/JO-XJd-_8.jpg +++ /dev/null diff --git a/public/images/KD3IkClNG.jpg b/public/images/KD3IkClNG.jpg Binary files differdeleted file mode 100644 index cd526bb..0000000 --- a/public/images/KD3IkClNG.jpg +++ /dev/null diff --git a/public/images/KNvt-8y2G.jpg b/public/images/KNvt-8y2G.jpg Binary files differdeleted file mode 100644 index 4d6e6d3..0000000 --- a/public/images/KNvt-8y2G.jpg +++ /dev/null diff --git a/public/images/KkMmanmXM.jpg b/public/images/KkMmanmXM.jpg Binary files differdeleted file mode 100644 index 837eb7e..0000000 --- a/public/images/KkMmanmXM.jpg +++ /dev/null diff --git a/public/images/LX4Iii8T0.jpg b/public/images/LX4Iii8T0.jpg Binary files differdeleted file mode 100755 index 846a7a6..0000000 --- a/public/images/LX4Iii8T0.jpg +++ /dev/null diff --git a/public/images/M42Hpaxe-.jpg b/public/images/M42Hpaxe-.jpg Binary files differdeleted file mode 100644 index 2e0e3ec..0000000 --- a/public/images/M42Hpaxe-.jpg +++ /dev/null diff --git a/public/images/MuzMJn0WL.jpg b/public/images/MuzMJn0WL.jpg Binary files differdeleted file mode 100755 index a8c9a6f..0000000 --- a/public/images/MuzMJn0WL.jpg +++ /dev/null diff --git a/public/images/NWu22eM3N.jpg b/public/images/NWu22eM3N.jpg Binary files differdeleted file mode 100644 index b10477f..0000000 --- a/public/images/NWu22eM3N.jpg +++ /dev/null diff --git a/public/images/PGPLMmrLx.jpg b/public/images/PGPLMmrLx.jpg Binary files differdeleted file mode 100644 index b921cbf..0000000 --- a/public/images/PGPLMmrLx.jpg +++ /dev/null diff --git a/public/images/QStowNxrG.jpg b/public/images/QStowNxrG.jpg Binary files differdeleted file mode 100644 index 8f68d0e..0000000 --- a/public/images/QStowNxrG.jpg +++ /dev/null diff --git a/public/images/Qc8yD9Czc.jpg b/public/images/Qc8yD9Czc.jpg Binary files differdeleted file mode 100644 index 5e93b8a..0000000 --- a/public/images/Qc8yD9Czc.jpg +++ /dev/null diff --git a/public/images/RIfjBFkNM.jpg b/public/images/RIfjBFkNM.jpg Binary files differdeleted file mode 100644 index ed3a770..0000000 --- a/public/images/RIfjBFkNM.jpg +++ /dev/null diff --git a/public/images/T4vKC9AST.jpg b/public/images/T4vKC9AST.jpg Binary files differdeleted file mode 100644 index ef33b08..0000000 --- a/public/images/T4vKC9AST.jpg +++ /dev/null diff --git a/public/images/WJg5kmqxO.jpg b/public/images/WJg5kmqxO.jpg Binary files differdeleted file mode 100755 index 4d993bc..0000000 --- a/public/images/WJg5kmqxO.jpg +++ /dev/null diff --git a/public/images/eDJLiKAlq.jpg b/public/images/eDJLiKAlq.jpg Binary files differdeleted file mode 100644 index c2a7a85..0000000 --- a/public/images/eDJLiKAlq.jpg +++ /dev/null diff --git a/public/images/eTr44-GcM.jpg b/public/images/eTr44-GcM.jpg Binary files differdeleted file mode 100644 index 4ba5e85..0000000 --- a/public/images/eTr44-GcM.jpg +++ /dev/null diff --git a/public/images/g-DXzAYja.jpg b/public/images/g-DXzAYja.jpg Binary files differdeleted file mode 100644 index d3cc855..0000000 --- a/public/images/g-DXzAYja.jpg +++ /dev/null diff --git a/public/images/jh4cSZE5f.jpg b/public/images/jh4cSZE5f.jpg Binary files differdeleted file mode 100644 index 9cd6959..0000000 --- a/public/images/jh4cSZE5f.jpg +++ /dev/null diff --git a/public/images/mI5wTGFf0.jpg b/public/images/mI5wTGFf0.jpg Binary files differdeleted file mode 100644 index 65b6eab..0000000 --- a/public/images/mI5wTGFf0.jpg +++ /dev/null diff --git a/public/images/p87zSi832.jpg b/public/images/p87zSi832.jpg Binary files differdeleted file mode 100644 index 785b840..0000000 --- a/public/images/p87zSi832.jpg +++ /dev/null diff --git a/public/images/pABmKJwq9.jpg b/public/images/pABmKJwq9.jpg Binary files differdeleted file mode 100644 index df55d1e..0000000 --- a/public/images/pABmKJwq9.jpg +++ /dev/null diff --git a/public/images/pDiyR1X02.jpg b/public/images/pDiyR1X02.jpg Binary files differdeleted file mode 100644 index 19581cb..0000000 --- a/public/images/pDiyR1X02.jpg +++ /dev/null diff --git a/public/images/pUWua-OvO.jpg b/public/images/pUWua-OvO.jpg Binary files differdeleted file mode 100755 index 10b666f..0000000 --- a/public/images/pUWua-OvO.jpg +++ /dev/null diff --git a/public/images/s6knwgTzC.jpg b/public/images/s6knwgTzC.jpg Binary files differdeleted file mode 100644 index f410131..0000000 --- a/public/images/s6knwgTzC.jpg +++ /dev/null diff --git a/public/images/tLpBN00Dr.jpg b/public/images/tLpBN00Dr.jpg Binary files differdeleted file mode 100644 index 196355e..0000000 --- a/public/images/tLpBN00Dr.jpg +++ /dev/null diff --git a/public/images/yUYmHHpYY.jpg b/public/images/yUYmHHpYY.jpg Binary files differdeleted file mode 100644 index ec0d340..0000000 --- a/public/images/yUYmHHpYY.jpg +++ /dev/null @@ -1,3 +1,5 @@ +const fs = require('fs'); + const express = require('express'); const mongoose = require('mongoose'); @@ -48,7 +50,7 @@ const deleteOldEvents = schedule.scheduleJob('59 23 * * *', function(fireDate){ const too_old = moment().subtract(7, 'days').toDate(); console.log(too_old); - Event.find({ end: { $lte: too_old } }).remove().exec().then((RemoveStatus) => { + Event.findOne({ end: { $lte: too_old } }).remove().exec().then((RemoveStatus) => { console.log("Documents removed successfully"); addToLog("deleteOldEvents", "success", "Old events deleted"); }).catch((err) => { @@ -204,7 +206,7 @@ router.post('/newevent', (req, res) => { img .resize(920, Jimp.AUTO) // resize .quality(60) // set JPEG quality - .write('./public/images/' + eventID + '.jpg'); // save + .write('./public/events/' + eventID + '.jpg'); // save }); eventImageFilename = eventID + '.jpg'; } @@ -341,7 +343,7 @@ router.post('/editevent/:eventID/:editToken', (req, res) => { img .resize(920, Jimp.AUTO) // resize .quality(60) // set JPEG quality - .write('./public/images/' + eventID + '.jpg'); // save + .write('./public/events/' + eventID + '.jpg'); // save }); eventImageFilename = eventID + '.jpg'; } @@ -366,7 +368,7 @@ router.post('/editevent/:eventID/:editToken', (req, res) => { }) .then(() => { addToLog("editEvent", "success", "Event " + req.params.eventID + " edited"); - Event.find({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { + Event.findOne({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { console.log(ids) attendeeEmails = ids; if (!error && attendeeEmails != ""){ @@ -409,16 +411,19 @@ router.post('/editevent/:eventID/:editToken', (req, res) => { router.post('/deleteevent/:eventID/:editToken', (req, res) => { let submittedEditToken = req.params.editToken; - Event.find(({ + Event.findOne(({ id: req.params.eventID, })) .then((event) => { + console.log(submittedEditToken); if (event.editToken === submittedEditToken) { // Token matches + eventImage = event.image; + // Send emails here otherwise they don't exist lol - Event.find({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { + Event.findOne({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { attendeeEmails = ids; if (!error){ console.log("Sending emails to: " + attendeeEmails); @@ -450,11 +455,20 @@ router.post('/deleteevent/:eventID/:editToken', (req, res) => { } }) .then(() => { - addToLog("deleteEvent", "success", "Event " + req.params.eventID + " deleted"); - res.writeHead(302, { - 'Location': '/' - }); - res.end(); + // Delete image + fs.unlink(global.appRoot + '/public/events/' + eventImage, (err) => { + if (err) { + res.send(err); + addToLog("deleteEvent", "error", "Attempt to delete event image for event " + req.params.eventID + " failed with error: " + err); + } + // Image removed + addToLog("deleteEvent", "success", "Event " + req.params.eventID + " deleted"); + res.writeHead(302, { + 'Location': '/' + }); + res.end(); + }) + }) .catch((err) => { res.send('Sorry! Something went wrong (error deleting): ' + err); addToLog("deleteEvent", "error", "Attempt to delete event " + req.params.eventID + " failed with error: " + err);}); } @@ -523,7 +537,7 @@ router.post('/post/comment/:eventID', (req, res) => { event.save() .then(() => { addToLog("addEventComment", "success", "Comment added to event " + req.params.eventID); - Event.find({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { + Event.findOne({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { attendeeEmails = ids; if (!error){ console.log("Sending emails to: " + attendeeEmails); @@ -572,7 +586,7 @@ router.post('/post/reply/:eventID/:commentID', (req, res) => { event.save() .then(() => { addToLog("addEventReply", "success", "Reply added to comment " + commentID + " in event " + req.params.eventID); - Event.find({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { + Event.findOne({id: req.params.eventID}).distinct('attendees.email', function(error, ids) { attendeeEmails = ids; if (!error){ console.log("Sending emails to: " + attendeeEmails); @@ -1,5 +1,7 @@ require('dotenv').config(); +const path = require('path'); + const mongoose = require('mongoose'); const databaseCredentials = require('./config/database.js'); @@ -8,18 +10,19 @@ mongoose.connect(databaseCredentials.url, { useNewUrlParser: true }); mongoose.Promise = global.Promise; mongoose.connection .on('connected', () => { - console.log(`Mongoose connection open on ${process.env.DATABASE}`); + console.log('Mongoose connection open!'); }) .on('error', (err) => { - console.log(`Connection error: ${err.message}`); + console.log('Connection error: ${err.message}'); }); require('./models/Event'); -require('./models/User'); require('./models/Log'); const app = require('./app'); +global.appRoot = path.resolve(__dirname); + const server = app.listen(3000, () => { - console.log(`Express is running on port ${server.address().port}`); + console.log(`Welcome to gathio! The app is now running on https://localhost:${server.address().port}`); }); diff --git a/views/event.handlebars b/views/event.handlebars index ab04987..f27e8b6 100755 --- a/views/event.handlebars +++ b/views/event.handlebars @@ -1,5 +1,5 @@ {{#if eventHasCoverImage}} - <div id="eventImageContainer" style="background-image: url(/images/{{eventData.image}});"></div> + <div id="eventImageContainer" style="background-image: url(/events/{{eventData.image}});"></div> {{else}} <div id="genericEventImageContainer" style="background-image: url(/images/seigaiha.png);"></div> {{/if}} @@ -378,7 +378,7 @@ label_selected: "Change file", no_label: false }); - $("#image-preview").css("background-image", "url('/images/{{eventData.image}}')"); + $("#image-preview").css("background-image", "url('/events/{{eventData.image}}')"); $("#image-preview").css("background-size", "cover"); $("#image-preview").css("background-position", "center center"); {{#if editingEnabled}} |