mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
closes #3458
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
"upload_picture": "Upload picture",
|
"upload_picture": "Upload picture",
|
||||||
"upload_a_picture": "Upload a picture",
|
"upload_a_picture": "Upload a picture",
|
||||||
|
"remove_uploaded_picture" : "Remove Uploaded Picture",
|
||||||
"image_spec": "You may only upload PNG, JPG, or GIF files",
|
"image_spec": "You may only upload PNG, JPG, or GIF files",
|
||||||
|
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
|
|||||||
@@ -186,8 +186,16 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
|
|||||||
$('#user-uploaded-picture').attr('src', urlOnServer);
|
$('#user-uploaded-picture').attr('src', urlOnServer);
|
||||||
updateHeader(urlOnServer);
|
updateHeader(urlOnServer);
|
||||||
uploadedPicture = urlOnServer;
|
uploadedPicture = urlOnServer;
|
||||||
|
$('#removeUploadedPictureBtn').removeClass('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onRemoveComplete(urlOnServer) {
|
||||||
|
$('#user-current-picture').attr('src', urlOnServer);
|
||||||
|
$('#user-uploaded-picture').attr('src', '');
|
||||||
|
updateHeader(urlOnServer);
|
||||||
|
uploadedPicture = '';
|
||||||
|
$('#removeUploadedPictureBtn').addClass('hide');
|
||||||
|
}
|
||||||
|
|
||||||
$('#upload-picture-modal').on('hide', function() {
|
$('#upload-picture-modal').on('hide', function() {
|
||||||
$('#userPhotoInput').val('');
|
$('#userPhotoInput').val('');
|
||||||
@@ -226,6 +234,16 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#removeUploadedPictureBtn').on('click', function() {
|
||||||
|
socket.emit('user.removeUploadedPicture', {uid: ajaxify.data.theirid}, function(err, imageUrlOnServer) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
onRemoveComplete(imageUrlOnServer);
|
||||||
|
$('#change-picture-modal').modal('hide');
|
||||||
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEmailConfirm() {
|
function handleEmailConfirm() {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ define('forum/account/settings', ['forum/account/header'], function(header) {
|
|||||||
config[key] = newSettings[key];
|
config[key] = newSettings[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.exposeConfigToTemplates();
|
|
||||||
if (requireReload && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {
|
if (requireReload && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {
|
||||||
app.alert({
|
app.alert({
|
||||||
id: 'setting-change',
|
id: 'setting-change',
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ accountsController.uploadPicture = function (req, res, next) {
|
|||||||
}
|
}
|
||||||
], function(err, image) {
|
], function(err, image) {
|
||||||
fs.unlink(userPhoto.path, function(err) {
|
fs.unlink(userPhoto.path, function(err) {
|
||||||
winston.error('unable to delete picture', err);
|
winston.error('unable to delete picture ' + userPhoto.path, err);
|
||||||
});
|
});
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
|
winston = require('winston'),
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
groups = require('../groups'),
|
groups = require('../groups'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
@@ -166,6 +167,18 @@ SocketUser.changePassword = function(socket, data, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isAdminOrSelf(socket, uid, callback) {
|
||||||
|
if (socket.uid === parseInt(uid, 10)) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
user.isAdministrator(socket.uid, function(err, isAdmin) {
|
||||||
|
if (err || !isAdmin) {
|
||||||
|
return callback(err || new Error('[[error:no-privileges]]'));
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
SocketUser.updateProfile = function(socket, data, callback) {
|
SocketUser.updateProfile = function(socket, data, callback) {
|
||||||
function update(oldUserData) {
|
function update(oldUserData) {
|
||||||
function done(err, userData) {
|
function done(err, userData) {
|
||||||
@@ -197,15 +210,10 @@ SocketUser.updateProfile = function(socket, data, callback) {
|
|||||||
callback(null, userData);
|
callback(null, userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket.uid === parseInt(data.uid, 10)) {
|
isAdminOrSelf(socket, data.uid, function(err) {
|
||||||
return user.updateProfile(socket.uid, data, done);
|
if (err) {
|
||||||
}
|
return callback(err);
|
||||||
|
|
||||||
user.isAdministrator(socket.uid, function(err, isAdmin) {
|
|
||||||
if (err || !isAdmin) {
|
|
||||||
return callback(err || new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user.updateProfile(data.uid, data, done);
|
user.updateProfile(data.uid, data, done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -238,16 +246,6 @@ SocketUser.changePicture = function(socket, data, callback) {
|
|||||||
|
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
|
|
||||||
function changePicture(uid, callback) {
|
|
||||||
user.getUserField(uid, type, function(err, picture) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setUserField(uid, 'picture', picture, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'gravatar') {
|
if (type === 'gravatar') {
|
||||||
type = 'gravatarpicture';
|
type = 'gravatarpicture';
|
||||||
} else if (type === 'uploaded') {
|
} else if (type === 'uploaded') {
|
||||||
@@ -256,41 +254,60 @@ SocketUser.changePicture = function(socket, data, callback) {
|
|||||||
return callback(new Error('[[error:invalid-image-type, ' + ['gravatar', 'uploadedpicture'].join(', ') + ']]'));
|
return callback(new Error('[[error:invalid-image-type, ' + ['gravatar', 'uploadedpicture'].join(', ') + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket.uid === parseInt(data.uid, 10)) {
|
async.waterfall([
|
||||||
return changePicture(socket.uid, callback);
|
function (next) {
|
||||||
}
|
isAdminOrSelf(socket, data.uid, next);
|
||||||
|
},
|
||||||
user.isAdministrator(socket.uid, function(err, isAdmin) {
|
function (next) {
|
||||||
if (err || !isAdmin) {
|
user.getUserField(data.uid, type, next);
|
||||||
return callback(err || new Error('[[error:no-privileges]]'));
|
},
|
||||||
|
function (picture, next) {
|
||||||
|
user.setUserField(data.uid, 'picture', picture, next);
|
||||||
}
|
}
|
||||||
|
], callback);
|
||||||
changePicture(data.uid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.uploadProfileImageFromUrl = function(socket, data, callback) {
|
SocketUser.uploadProfileImageFromUrl = function(socket, data, callback) {
|
||||||
function upload() {
|
|
||||||
user.uploadFromUrl(data.uid, data.url, function(err, uploadedImage) {
|
|
||||||
callback(err, uploadedImage ? uploadedImage.url : null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!socket.uid || !data.url || !data.uid) {
|
if (!socket.uid || !data.url || !data.uid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(socket.uid, 10) === parseInt(data.uid, 10)) {
|
isAdminOrSelf(socket, data.uid, function(err) {
|
||||||
return upload();
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
user.uploadFromUrl(data.uid, data.url, function(err, uploadedImage) {
|
||||||
|
callback(err, uploadedImage ? uploadedImage.url : null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketUser.removeUploadedPicture = function(socket, data, callback) {
|
||||||
|
if (!socket.uid || !data.uid) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.isAdministrator(socket.uid, function(err, isAdmin) {
|
async.waterfall([
|
||||||
if (err || !isAdmin) {
|
function (next) {
|
||||||
return callback(err || new Error('[[error:not-allowed]]'));
|
isAdminOrSelf(socket, data.uid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
user.getUserField(data.uid, 'uploadedpicture', next);
|
||||||
|
},
|
||||||
|
function(uploadedPicture, next) {
|
||||||
|
if (!uploadedPicture.startsWith('http')) {
|
||||||
|
require('fs').unlink(uploadedPicture, function(err) {
|
||||||
|
if (err) {
|
||||||
|
winston.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
user.setUserField(data.uid, 'uploadedpicture', '', next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.getUserField(data.uid, 'picture', next);
|
||||||
}
|
}
|
||||||
|
], callback);
|
||||||
upload();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.follow = function(socket, data, callback) {
|
SocketUser.follow = function(socket, data, callback) {
|
||||||
@@ -346,19 +363,10 @@ SocketUser.saveSettings = function(socket, data, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket.uid === parseInt(data.uid, 10)) {
|
isAdminOrSelf(socket, data.uid, function(err) {
|
||||||
return user.saveSettings(socket.uid, data.settings, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
user.isAdministrator(socket.uid, function(err, isAdmin) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAdmin) {
|
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
user.saveSettings(data.uid, data.settings, callback);
|
user.saveSettings(data.uid, data.settings, callback);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user