diff --git a/public/src/forum/account.js b/public/src/forum/account.js index b54d0f39f5..be0b58058b 100644 --- a/public/src/forum/account.js +++ b/public/src/forum/account.js @@ -11,14 +11,11 @@ var postcount = $('#postcount'); postcount.html(app.addCommas(postcount.html())); - var editLink = $('#editLink'); var followBtn = $('#follow-btn'); if(yourid === "0") { - editLink.hide(); followBtn.hide(); } else if(yourid !== theirid) { - editLink.hide(); if(isFollowing) followBtn.hide(); else diff --git a/public/src/forum/accountheader.js b/public/src/forum/accountheader.js new file mode 100644 index 0000000000..f294065184 --- /dev/null +++ b/public/src/forum/accountheader.js @@ -0,0 +1,20 @@ +(function() { + var yourid = templates.get('yourid'), + theirid = templates.get('theirid'); + + $(document).ready(function() { + + var editLink = $('#editLink'); + var settingsLink = $('#settingsLink'); + + if(yourid === "0") { + editLink.hide(); + settingsLink.hide(); + } + else if(yourid !== theirid) { + editLink.hide(); + settingsLink.hide(); + } + }); + +}()); \ No newline at end of file diff --git a/public/src/forum/accountsettings.js b/public/src/forum/accountsettings.js new file mode 100644 index 0000000000..1bc92cfff6 --- /dev/null +++ b/public/src/forum/accountsettings.js @@ -0,0 +1,16 @@ + + + +$(document).ready(function() { + + $('#submitBtn').on('click', function() { + + var settings = { + showemail: $('#showemailCheckBox').is(':checked')?1:0 + }; + + socket.emit('api:user.saveSettings', settings); + return false; + }); + +}); \ No newline at end of file diff --git a/public/src/forum/followers.js b/public/src/forum/followers.js index d5457858cc..d5ad575f02 100644 --- a/public/src/forum/followers.js +++ b/public/src/forum/followers.js @@ -9,12 +9,7 @@ if(parseInt(followersCount, 10) === 0) { $('#no-followers-notice').show(); } - var editLink = $('#editLink'); - - if(yourid !== theirid) { - editLink.hide(); - } - + $('.reputation').each(function(index, element) { $(element).html(app.addCommas($(element).html())); }); diff --git a/public/src/forum/following.js b/public/src/forum/following.js index 53e368d202..0b3a550f79 100644 --- a/public/src/forum/following.js +++ b/public/src/forum/following.js @@ -9,10 +9,8 @@ if(parseInt(followingCount, 10) === 0) { $('#no-following-notice').show(); } - var editLink = $('#editLink'); if(yourid !== theirid) { - editLink.hide(); $('.unfollow-btn').hide(); } else { diff --git a/public/templates/account.tpl b/public/templates/account.tpl index 79a94cae4d..bb471baa57 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -8,8 +8,9 @@ {username} @@ -32,7 +33,7 @@

profile

- + {email}
@@ -101,4 +102,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 2b0c7bbc11..74509bcdd4 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -66,8 +66,9 @@ edit
@@ -170,4 +171,4 @@ - \ No newline at end of file + diff --git a/public/templates/accountsettings.tpl b/public/templates/accountsettings.tpl new file mode 100644 index 0000000000..bff29397fc --- /dev/null +++ b/public/templates/accountsettings.tpl @@ -0,0 +1,34 @@ + +
+ + + +
+
+

privacy

+ +
+ +
+ +
+
+ +
+ + \ No newline at end of file diff --git a/public/templates/config.json b/public/templates/config.json index 2aa8f4c9a9..5f00752c23 100644 --- a/public/templates/config.json +++ b/public/templates/config.json @@ -23,6 +23,7 @@ "users[^]*edit": "accountedit", "users[^]*following": "following", "users[^]*followers": "followers", + "users[^]*settings": "accountsettings", "users/[^]*": "account", "recent": "recent", diff --git a/public/templates/followers.tpl b/public/templates/followers.tpl index 3e38ca006c..212d88b2a6 100644 --- a/public/templates/followers.tpl +++ b/public/templates/followers.tpl @@ -7,8 +7,9 @@ followers
@@ -41,4 +42,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/public/templates/following.tpl b/public/templates/following.tpl index b14bf94904..7cc6409230 100644 --- a/public/templates/following.tpl +++ b/public/templates/following.tpl @@ -9,8 +9,9 @@ following @@ -46,3 +47,4 @@ + diff --git a/src/routes/user.js b/src/routes/user.js index ae646e8c8b..0be3abcf12 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -90,6 +90,22 @@ var user = require('./../user.js'), }); }); + app.get('/users/:userslug/settings', function(req, res) { + + if(!req.user) + return res.redirect('/403'); + + user.getUserField(req.user.uid, 'userslug', function(userslug) { + if(req.params.userslug && userslug === req.params.userslug) { + app.build_header({ req: req, res: res }, function(err, header) { + res.send(header + app.create_route('users/'+req.params.userslug+'/settings','accountsettings') + templates['footer']); + }) + } else { + return res.redirect('/404'); + } + }); + }); + app.post('/users/uploadpicture', function(req, res) { if(!req.user) return res.redirect('/403'); @@ -110,24 +126,7 @@ var user = require('./../user.js'), return; } - user.getUserField(req.user.uid, 'uploadedpicture', function(oldpicture) { - - if(!oldpicture) { - uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res); - return; - } - - var absolutePath = path.join(global.configuration['ROOT_DIRECTORY'], global.nconf.get('upload_path'), path.basename(oldpicture)); - - fs.unlink(absolutePath, function(err) { - if(err) { - console.error('[%d] %s', Date.now(), + err); - } - - uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res); - - }); - }); + uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res); }); function uploadUserPicture(uid, extension, tempPath, res) { @@ -240,6 +239,9 @@ var user = require('./../user.js'), getUserDataByUserSlug(userslug, callerUID, function(userData) { res.json(userData); }); + } + else if (section === 'settings') { + getSettings(req, res, callerUID); } else { getUserDataByUserSlug(userslug, callerUID, function(userData) { if(userData) { @@ -288,6 +290,32 @@ var user = require('./../user.js'), }); } + function getSettings(req, res, callerUid) { + + user.get_uid_by_userslug(req.params.userslug, function(uid) { + if(!uid) { + res.json(404, { error: 'User not found!' }) ; + return; + } + uid = parseInt(uid, 10); + if(uid !== callerUid || callerUid === "0") { + res.json(403, { error: 'Not allowed!' }); + return; + } + user.getUserFields(uid, ['username','userslug','showemail'], function(userData) { + if(userData) { + if(userData.showemail && userData.showemail === "1") + userData.showemail = "checked"; + else + userData.showemail = ""; + res.json(userData); + } else { + res.json(404, { error: 'User not found!' }) ; + } + }); + }); + } + app.get('/api/users/:userslug?/:section?', api_method); app.get('/api/users-sort-posts', getUsersSortedByPosts); app.get('/api/users-sort-reputation', getUsersSortedByReputation); @@ -332,6 +360,8 @@ var user = require('./../user.js'), callback(null); return; } + + uid = parseInt(uid, 10); user.getUserData(uid, function(data) { if(data) { @@ -343,6 +373,19 @@ var user = require('./../user.js'), data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear(); } + function canSeeEmail() { + return callerUID === uid || (data.email && (data.showemail && data.showemail === "1")); + } + + if(!canSeeEmail()) + data.email = ""; + + if(callerUID === uid && data.showemail === "0") + data.emailClass = ""; + else + data.emailClass = "hidden"; + + data.uid = uid; data.yourid = callerUID; data.theirid = uid; diff --git a/src/user.js b/src/user.js index bcea85da46..46dc82e7c7 100644 --- a/src/user.js +++ b/src/user.js @@ -65,7 +65,8 @@ var utils = require('./../public/src/utils.js'), 'reputation': 0, 'postcount': 0, 'lastposttime': 0, - 'administrator': (uid == 1) ? 1 : 0 + 'administrator': (uid == 1) ? 1 : 0, + 'showemail': 0 }); RDB.set('username:' + username + ':uid', uid); diff --git a/src/websockets.js b/src/websockets.js index 9b7604feed..c548b01c9c 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -313,6 +313,21 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), } }); + socket.on('api:user.saveSettings', function(data) { + if(uid) { + user.setUserFields(uid, { + showemail:data.showemail + }); + + socket.emit('event:alert', { + title: 'Saved', + message: 'Settings saved!', + type: 'success', + timeout: 2000 + }); + } + }); + socket.on('api:topics.post', function(data) { topics.post(socket, uid, data.title, data.content, data.category_id, data.images); });