Allow to disable gravatar

Since Gravatar is an external image source and not perfect from a
privacy perspective, forbidding it allows to improve privacy.

This commit also simplifies and optimizes the avatar code.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
Sheogorath 2018-06-23 23:40:46 +02:00
parent a2608c319a
commit 318b2d378f
No known key found for this signature in database
GPG key ID: 1F05CC3635CDDFFD
5 changed files with 23 additions and 27 deletions

View file

@ -1,6 +1,5 @@
'use strict'
// external modules
var md5 = require('blueimp-md5')
var Sequelize = require('sequelize')
var scrypt = require('scrypt')
@ -128,10 +127,7 @@ module.exports = function (sequelize, DataTypes) {
}
break
case 'dropbox':
// no image api provided, use gravatar
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value)
if (bigger) photo += '?s=400'
else photo += '?s=96'
photo = generateAvatarURL('', profile.emails[0].value, bigger)
break
case 'google':
photo = profile.photos[0].value
@ -139,35 +135,19 @@ module.exports = function (sequelize, DataTypes) {
else photo = photo.replace(/(\?sz=)\d*$/i, '$196')
break
case 'ldap':
// no image api provided,
// use gravatar if email exists,
// otherwise generate a letter avatar
if (profile.emails[0]) {
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0])
if (bigger) photo += '?s=400'
else photo += '?s=96'
} else {
photo = generateAvatarURL(profile.username)
}
photo = generateAvatarURL(profile.username, profile.emails[0], bigger)
break
case 'saml':
if (profile.emails[0]) {
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0])
if (bigger) photo += '?s=400'
else photo += '?s=96'
} else {
photo = generateAvatarURL(profile.username)
}
photo = generateAvatarURL(profile.username, profile.emails[0], bigger)
break
}
return photo
},
parseProfileByEmail: function (email) {
var photoUrl = 'https://www.gravatar.com/avatar/' + md5(email)
return {
name: email.substring(0, email.lastIndexOf('@')),
photo: photoUrl + '?s=96',
biggerphoto: photoUrl + '?s=400'
photo: generateAvatarURL('', email, false),
biggerphoto: generateAvatarURL('', email, true)
}
}
}