mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
moved upload route into API namespace
This commit is contained in:
@@ -125,7 +125,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader'], function(head
|
||||
$('#uploadPictureBtn').on('click', function() {
|
||||
|
||||
$('#change-picture-modal').modal('hide');
|
||||
uploader.open(config.relative_path + '/user/uploadpicture', {uid: ajaxify.variables.get('theirid')}, config.maximumProfileImageSize, function(imageUrlOnServer) {
|
||||
uploader.open(config.relative_path + '/api/user/' + ajaxify.variables.get('userslug') + '/uploadpicture', {}, config.maximumProfileImageSize, function(imageUrlOnServer) {
|
||||
imageUrlOnServer = imageUrlOnServer + '?' + new Date().getTime();
|
||||
|
||||
$('#user-current-picture').attr('src', imageUrlOnServer);
|
||||
|
||||
@@ -407,26 +407,24 @@ accountsController.uploadPicture = function (req, res, next) {
|
||||
image.convertImageToPng(req.files.userPhoto.path, extension, next);
|
||||
},
|
||||
function(next) {
|
||||
try {
|
||||
var params = JSON.parse(req.body.params);
|
||||
if(parseInt(updateUid, 10) === parseInt(params.uid, 10)) {
|
||||
return next();
|
||||
user.getUidByUserslug(req.params.userslug, next);
|
||||
},
|
||||
function(uid, next) {
|
||||
if(parseInt(updateUid, 10) === parseInt(uid, 10)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
user.isAdministrator(req.user.uid, function(err, isAdmin) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
user.isAdministrator(req.user.uid, function(err, isAdmin) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!isAdmin) {
|
||||
return userNotAllowed();
|
||||
}
|
||||
updateUid = params.uid;
|
||||
next();
|
||||
});
|
||||
} catch(err) {
|
||||
next(err);
|
||||
}
|
||||
if (!isAdmin) {
|
||||
return userNotAllowed();
|
||||
}
|
||||
updateUid = uid;
|
||||
next();
|
||||
});
|
||||
}
|
||||
], function(err, result) {
|
||||
|
||||
|
||||
@@ -154,13 +154,11 @@ middleware.checkAccountPermissions = function(req, res, next) {
|
||||
return res.redirect('/login?next=' + req.url);
|
||||
}
|
||||
|
||||
// this function requires userslug to be passed in. todo: /user/uploadpicture should pass in userslug I think
|
||||
user.getUidByUserslug(req.params.userslug, function (err, uid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// not sure if this check really should belong here. also make sure we're not doing this check again in the actual method
|
||||
if (!uid) {
|
||||
if (res.locals.isAPI) {
|
||||
return res.json(404, 'not-found');
|
||||
|
||||
@@ -188,9 +188,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
|
||||
app.post('/post/upload', uploadPost);
|
||||
app.post('/topic/thumb/upload', uploadThumb);
|
||||
app.post('/user/:userslug/uploadpicture', middleware.authenticate, middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, controllers.accounts.uploadPicture);
|
||||
});
|
||||
|
||||
// this should be in the API namespace
|
||||
// also, perhaps pass in :userslug so we can use checkAccountPermissions middleware - in future will allow admins to upload a picture for a user
|
||||
app.post('/user/uploadpicture', middleware.authenticate, middleware.checkGlobalPrivacySettings, /*middleware.checkAccountPermissions,*/ controllers.accounts.uploadPicture);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user