diff --git a/routes/chat.js b/routes/chat.js index 9d8e438d..a0a82155 100644 --- a/routes/chat.js +++ b/routes/chat.js @@ -20,7 +20,7 @@ router.use(bodyParser.urlencoded({ extended: false })) /* GET home page. */ -router.get('/' , function(req, res, next) { +router.get('/', checkAuthentication, function(req, res, next) { chatData.find({users: {$elemMatch : { @@ -72,5 +72,16 @@ router.post('/messages',async (req, res) => { }) +//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') + } +} + module.exports = router; diff --git a/views/chat.hbs b/views/chat.hbs index d7b13557..0d2602c6 100644 --- a/views/chat.hbs +++ b/views/chat.hbs @@ -51,11 +51,14 @@ img{ max-width:100%;} width: 88%; } -.chat_people{ overflow:hidden; clear:both;} +.chat_people{ + overflow:hidden; + clear:both; + padding: 20px 10px; +} .chat_list { border-bottom: 1px solid #c4c4c4; margin: 0; - padding: 18px 16px 10px; } .inbox_chat { height: 550px; overflow-y: scroll;} @@ -145,17 +148,19 @@ img{ max-width:100%;}
{{# each chats }} -
- +
sunil
-
{{this.selectedPersonSelling}} Dec 25
-

Item: {{this.selectedPostTitle}}

+ {{#ifEquals this.selectedPersonSelling ../currentSession.passport.user._json.email}} +
Interested buyer for "{{this.selectedPostTitle}}"Dec 25
+ {{/ifEquals}} + {{#ifEquals this.dateChatStartedBy ../currentSession.passport.user._json.email}} +
Seller of "{{this.selectedPostTitle}}"Dec 25
+ {{/ifEquals}}

-
{{/each}}
@@ -187,16 +192,17 @@ img{ max-width:100%;} // When send is pressed, get imporant values and run sendMessage function to save to DB $("#send_message").click(() => { // TODO: check to see if user has not selected a thread, dont allow to send if they are have not selected - var threadId = $("input[type='radio']:checked").val() + var threadId = window.sessionStorage.getItem('currentThread'); var chatMessage = { name: $("#username").val(), chat: $("#message").val(), thread: threadId } sendMessage(chatMessage) }) // if a thread is selected show the messages specific to that thread - $('input[type="radio"]').click(function(){ - var threadId = $("input[type='radio']:checked"). val() - console.log("Radio Button Selected", threadId); + $('.chat_people').click(function(){ + console.log('Chat Clicked'); + var threadId = $(this).attr('threadId'); + window.sessionStorage.setItem('currentThread', threadId); $("#chatroom").empty(); sendInfoForMessages(threadId); })