The user and email exists in the bd
What happens when is the user already registered in the database?
I did that this bundle works. But now I have a problem. An user which exist in my web, when he log with facebook, he get an error: this email xxx already exists in the bd
How I can solve this problem?? And associate the users with its count of facebook...
Thanks! ; )
It depends of what you are doing in your own code. FOSFacebookBundle itself does not use any database.
thank @stof for reply!
I have FOSUserBundle and FosFacebookBundle.
And when I log with facebook, I get the error: This email exist.
How can I associate an user with facebook ID ? Any idea? Thanks!
Anyone ? pleeease any idea ?
In your Facebook provider, in the loadUserByUsername function:
public function loadUserByUsername($username)
{
$user = $this->findUserByFbId($username);
try {
$fbdata = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
$fbdata = null;
}
if (!empty($fbdata)) {
$userByEmail = $this->userManager->findUserBy(array('email' => $fbdata['email']));
if (!empty($userByEmail)) {
$user = $userByEmail;
}
elseif (empty($user)) {
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setPassword('');
}
// TODO use http://developers.facebook.com/docs/api/realtime
$user->setFBData($fbdata);
if (count($this->validator->validate($user, 'Facebook'))) {
// TODO: the user was found obviously, but doesnt match our expectations, do something smart
throw new UsernameNotFoundException('The facebook user could not be stored');
}
$this->userManager->updateUser($user);
}
if (empty($user)) {
throw new UsernameNotFoundException('The user is not authenticated on facebook');
}
return $user;
}
And you can after change your setFbData in your User class if you don't want the username and salt to be updated.