From 9612f9b6f41b7e3328fa8fc789d6a5fa738107c6 Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Thu, 11 Dec 2014 17:24:31 +0200 Subject: [PATCH] #7 Enable FB avatars --- app/controllers/users/users.profile.server.controller.js | 2 +- .../users/controllers/profile.edit.client.controller.js | 4 ++++ .../users/directives/tr-avatar.client.directive.js | 8 +++++--- .../users/views/profile/edit-profile.client.view.html | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/users/users.profile.server.controller.js b/app/controllers/users/users.profile.server.controller.js index ed8af64265..4fcd562c94 100644 --- a/app/controllers/users/users.profile.server.controller.js +++ b/app/controllers/users/users.profile.server.controller.js @@ -38,7 +38,7 @@ exports.userProfileFields = [ ].join(' '); // Restricted set of profile fields when only really "miniprofile" is needed -exports.userMiniProfileFields = 'id displayName username avatarSource emailHash'; +exports.userMiniProfileFields = 'id displayName username avatarSource emailHash additionalProvidersData.facebook.id'; /** * Rules for sanitizing user description coming in and out diff --git a/public/modules/users/controllers/profile.edit.client.controller.js b/public/modules/users/controllers/profile.edit.client.controller.js index 35cf32d20e..9d430cdd7b 100644 --- a/public/modules/users/controllers/profile.edit.client.controller.js +++ b/public/modules/users/controllers/profile.edit.client.controller.js @@ -109,6 +109,10 @@ angular.module('users').controller('EditProfileController', ['$scope', '$modal', templateUrl: 'avatar.client.modal.html', //inline at template controller: function ($scope, $modalInstance) { $scope.user = user; + // Check if provider is already in use with current user + $scope.isConnectedSocialAccount = function(provider) { + return $scope.user.provider === provider || ($scope.user.additionalProvidersData && $scope.user.additionalProvidersData[provider]); + }; $scope.close = function () { $modalInstance.dismiss('close'); }; diff --git a/public/modules/users/directives/tr-avatar.client.directive.js b/public/modules/users/directives/tr-avatar.client.directive.js index c2dde89f4b..1728813993 100644 --- a/public/modules/users/directives/tr-avatar.client.directive.js +++ b/public/modules/users/directives/tr-avatar.client.directive.js @@ -54,9 +54,11 @@ angular.module('users').directive('trAvatar', ['$location', * @link https://developers.facebook.com/docs/graph-api/reference/user/picture/ */ if($scope.source === 'facebook' ) { - if($scope.user && $scope.user.email) { - var fb_id = '#'; - $scope.avatar = $location.protocol() + '://graph.facebook.com/' + fb_id + '/picture/?width=' +($scope.size || defaultSize) + '&height=' + ($scope.size || defaultSize); + if($scope.user && + $scope.user.additionalProvidersData && + $scope.user.additionalProvidersData.facebook && + $scope.user.additionalProvidersData.facebook.id) { + $scope.avatar = $location.protocol() + '://graph.facebook.com/' + $scope.user.additionalProvidersData.facebook.id + '/picture/?width=' +($scope.size || defaultSize) + '&height=' + ($scope.size || defaultSize); } else { $scope.avatar = defaultAvatar; diff --git a/public/modules/users/views/profile/edit-profile.client.view.html b/public/modules/users/views/profile/edit-profile.client.view.html index a26a78476f..0a7e2a3cf1 100644 --- a/public/modules/users/views/profile/edit-profile.client.view.html +++ b/public/modules/users/views/profile/edit-profile.client.view.html @@ -211,12 +211,11 @@

Save your profile first to edit hosting status.

- - !-- When NOT connected to FB-- + +