4

I have a special use case I can not solve. When the user click on Facebook Connect and find an similar email in my DB. I want to ask the user if the account belongs to him.

If the answer is yes, he needs to connect with his account and then add the Facebook ID in the DB.

If the answer is no, I create a new user in the DB and log in.

I don't find the best way to do this. Can someone help me ?

iamdto
  • 1,372
  • 11
  • 23
JeremyP
  • 575
  • 1
  • 9
  • 20
  • I have implemented a facebook provider and in the method LoadByUsername. When it detected the Email exist, I try to transmit data to a controller. I don't know if it is the best way. – JeremyP Jan 24 '13 at 09:55

1 Answers1

3

In controller you can check whether email exists in DB or not using fos user bundle user manager

$user = $this->get('fos_user.user_manager')->findUserByEmail($email);

After user confirms, you can use implemented facebook provider to do necessary action.

between, I have a question for you,

"If the answer is no, I create a new user in the DB and log in."

how do you create a new user with same email (assuming email is unique)?

Venu
  • 7,243
  • 4
  • 39
  • 54
  • I check already if the email exist but in my case, the problem involved when i want to ask if the account belongs to the user who try to connect. – JeremyP Jan 24 '13 at 18:10
  • Why you want to confirm gain? as user had already verified his email with facebook. I would ignore that step. btw, what is the problem? – Venu Jan 25 '13 at 03:59