From 2b6e57f0d908ac638fd784e059c67f97499bb398 Mon Sep 17 00:00:00 2001 From: Karan Erry Date: Thu, 2 May 2019 01:17:02 -0400 Subject: [PATCH 1/3] Login no longer required for index --- app.js | 3 +++ routes/chat.js | 59 +++++++++++++++++++++++++++---------------------- views/chat.hbs | 11 ++++----- views/index.hbs | 41 ++++++---------------------------- 4 files changed, 46 insertions(+), 68 deletions(-) diff --git a/app.js b/app.js index ae70a632..f66af294 100644 --- a/app.js +++ b/app.js @@ -39,6 +39,9 @@ var handlebars = hbs.create({ ifEquals: function(arg1, arg2, options) { return (arg1 == arg2) ? options.fn(this) : options.inverse(this); }, + ifNotEquals: function(arg1, arg2, options) { + return (arg1 != arg2) ? options.fn(this) : options.inverse(this); + } }, extname: 'hbs', defaultLayout:'layout.hbs', diff --git a/routes/chat.js b/routes/chat.js index 0767b659..6e9454b5 100644 --- a/routes/chat.js +++ b/routes/chat.js @@ -21,7 +21,10 @@ router.use(bodyParser.urlencoded({ extended: false })) /* GET home page. */ -router.get('/', checkAuthentication, setupSocketListeners, function(req, res, next) { +router.get('/', (req, res, next) => { + req.session.authorigin = 'chat?' + querystring.stringify(req.query); + next(); + }, checkAuthentication, setupSocketListeners, function(req, res, next) { // Setup chat data and render chat page preselectedThread = req.query.preselectedThread ? req.query.preselectedThread : ''; chatData.find({allParticipants: @@ -95,40 +98,42 @@ function setupSocketListeners(req, res, next) { next(); } -router.post('/openThread', checkAuthentication, function(req,res){ - chatData.findOne({item: req.body.itemId, interestedBuyer:req.session.passport.user._json.email}).then(doc => { - if (!doc) { - // Start a new thread - var current_millies = new Date().getTime(); - var current_timestamp = Long.fromNumber(current_millies); - var date = new Date(current_millies); - var dateReadable = date.toString(); - var chat = { - item: mongoose.Types.ObjectId(req.body.itemId), - seller: req.body.seller, - interestedBuyer: req.session.passport.user._json.email, - allParticipants:[ {email: req.session.passport.user._json.email}, {email: req.body.seller} ], - dateChatCreated: current_timestamp, - dateChatCreatedComputed: dateReadable - } - var data = new chatData(chat); - data.save((err, doc) => { +router.get('/openThread', (req, res, next) => { + req.session.authorigin = 'chat/openThread?' + querystring.stringify(req.query); + next(); + }, checkAuthentication, function(req,res){ + var {itemId, seller} = req.query; + chatData.findOne({item: itemId, interestedBuyer:req.session.passport.user._json.email}).then(doc => { + if (!doc) { + // Start a new thread + var current_millies = new Date().getTime(); + var current_timestamp = Long.fromNumber(current_millies); + var date = new Date(current_millies); + var dateReadable = date.toString(); + var chat = { + item: mongoose.Types.ObjectId(itemId), + seller: seller, + interestedBuyer: req.session.passport.user._json.email, + allParticipants:[ {email: req.session.passport.user._json.email}, {email: seller} ], + dateChatCreated: current_timestamp, + dateChatCreatedComputed: dateReadable + } + var data = new chatData(chat); + data.save((err, doc) => { + res.redirect('/chat?' + querystring.stringify({'preselectedThread':doc.id})); + }); + } else { + // Open the existing thread res.redirect('/chat?' + querystring.stringify({'preselectedThread':doc.id})); - }); - } else { - // Open the existing thread - res.redirect('/chat?' + querystring.stringify({'preselectedThread':doc.id})); - } - }) + } + }) }); //authenticate a user is logged in function checkAuthentication(req,res,next){ if(req.isAuthenticated()){ - //req.isAuthenticated() will return true if user is logged in next(); } else{ - req.session.authorigin = 'chat'; res.redirect('/auth/google/callback') } } diff --git a/views/chat.hbs b/views/chat.hbs index 4ff2cf5f..36bf461c 100644 --- a/views/chat.hbs +++ b/views/chat.hbs @@ -225,16 +225,15 @@ img{ max-width:100%;} +{{/if}} \ No newline at end of file From 4939145d3a03d28603daa44d0406ff968e9d2773 Mon Sep 17 00:00:00 2001 From: Karan Erry Date: Fri, 3 May 2019 11:41:37 -0400 Subject: [PATCH 3/3] edit message box placeholder --- .DS_Store | Bin 8196 -> 8196 bytes views/chat.hbs | 6 ++---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.DS_Store b/.DS_Store index 762b4ed3853ad53cdae4e75e6673e4c7ab2950f0..aae1b97bd18968f05e689a05178a2d7027465d34 100644 GIT binary patch delta 83 zcmZp1XmOa}&nUDpU^hRb&}JS1d1h`lh9ZW1hEj$ShSbS%!Z#(6_zcBm!9{sF`FZIK e3=E8$HH6g}Hx}(++RQHTjb-v*;h>F0TbTf&1{e?k delta 38 ucmZp1XmOa}&nU1lU^hRbz-Ar+dFIX9A}WlV{dsmUZ)TVH#
- +
@@ -301,7 +301,7 @@ img{ max-width:100%;} function appendMessage(message){ // Add new message to chat room $("#chatroom").append(`

${message.byWho}: ${message.message}

`) - $("#message").val(" "); + $("#message").val(""); } function displayThread(thread){ @@ -317,8 +317,6 @@ img{ max-width:100%;} for (var i in thread.messages) { appendMessage(thread.messages[i]); } - - $("#message").val(" "); } \ No newline at end of file