fixes admin user picture edit

v1.18.x
Baris Soner Usakli 11 years ago
parent 30cc992f5e
commit 43e8016dd1

@ -117,7 +117,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
$('#uploadPictureBtn').on('click', function() { $('#uploadPictureBtn').on('click', function() {
$('#change-picture-modal').modal('hide'); $('#change-picture-modal').modal('hide');
uploader.open(RELATIVE_PATH + '/user/uploadpicture', {}, config.maximumProfileImageSize, function(imageUrlOnServer) { uploader.open(RELATIVE_PATH + '/user/uploadpicture', {uid: templates.get('theirid')}, config.maximumProfileImageSize, function(imageUrlOnServer) {
imageUrlOnServer = imageUrlOnServer + '?' + new Date().getTime(); imageUrlOnServer = imageUrlOnServer + '?' + new Date().getTime();
$('#user-current-picture').attr('src', imageUrlOnServer); $('#user-current-picture').attr('src', imageUrlOnServer);
@ -220,7 +220,8 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
AccountEdit.changeUserPicture = function(type) { AccountEdit.changeUserPicture = function(type) {
var userData = { var userData = {
type: type type: type,
uid: templates.get('theirid')
}; };
socket.emit('user.changePicture', userData, function(err) { socket.emit('user.changePicture', userData, function(err) {

@ -165,8 +165,7 @@ var fs = require('fs'),
}); });
} }
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10); var updateUid = req.params.uid;
var filename = req.user.uid + '-profileimg' + (convertToPNG ? '.png' : extension);
async.waterfall([ async.waterfall([
function(next) { function(next) {
@ -174,16 +173,41 @@ var fs = require('fs'),
}, },
function(next) { function(next) {
image.convertImageToPng(req.files.userPhoto.path, extension, 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.isAdministrator(req.user.uid, function(err, isAdmin) {
if(err) {
return next(err);
}
if(!isAdmin) {
return res.json(403, {
error: 'Not allowed!'
});
}
updateUid = params.uid;
next();
});
} catch(err) {
next(err);
}
} }
], function(err, result) { ], function(err, result) {
function done(err, image) { function done(err, image) {
fs.unlink(req.files.userPhoto.path); fs.unlink(req.files.userPhoto.path);
if(err) { if(err) {
return res.send({error: err.message}); return res.send({error: err.message});
} }
user.setUserField(req.user.uid, 'uploadedpicture', image.url); user.setUserField(updateUid, 'uploadedpicture', image.url);
user.setUserField(req.user.uid, 'picture', image.url); user.setUserField(updateUid, 'picture', image.url);
res.json({ res.json({
path: image.url path: image.url
}); });
@ -194,10 +218,13 @@ var fs = require('fs'),
} }
if(plugins.hasListeners('filter:uploadImage')) { if(plugins.hasListeners('filter:uploadImage')) {
plugins.fireHook('filter:uploadImage', req.files.userPhoto, done); return plugins.fireHook('filter:uploadImage', req.files.userPhoto, done);
} else { }
user.getUserField(req.user.uid, 'uploadedpicture', function (err, oldpicture) { var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
var filename = updateUid + '-profileimg' + (convertToPNG ? '.png' : extension);
user.getUserField(updateUid, 'uploadedpicture', function (err, oldpicture) {
if (!oldpicture) { if (!oldpicture) {
file.saveFileToLocal(filename, req.files.userPhoto.path, done); file.saveFileToLocal(filename, req.files.userPhoto.path, done);
return; return;
@ -213,7 +240,6 @@ var fs = require('fs'),
file.saveFileToLocal(filename, req.files.userPhoto.path, done); file.saveFileToLocal(filename, req.files.userPhoto.path, done);
}); });
}); });
}
}); });
}); });
}); });

@ -102,12 +102,12 @@ SocketUser.updateProfile = function(socket, data, callback) {
SocketUser.changePicture = function(socket, data, callback) { SocketUser.changePicture = function(socket, data, callback) {
if(!data) { if(!data) {
return; return callback(new Error('invalid-data'));
} }
var type = data.type; var type = data.type;
function updateHeader() { function updateHeader(callback) {
user.getUserFields(socket.uid, ['picture'], function(err, fields) { user.getUserFields(socket.uid, ['picture'], function(err, fields) {
if(err) { if(err) {
return callback(err); return callback(err);
@ -118,7 +118,17 @@ SocketUser.changePicture = function(socket, data, callback) {
socket.emit('meta.updateHeader', null, fields); socket.emit('meta.updateHeader', null, fields);
} }
callback(null); callback();
});
}
function changePicture(uid, callback) {
user.getUserField(uid, type, function(err, picture) {
if(err) {
return callback(err);
}
user.setUserField(uid, 'picture', picture, callback);
}); });
} }
@ -130,9 +140,26 @@ SocketUser.changePicture = function(socket, data, callback) {
return callback(new Error('invalid-image-type')); return callback(new Error('invalid-image-type'));
} }
user.getUserField(socket.uid, type, function(err, picture) { if(socket.uid === parseInt(data.uid, 10)) {
user.setUserField(socket.uid, 'picture', picture); changePicture(socket.uid, function(err) {
updateHeader(); if(err) {
return callback(err);
}
updateHeader(callback);
});
return;
}
user.isAdministrator(socket.uid, function(err, isAdmin) {
if(err) {
return callback(err);
}
if(!isAdmin) {
return callback(new Error('not-allowed'));
}
changePicture(data.uid, callback);
}); });
}; };

Loading…
Cancel
Save