|
|
@ -97,7 +97,9 @@ var user = require('./../user.js'),
|
|
|
|
|
|
|
|
|
|
|
|
user.getUserField(req.user.uid, 'userslug', function(userslug) {
|
|
|
|
user.getUserField(req.user.uid, 'userslug', function(userslug) {
|
|
|
|
if(req.params.userslug && userslug === req.params.userslug) {
|
|
|
|
if(req.params.userslug && userslug === req.params.userslug) {
|
|
|
|
res.send(app.build_header(res) + app.create_route('users/'+req.params.userslug+'/settings','accountsettings') + templates['footer']);
|
|
|
|
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 {
|
|
|
|
} else {
|
|
|
|
return res.redirect('/404');
|
|
|
|
return res.redirect('/404');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,24 +126,7 @@ var user = require('./../user.js'),
|
|
|
|
return;
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function uploadUserPicture(uid, extension, tempPath, res) {
|
|
|
|
function uploadUserPicture(uid, extension, tempPath, res) {
|
|
|
@ -254,6 +239,9 @@ var user = require('./../user.js'),
|
|
|
|
getUserDataByUserSlug(userslug, callerUID, function(userData) {
|
|
|
|
getUserDataByUserSlug(userslug, callerUID, function(userData) {
|
|
|
|
res.json(userData);
|
|
|
|
res.json(userData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (section === 'settings') {
|
|
|
|
|
|
|
|
getSettings(req, res, callerUID);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
getUserDataByUserSlug(userslug, callerUID, function(userData) {
|
|
|
|
getUserDataByUserSlug(userslug, callerUID, function(userData) {
|
|
|
|
if(userData) {
|
|
|
|
if(userData) {
|
|
|
@ -302,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/:userslug?/:section?', api_method);
|
|
|
|
app.get('/api/users-sort-posts', getUsersSortedByPosts);
|
|
|
|
app.get('/api/users-sort-posts', getUsersSortedByPosts);
|
|
|
|
app.get('/api/users-sort-reputation', getUsersSortedByReputation);
|
|
|
|
app.get('/api/users-sort-reputation', getUsersSortedByReputation);
|
|
|
@ -347,6 +361,8 @@ var user = require('./../user.js'),
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uid = parseInt(uid, 10);
|
|
|
|
|
|
|
|
|
|
|
|
user.getUserData(uid, function(data) {
|
|
|
|
user.getUserData(uid, function(data) {
|
|
|
|
if(data) {
|
|
|
|
if(data) {
|
|
|
|
data.joindate = utils.relativeTime(data.joindate);
|
|
|
|
data.joindate = utils.relativeTime(data.joindate);
|
|
|
@ -357,6 +373,19 @@ var user = require('./../user.js'),
|
|
|
|
data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();
|
|
|
|
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.uid = uid;
|
|
|
|
data.yourid = callerUID;
|
|
|
|
data.yourid = callerUID;
|
|
|
|
data.theirid = uid;
|
|
|
|
data.theirid = uid;
|
|
|
|