Skip to content

Node.js based forum software built for the modern web

Fixed cover loading for subdirs and added removal

Julian Lamf1412b6e9b9a
diff --git a/public/src/modules/coverPhoto.js b/public/src/modules/coverPhoto.js
index 3d36d6d710..ef90f26e9a 100644
--- a/public/src/modules/coverPhoto.js
+++ b/public/src/modules/coverPhoto.js
@@ -23,6 +23,7 @@ define('coverPhoto', [
units: 'percent'
});
});
+ coverEl.find('.remove').on('click', coverPhoto.remove);
coverEl
.on('dragover', coverPhoto.onDragOver)
@@ -79,5 +80,17 @@ define('coverPhoto', [
});
};
+ coverPhoto.remove = function() {
+ socket.emit('user.removeCover', {
+ uid: ajaxify.data.uid
+ }, function(err) {
+ if (!err) {
+ ajaxify.refresh();
+ } else {
+ app.alertError(err.message);
+ }
+ });
+ };
+
return coverPhoto;
});
\ No newline at end of file
diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js
index 0205b60356..349a6c856e 100644
--- a/src/controllers/accounts/edit.js
+++ b/src/controllers/accounts/edit.js
@@ -131,7 +131,7 @@ editController.uploadCoverPicture = function(req, res, next) {
return next(err);
}
- res.json([{url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
+ res.json([{ url: image.url }]);
});
};
diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js
index 4eccfbcfe5..a245c6e29d 100644
--- a/src/socket.io/user/profile.js
+++ b/src/socket.io/user/profile.js
@@ -37,6 +37,20 @@ module.exports = function(SocketUser) {
});
};
+ SocketUser.removeCover = function(socket, data, callback) {
+ if (!socket.uid) {
+ return callback(new Error('[[error:no-privileges]]'));
+ }
+
+ user.isAdministrator(socket.uid, function(err, isAdmin) {
+ if (!isAdmin && data.uid !== socket.uid) {
+ return callback(new Error('[[error:no-privileges]]'));
+ }
+
+ user.removeCoverPicture(data, callback);
+ });
+ };
+
function isAdminOrSelfAndPasswordMatch(uid, data, callback) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, uid),
diff --git a/src/user/picture.js b/src/user/picture.js
index 20bb9647ef..503efd8845 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -13,7 +13,8 @@ var async = require('async'),
plugins = require('../plugins'),
file = require('../file'),
image = require('../image'),
- meta = require('../meta');
+ meta = require('../meta'),
+ db = require('../database');
module.exports = function(User) {
@@ -198,4 +199,7 @@ module.exports = function(User) {
});
};
+ User.removeCoverPicture = function(data, callback) {
+ db.deleteObjectField('user:' + data.uid, 'cover:url', callback);
+ };
};
\ No newline at end of file