Skip to content

Commit

Permalink
#7 Enable FB avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
simison committed Dec 11, 2014
1 parent ebf776d commit 9612f9b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users/users.profile.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down
8 changes: 5 additions & 3 deletions public/modules/users/directives/tr-avatar.client.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,11 @@ <h4>Save your profile first to edit hosting status.</h4>
</div>
</div>

<!--
<div class="row text-center">

<div class="col-xs-5 col-xs-offset-1">

!-- When connected to FB--
<!-- When connected to FB-->
<label for="avatar-source-facebook" ng-if="isConnectedSocialAccount('facebook')">
<div tr-avatar data-user="user" data-size="144" data-link="false" data-source="facebook"></div>
<div class="avatar-source-label">
Expand All @@ -225,7 +224,7 @@ <h4>Save your profile first to edit hosting status.</h4>
</div>
</label>

!-- When NOT connected to FB--
<!-- When NOT connected to FB-->
<label for="avatar-source-facebook" ng-if="!isConnectedSocialAccount('facebook')">
<a href="/auth/facebook" class="avatar-source-link">
<div tr-avatar data-size="144" data-link="false" data-source="none"></div>
Expand All @@ -238,6 +237,7 @@ <h4>Save your profile first to edit hosting status.</h4>
</label>
</div>

<!--
<div class="col-xs-5">
<label for="avatar-source-upload">
<a href="#" class="avatar-source-link">
Expand Down

0 comments on commit 9612f9b

Please sign in to comment.