From 7d61fa4712189526f3987b6c656fd3521c4a2de5 Mon Sep 17 00:00:00 2001 From: daFish Date: Fri, 27 Apr 2012 08:30:14 +0200 Subject: [PATCH 1/5] Fixed path to facebook sdk. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48f576a..cef6dda 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Installation # application/config/config.xml Date: Mon, 7 May 2012 12:02:01 +0200 Subject: [PATCH 2/5] Updated yml example. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cef6dda..dc469cf 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Installation # application/config/config.yml fos_facebook: - file: %kernel.root_dir%/../vendor/facebook/src/base_facebook.php + file: %kernel.root_dir%/../vendor/facebook/php-sdk/src/base_facebook.php alias: facebook app_id: 123456879 secret: s3cr3t From d09917cdcb8ac1e08d3e56a26f92f6850de550cd Mon Sep 17 00:00:00 2001 From: MattKetmo Date: Thu, 10 May 2012 22:39:13 +0200 Subject: [PATCH 3/5] Fixed var typo in README --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dc469cf..25797f8 100644 --- a/README.md +++ b/README.md @@ -398,20 +398,17 @@ The following example also adds "firstname" and "lastname" properties, using the */ protected $facebookId; - public function serialize() { - return serialize(array($this->facebookID, parent::serialize())); + return serialize(array($this->facebookId, parent::serialize())); } public function unserialize($data) { - list($this->facebookID, $parentData) = unserialize($data); + list($this->facebookId, $parentData) = unserialize($data); parent::unserialize($parentData); } - - /** * @return string */ From c1ddcc20324933f6069224a03bd14e870c1a30df Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Sat, 12 May 2012 11:21:40 +0200 Subject: [PATCH 4/5] Set the file parameter optional --- DependencyInjection/Configuration.php | 2 +- DependencyInjection/FOSFacebookExtension.php | 7 ++++++- Resources/config/facebook.xml | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1d4cbb2..b37049c 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -39,7 +39,7 @@ public function getConfigTreeBuilder() ->children() ->scalarNode('app_id')->isRequired()->cannotBeEmpty()->end() ->scalarNode('secret')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('file')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('file')->defaultNull()->end() ->scalarNode('cookie')->defaultFalse()->end() ->scalarNode('domain')->defaultNull()->end() ->scalarNode('alias')->defaultNull()->end() diff --git a/DependencyInjection/FOSFacebookExtension.php b/DependencyInjection/FOSFacebookExtension.php index 2d96adc..da243b0 100644 --- a/DependencyInjection/FOSFacebookExtension.php +++ b/DependencyInjection/FOSFacebookExtension.php @@ -40,9 +40,14 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('fos_facebook.'.$attribute.'.class', $config['class'][$attribute]); } - foreach (array('file', 'app_id', 'secret', 'cookie', 'domain', 'logging', 'culture', 'permissions') as $attribute) { + foreach (array('app_id', 'secret', 'cookie', 'domain', 'logging', 'culture', 'permissions') as $attribute) { $container->setParameter('fos_facebook.'.$attribute, $config[$attribute]); } + + if (isset($config['file']) && $container->hasDefinition('fos_facebook.api')) { + $facebookApi = $container->getDefinition('fos_facebook.api'); + $facebookApi->setFile($config['file']); + } } /** diff --git a/Resources/config/facebook.xml b/Resources/config/facebook.xml index 983aaf9..a376d91 100644 --- a/Resources/config/facebook.xml +++ b/Resources/config/facebook.xml @@ -7,7 +7,6 @@ - %fos_facebook.file% %fos_facebook.app_id% %fos_facebook.secret% From a369a1d61d8a8912f2e984414179d96c5fbd226d Mon Sep 17 00:00:00 2001 From: daFish Date: Wed, 23 May 2012 08:42:17 +0200 Subject: [PATCH 5/5] Added integration of existing account. --- README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 25797f8..300b502 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This Bundle enables integration of the Facebook PHP and JS SDK's. Furthermore it also provides a Symfony2 authentication provider so that users can login to a Symfony2 application via Facebook. Furthermore via custom user provider support the Facebook login can also be integrated with other data sources like the -database based solution provided by FOSUserBundle. +database based solution provided by FOSUserBundle including adding Facebook data to an existing account. Note that logging in a user requires multiple steps: @@ -321,6 +321,11 @@ to the provider id in the "provider" section in the config.yml: return $this->userManager->findUserBy(array('facebookId' => $fbId)); } + public function findUserByEmail($email) + { + return $this->userManager->findUserBy(array('email' => $email)); + } + public function loadUserByUsername($username) { $user = $this->findUserByFbId($username); @@ -332,7 +337,12 @@ to the provider id in the "provider" section in the config.yml: } if (!empty($fbdata)) { - if (empty($user)) { + // there might be already a user with the same email adress + if (null === $user) { + $user = $this->findUserByEmail($fbdata['email']); + } + + if (null === $user) { $user = $this->userManager->createUser(); $user->setEnabled(true); $user->setPassword(''); @@ -365,7 +375,7 @@ to the provider id in the "provider" section in the config.yml: } } -Finally one also needs to add a getFacebookId() and setFBData() method to the User model. +Finally one also needs to add a getFacebookId() and setFBData() method to the User model. It also takes care of already registered users. The following example also adds "firstname" and "lastname" properties, using the Doctrine ORM: facebookId = $facebookId; - $this->setUsername($facebookId); - $this->salt = ''; + if (!$this->username) { + $this->setUsername($facebookId); + $this->salt = ''; + } } /**