diff --git a/dashboard/src/js/client.js b/dashboard/src/js/client.js index 6cd632f85..0bd97d93a 100644 --- a/dashboard/src/js/client.js +++ b/dashboard/src/js/client.js @@ -618,6 +618,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout twoFactorAuthenticationEnabled: false, source: null, avatarUrl: null, + avatarType: null, hasBackgroundImage: false }; this._config = { @@ -747,6 +748,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout this._userInfo.role = userInfo.role; this._userInfo.source = userInfo.source; this._userInfo.avatarUrl = userInfo.avatarUrl + '?ts=' + Date.now(); // we add the timestamp to avoid caching + this._userInfo.avatarType = userInfo.avatarType; this._userInfo.hasBackgroundImage = userInfo.hasBackgroundImage; this._userInfo.isAtLeastOwner = [ ROLES.OWNER ].indexOf(userInfo.role) !== -1; this._userInfo.isAtLeastAdmin = [ ROLES.OWNER, ROLES.ADMIN ].indexOf(userInfo.role) !== -1; diff --git a/dashboard/src/views/profile.js b/dashboard/src/views/profile.js index 3d27d1049..d37e08d14 100644 --- a/dashboard/src/views/profile.js +++ b/dashboard/src/views/profile.js @@ -207,15 +207,10 @@ angular.module('Application').controller('ProfileController', ['$scope', '$trans avatarChangeReset: function () { $scope.avatarChange.error.avatar = null; - if ($scope.user.avatarUrl.indexOf('/api/v1/profile/avatar') !== -1) { - $scope.avatarChange.type = 'custom'; - } else if ($scope.user.avatarUrl.indexOf('https://www.gravatar.com') === 0) { - $scope.avatarChange.type = 'gravatar'; - } else { - $scope.avatarChange.type = ''; - } - + console.log($scope.user) + $scope.avatarChange.type = $scope.user.avatarType; $scope.avatarChange.typeOrig = $scope.avatarChange.type; + document.getElementById('previewAvatar').src = $scope.avatarChange.type === 'custom' ? $scope.user.avatarUrl : ''; $scope.avatarChange.pictureChanged = false; $scope.avatarChange.avatar = null; diff --git a/src/routes/profile.js b/src/routes/profile.js index 1d191aed6..68e833a1c 100644 --- a/src/routes/profile.js +++ b/src/routes/profile.js @@ -45,6 +45,14 @@ async function get(req, res, next) { const [error, backgroundImage] = await safe(users.getBackgroundImage(req.user.id)); if (error) return next(BoxError.toHttpError(error)); + const [avatarError, avatar] = await safe(users.getAvatar(req.user.id)); + if (avatarError) return next(BoxError.toHttpError(error)); + + let avatarType; + if (avatar.equals(constants.AVATAR_GRAVATAR)) avatarType = constants.AVATAR_GRAVATAR; + else if (avatar.equals(constants.AVATAR_NONE)) avatarType = constants.AVATAR_NONE; + else avatarType = constants.AVATAR_CUSTOM; + const { fqdn:dashboardFqdn } = await dashboard.getLocation(); next(new HttpSuccess(200, { @@ -57,7 +65,8 @@ async function get(req, res, next) { role: req.user.role, source: req.user.source, hasBackgroundImage: !!backgroundImage, - avatarUrl: `https://${dashboardFqdn}/api/v1/profile/avatar/${req.user.id}` + avatarUrl: `https://${dashboardFqdn}/api/v1/profile/avatar/${req.user.id}`, + avatarType: avatarType.toString() // this is a Buffer })); }