chok / sfMelodyPlugin

Allow to communicate with many services(google, yahoo...) throw OAuth
MIT License
45 stars 21 forks source link

Update existing user instead of creating new one #24

Closed tobiassjosten closed 13 years ago

tobiassjosten commented 13 years ago

I have an app that has been using sfFacebookConnectPlugin but now I want to switch to sfMelodyPlugin for this one as well. Problem is that I already have a couple of hundred users connected to it and I have no idea how to move them over.

The furthest I've come is by adding the email permission, so to force the approval dialog again. But then sfMelodyPlugin tries to create the user Facebook__12345 and Doctrine crashes with an error saying the user already exists.

Is it possible to somehow have sfMelodyPlugin recognize the existing user and merge with it instead of creating a new one.

tobiassjosten commented 13 years ago

I updated the title to better reflect what I feel is the issue. sfMelodyUserFactory's getUser() method is being called and it indiscriminately calls createUser(). Perhaps there should be some functionality in there that checks for an existing user?

chok commented 13 years ago

You have to specify in your config a way for melody to retrive the existing user.

In fact You can specify key in the user config and if all key exists it does'nt create the user.

tobiassjosten commented 13 years ago

Thanks for the help! I'll try the key approach.

Where would I specify such a retrieve method though?

chok commented 13 years ago

You don't have to specify a method and actually you can't.

You have to do something like that :

all:
  ...
  melody:
    ..
    facebook:
      ...
      user:
        username:
          key: true
          prefix: Facebook_
          call etc....

By default, all value in the user config are key but if you specify a field as key all other are not considered as key anymore so if a user with username Facebook_Id exists he dosen't create a new one anymore.

tobiassjosten commented 13 years ago

Now I finally got around to try this. And it works like a charm, of course. Thanks!