From 29144967996bb0856527defdf892ee1147754198 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 10 Jun 2013 16:00:08 -0400 Subject: [PATCH] fixing bug where an anonymous user could follow a topic... yikes --- public/src/forum/topic.js | 11 ++++++++++- src/websockets.js | 13 ++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 0cba8ce384..64e536ce21 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -189,7 +189,16 @@ set_follow_state(state, true); }); socket.on('api:topic.follow', function(data) { - set_follow_state(data.follow); + if (data.status && data.status === 'ok') set_follow_state(data.follow); + else { + app.alert({ + type: 'error', + alert_id: 'topic_follow', + title: 'Please Log In', + message: 'Please register or log in in order to subscribe to this topic', + timeout: 5000 + }); + } }); socket.emit('api:topic.followCheck', tid); followEl[0].addEventListener('click', function() { diff --git a/src/websockets.js b/src/websockets.js index 5c222d8787..95b613e97a 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -378,9 +378,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), }); socket.on('api:topic.follow', function(tid) { - threadTools.toggleFollow(tid, uid, function(follow) { - if (follow.status === 'ok') socket.emit('api:topic.follow', follow); - }); + if (uid && uid > 0) { + threadTools.toggleFollow(tid, uid, function(follow) { + if (follow.status === 'ok') socket.emit('api:topic.follow', follow); + }); + } else { + socket.emit('api:topic.follow', { + status: 'error', + error: 'not-logged-in' + }); + } }); });