Merge branch 'master' of github.com:psychobunny/node-forum

v1.18.x
Julian Lam 12 years ago
commit 2c95c19c9a

@ -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

@ -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();
}
});
}());

@ -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;
});
});

@ -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()));
});

@ -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 {

@ -8,8 +8,9 @@
<a href="/users/{userslug}">{username}</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="followersLink" class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span id="followingLink" class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
@ -32,7 +33,7 @@
<h4>profile</h4>
<div class="inline-block">
<div class="account-bio-block">
<span class="account-bio-label">email</span>
<span class="account-bio-label">email</span><i class="icon-eye-close {emailClass}" title="Email hidden"></i>
<span>{email}</span>
<br/>
@ -101,4 +102,5 @@
<input type="hidden" template-variable="theirid" value="{theirid}" />
<input type="hidden" template-type="boolean" template-variable="isFollowing" value="{isFollowing}" />
<script type="text/javascript" src="{relative_path}/src/forum/account.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/account.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>

@ -66,8 +66,9 @@
<a href="/users/{userslug}/edit">edit</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="followersLink" class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span id="followingLink" class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
@ -170,4 +171,4 @@
<input type="hidden" template-variable="gravatarpicture" value="{gravatarpicture}" />
<input type="hidden" template-variable="uploadedpicture" value="{uploadedpicture}" />
<script type="text/javascript" src="{relative_path}/src/forum/accountedit.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountedit.js"></script>

@ -0,0 +1,34 @@
<div class="well">
<div class="account-username-box">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/settings">settings</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<h4>privacy</h4>
<label class="checkbox">
<input id="showemailCheckBox" type="checkbox" {showemail}> Show my email
</label>
</div>
<div class="span6">
</div>
</div>
<div class="form-actions">
<a id="submitBtn" href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
<script type="text/javascript" src="{relative_path}/src/forum/accountsettings.js"></script>

@ -23,6 +23,7 @@
"users[^]*edit": "accountedit",
"users[^]*following": "following",
"users[^]*followers": "followers",
"users[^]*settings": "accountsettings",
"users/[^]*": "account",
"recent": "recent",

@ -7,8 +7,9 @@
<a href="/users/{userslug}/followers">followers</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="followersLink" class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span id="followingLink" class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
@ -41,4 +42,5 @@
<input type="hidden" template-variable="theirid" value="{theirid}" />
<input type="hidden" template-variable="followersCount" value="{followersCount}" />
<script type="text/javascript" src="{relative_path}/src/forum/followers.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/followers.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>

@ -9,8 +9,9 @@
<a href="/users/{userslug}/following">following</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="followersLink" class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span id="followingLink" class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
@ -46,3 +47,4 @@
<input type="hidden" template-variable="followingCount" value="{followingCount}" />
<script type="text/javascript" src="{relative_path}/src/forum/following.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>

@ -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;

@ -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);

@ -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);
});

Loading…
Cancel
Save