views:

16

answers:

1

I am trying to implement a simple login system with facebook, but I need users to pick a username. What I was thinking was to get all the information I need from facebook, request permissions, then add the information to the database, redirect to a form asking for a username and then add that to the database, to the same entry.

I think a transaction is needed so I don't end up with any half completed database entries. But I've only ever used them on the same page, so I'm wondering if this is safe? If it fails then there is no point where I would be telling the database to roll back the changes and it would be with a transaction open.

Is this right or will it be ok?

A: 

I think you made it more complicated than it should be :)

No need to enter facebook id into database before username as you can always grab it later.

  • Forward user to login screen (or better just open login popup using javascript FB API)
  • Once user is logged in forward them to username picking page (or better do javascript popup without page redirect)
  • When user is entered username request the current user id from facebook on server side (by either using graph api or fql) and then if everything is ok enter this record to database.
serg
So when they do the log in I could request permissions then and also put their first and last name and profile picture url into a session so I can add these to the database entry also?
Michael Mallett
@Michael you can get all this info from facebook at any time, it might be not even worth putting it into database (other than facebook userid and your custom fields like username). Just make sure you requested all required permissions (with `offline_access`), that way you can get this info anytime anywhere.
serg
The names aren't really necessary I agree. But the picture url I would like to put in the database as they have a choice of using their own upload or their current profile picture. I don't want there to be too many profiles with the default picture, because it will look rubbish. Thanks very much for your help. Now to figure out why I am getting a redirect loop when I request permissions.
Michael Mallett
@Michael I would suggest you store picture only if it is not from facebook (was uploaded). If they chose to use facebook one then you can always get it later (and if you store it in database it might become outdated if they change their avatar on facebook).
serg
Isn't there a permalink you can get from facebook that is your profile picture and therefore updates when they change it? That's all I would store in the database, I'm not actually saving their facebook picture
Michael Mallett
@Michael Yes there is a permalink and all it requires is user id: `<img src="https://graph.facebook.com/<USER_ID>/picture"/>` You can store this image url if you want, but I would rather just store userid.
serg