Update default gravatar admin option to defaultAvatar

v1.18.x
Julian Lam 9 years ago
parent 97dd5500a1
commit 896abb59d3

@ -93,8 +93,8 @@ uploadsController.uploadLogo = function(req, res, next) {
upload('site-logo', req, res, next);
};
uploadsController.uploadGravatarDefault = function(req, res, next) {
upload('gravatar-default', req, res, next);
uploadsController.uploadDefaultAvatar = function(req, res, next) {
upload('avatar-default', req, res, next);
};
function upload(name, req, res, next) {

@ -249,7 +249,7 @@ middleware.renderHeader = function(req, res, data, callback) {
next(null, {
username: '[[global:guest]]',
userslug: '',
picture: user.createGravatarURLFromEmail(''),
picture: meta.config.defaultAvatar,
status: 'offline',
banned: false,
uid: 0

@ -15,7 +15,7 @@ function apiRoutes(router, middleware, controllers) {
router.post('/uploadfavicon', middlewares, controllers.admin.uploads.uploadFavicon);
router.post('/uploadTouchIcon', middlewares, controllers.admin.uploads.uploadTouchIcon);
router.post('/uploadlogo', middlewares, controllers.admin.uploads.uploadLogo);
router.post('/uploadgravatardefault', middlewares, controllers.admin.uploads.uploadGravatarDefault);
router.post('/uploadDefaultAvatar', middlewares, controllers.admin.uploads.uploadDefaultAvatar);
}
function adminRouter(middleware, controllers) {

@ -21,7 +21,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate,
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2015, 8, 27);
latestSchema = Date.UTC(2015, 8, 30);
Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) {
@ -507,6 +507,39 @@ Upgrade.upgrade = function(callback) {
winston.info('[2015/09/27] Generating user icons skipped');
next();
}
},
function(next) {
thisSchemaDate = Date.UTC(2015, 8, 30);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2015/09/30] Converting default Gravatar image to default User Avatar');
async.waterfall([
async.apply(db.isObjectField, 'config', 'customGravatarDefaultImage'),
function(keyExists, _next) {
if (keyExists) {
_next();
} else {
winston.info('[2015/09/30] Converting default Gravatar image to default User Avatar skipped');
Upgrade.update(thisSchemaDate, next);
next();
}
},
async.apply(db.getObjectField, 'config', 'customGravatarDefaultImage'),
async.apply(db.setObjectField, 'config', 'defaultAvatar'),
async.apply(db.deleteObjectField, 'config', 'customGravatarDefaultImage')
], function(err) {
if (err) {
return next(err);
}
winston.info('[2015/09/30] Converting default Gravatar image to default User Avatar done');
Upgrade.update(thisSchemaDate, next);
});
} else {
winston.info('[2015/09/30] Converting default Gravatar image to default User Avatar skipped');
next();
}
}

@ -142,25 +142,6 @@ var async = require('async'),
return isOnline ? (status || 'online') : 'offline';
};
User.createGravatarURLFromEmail = function(email) {
var customGravatarDefaultImage = meta.config.customGravatarDefaultImage;
if (customGravatarDefaultImage && customGravatarDefaultImage.indexOf('http') === -1) {
customGravatarDefaultImage = nconf.get('url') + meta.config.customGravatarDefaultImage;
}
var options = {
size: parseInt(meta.config.profileImageDimension, 10) || 128,
default: customGravatarDefaultImage || meta.config.defaultGravatarImage || 'identicon',
rating: 'pg'
};
if (!email) {
email = '';
}
return gravatar.url(email, options, true);
};
User.hashPassword = function(password, callback) {
if (!password) {
return callback(null, password);

@ -85,23 +85,11 @@
</div>
<div class="form-group">
<label>Default Gravatar Image</label>
<select class="form-control" data-field="defaultGravatarImage">
<option value="">default</option>
<option value="identicon">identicon</option>
<option value="mm">mystery-man</option>
<option value="monsterid">monsterid</option>
<option value="wavatar">wavatar</option>
<option value="retro">retro</option>
</select>
</div>
<div class="form-group">
<label>Custom Gravatar Default Image</label>
<label>Custom Default Avatar</label>
<div class="input-group">
<input id="customGravatarDefaultImage" type="text" class="form-control" placeholder="A custom image to use instead of gravatar defaults" data-field="customGravatarDefaultImage" />
<input id="defaultAvatar" type="text" class="form-control" placeholder="A custom image to use instead of user icons" data-field="defaultAvatar" />
<span class="input-group-btn">
<input data-action="upload" data-target="customGravatarDefaultImage" data-route="{config.relative_path}/api/admin/uploadgravatardefault" type="button" class="btn btn-default" value="Upload"></input>
<input data-action="upload" data-target="defaultAvatar" data-route="{config.relative_path}/api/admin/uploadDefaultAvatar" type="button" class="btn btn-default" value="Upload"></input>
</span>
</div>
</div>

Loading…
Cancel
Save