mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 23:30:36 +01:00
fixed #4277
This commit is contained in:
@@ -78,10 +78,15 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
// boolean to signify whether an uploaded picture is present in the pictures list
|
||||
var uploaded = pictures.reduce(function(memo, cur) {
|
||||
return memo || cur.type === 'uploaded'
|
||||
}, false);
|
||||
|
||||
templates.parse('partials/modals/change_picture_modal', {
|
||||
pictures: pictures,
|
||||
uploaded: !!ajaxify.data.uploadedpicture,
|
||||
uploaded: uploaded,
|
||||
allowProfileImageUploads: ajaxify.data.allowProfileImageUploads
|
||||
}, function(html) {
|
||||
translator.translate(html, function(html) {
|
||||
@@ -189,15 +194,21 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
|
||||
function onUploadComplete(urlOnServer) {
|
||||
urlOnServer = urlOnServer + '?' + new Date().getTime();
|
||||
|
||||
$('#user-current-picture, img.avatar').attr('src', urlOnServer);
|
||||
updateHeader(urlOnServer);
|
||||
uploadedPicture = urlOnServer;
|
||||
|
||||
if (ajaxify.data.picture.length) {
|
||||
$('#user-current-picture, img.avatar').attr('src', urlOnServer);
|
||||
uploadedPicture = urlOnServer;
|
||||
} else {
|
||||
ajaxify.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
function onRemoveComplete(urlOnServer) {
|
||||
$('#user-current-picture').attr('src', urlOnServer);
|
||||
updateHeader(urlOnServer);
|
||||
uploadedPicture = '';
|
||||
function onRemoveComplete() {
|
||||
if (ajaxify.data.uploadedpicture === ajaxify.data.picture) {
|
||||
ajaxify.refresh();
|
||||
updateHeader();
|
||||
}
|
||||
}
|
||||
|
||||
modal.find('[data-action="upload"]').on('click', function() {
|
||||
@@ -239,12 +250,12 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
|
||||
});
|
||||
|
||||
modal.find('[data-action="remove-uploaded"]').on('click', function() {
|
||||
socket.emit('user.removeUploadedPicture', {uid: ajaxify.data.theirid}, function(err, imageUrlOnServer) {
|
||||
socket.emit('user.removeUploadedPicture', {uid: ajaxify.data.theirid}, function(err) {
|
||||
modal.modal('hide');
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
onRemoveComplete(imageUrlOnServer);
|
||||
onRemoveComplete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var path = require('path');
|
||||
|
||||
var user = require('../../user');
|
||||
var plugins = require('../../plugins');
|
||||
@@ -73,20 +74,21 @@ module.exports = function(SocketUser) {
|
||||
user.isAdminOrSelf(socket.uid, data.uid, next);
|
||||
},
|
||||
function (next) {
|
||||
user.getUserField(data.uid, 'uploadedpicture', next);
|
||||
user.getUserFields(data.uid, ['uploadedpicture', 'picture'], next);
|
||||
},
|
||||
function(uploadedPicture, next) {
|
||||
if (!uploadedPicture.startsWith('http')) {
|
||||
require('fs').unlink(uploadedPicture, function(err) {
|
||||
function(userData, next) {
|
||||
if (!userData.uploadedpicture.startsWith('http')) {
|
||||
require('fs').unlink(path.join(__dirname, '../../../public', userData.uploadedpicture), function(err) {
|
||||
if (err) {
|
||||
winston.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
user.setUserField(data.uid, 'uploadedpicture', '', next);
|
||||
},
|
||||
function(next) {
|
||||
user.getUserField(data.uid, 'picture', next);
|
||||
|
||||
user.setUserFields(data.uid, {
|
||||
uploadedpicture: '',
|
||||
picture: userData.uploadedpicture === userData.picture ? '' : userData.picture // if current picture is uploaded picture, reset to user icon
|
||||
}, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user