I have a fair number of user profile fields on my site. A good number of them are required, including ones that can be retrieved from Facebook (such as first and last name) and ones that cannot be retried from Facebook (such as phone number). Presently, fboauth automatically creates a Drupal user account when the user registers using the "Connect" button. I'd like the ability to set a switch on the configuration page to instead have the "Connect" button simply pre-populate the fields on the Drupal user registration form with the values it can retrieve from Facebook, and then have the user enter in the rest. The user account would then only be created when the user registration form is submitted (which would allow validation to ensure that all required user profile fields were entered), rather then being created automatically after the user authorizes the site in the Facebook dialog.
I may end up starting coding on this very shortly, so let me know if you have any advice on how best to accomplish it.
Comments
Comment #1
CydeWeys commentedI have this working locally now. I'll submit a .patch file later in the day for anyone else who's interested in this functionality. Ideally it'd be nice if it was incorporated into the fboauth code and available by default.
Comment #2
CydeWeys commentedI just attached a .patch that implements my proposal. Let me know what you think.
Comment #3
CydeWeys commentedI should point out that that .patch file is against the HEAD version from the 6.x branch.
Comment #4
quicksketchThis looks pretty good, but before I could commit it to the project it will need to be ported to Drupal 7 and have similar functionality for the Field module fields on user registration. There are probably a few areas that could use some cleanup code/logic-wise, but I can handle those changes to suit my preferences when this gets closer to completion. Right now this needs the following:
- Add PHPdoc for the new functions, including @param and @return.
- Rather than saying "Drupal registration process" or mentioning "Drupal" anywhere in the UI, I tend to use the word "normal" (e.g. "normal registration process"). This makes the module more suitable for more applications without modification.
- And the port to D7.
Comment #5
CydeWeys commentedCool, that sounds good. I'll get on it and get back to you with those changes and a new patch for Drupal 7 soon.
Comment #6
CydeWeys commentedHere's an updated patch for Drupal 6 and a new patch for Drupal 7.
I want to point out two potential areas of concern in the Drupal 7 patch.
One is that the hook_form_alter for the user register page in fboauth needs to happen after the hook_form_alter in the profile module fires, or it won't work. I handled this ordering by using module_implements_alter, but it's also possible to do it by adjusting fboauth's module weight to be greater than that of profile's. I chose the method I did because it will always work, whereas the module weight method will require the weight to be adjusted in the .install file in an update script, and thus an update will need to be run to get things working. Oh, and if the user doesn't have the Profile module installed when they install fboauth but then installs it later, then this approach won't work, whereas the module_implements_alter approach still does.
The second area of concern is noted in a TODO comment in the file includes/fboauth.field.inc. Let me know if this is indeed the correct way to handle that, or if I'm doing something horrendously wrong.
Oh, and let me know if you need me to make more changes, or if this is sufficient for you to take it from here.
Thanks!
Comment #7
CydeWeys commentedPlease let me know if there's anything else I can help you with to get this patch on its way to being committed.
Comment #8
CydeWeys commentedComment #9
hansfn commentedI just tested this module and it works great. However, the functionality in this issue is crucial. Telling the users to re-edit their profile to add some mandatory fields, just doesn't work. I tried the D7 patch above, but it didn't apply cleanly.
@CydeWeys: Do you mind re-rolling the D7 patch, so I can test and update the status to "reviewed and tested"?
Comment #10
quicksketchIt doesn't look like the D7 version of the patch yet supports Field module fields, so even after a reroll (if it's needed), this patch is going to need some work.
Comment #11
CydeWeys commentedquicksketch, those 26 lines of added code in includes/fboauth.field.inc don't implement Field API support? When I was testing this, values from Facebook were successfully being set on user profile fields. What do you think is missing?
By the way, I've made a slight modification to the D6 patch that was required to meet one of our additional requirements. The previous version of the patch redirected the user to a hard-coded registration page at 'user/register'. In the new version it's configurable as an admin variable. This change should be trivial to migrate over to the D7 patch (which I'll do once we get an idea of which additional Field API modifications are required).
Comment #12
samiu1287 commentedJust tested the module for the Drupal 6.x branch.
Both patches (in comment #6 and #11)(applies on both 6.x-1.4 and 6.x-1.5) they get the information from Facebook, populate the fields, but won't save the user. When you click save, nothing happens. If some of the fields are left empty, but are required, it bring up the correct message.
I've looked through the code, but can't figure out why it won't actually submit the data.
Comment #13
samiu1287 commentedI got it to work under 6.x-1.4 with the patch at #6. I only did one change: unset the cookie after the form has been populated. Apparently, if the cookie is set, the user submission will be stopped and the user registration form with the pre-populated fields will be shown.
Comment #14
tezalsec commentedThis is exactly what I need for my drupal 6.x project.
Now I have just hooked with mymodule_fboauth_action_connect() to make autocreation of users impossible.
Any chance of commit soon?
Thanks for a great module!
Cheers.
Comment #15
iamcarrico commentedI have re-set the D7 patch as well--- it seems to be working, and although there are some minor changes that I would eventually like to make (just to make it more efficient) this should do the trick.
@CydeWeys, can you add in the changes you made after this to the patch? Also--- it does work with the field API stuffs--- although as I said I think we could make it more drupal-y in the future. It was not adding in the username / email field, as those are not in the field API. I added them manually for now--
I am switching the issue to be to that, as this needs further testing.
Comment #16
hansfn commentedOK, I have tested the patch and it seems to work great, but I had two issues:
1) The import of Facebook user picture doesn't work. I guess this is a feature/limitation of not using auto-creation. Maybe we can use hook_user_presave to and the picture code from the function fboauth_create_user, to support picture import?
2) In the function fboauth_module_implements_alter (in the file fboauth.module), I think the correct hook is "form_user_register_form_alter" (and not "form_alter"). If I don't make that change, I get a lot of warnings about undefined index 'fboauth' on line 515.
Comment #17
iamcarrico commentedYea-- I have occasionally after putting in the patch gotten that error. I need to check if that is the best method of changing order in D7---
As for the first issue-- I think it just needs to be added in much like the email address is being added. I think that entire section needs to be re-thought, but I honestly do not have the time right now. I will get to it when I can.
Comment #18
quicksketchHere's a revised patch based on some thinking that I've been doing:
- It cleans up code to follow coding standards a little better (mostly wrapping at 80 characters and fixing formatting).
- I changed the checkbox to use two radio buttons instead for clarity. If you have to include a description that includes, "if this box is not checked..." because unchecking it has a different behavior, it's probably better to use radio buttons and describe each option up front.
- The code for prepopulating fields seemed difficult to follow. Instead of generating a list of $user values from the $fbuser object and then passing that into a form-manipulating function, I just passed the $fbauth object into the form-manipulating function and let it do the work. That way there's less tracking down of mysterious variables.
However, after working on this for a few hours, I've come to the conclusion that FBOAuth is not the right place for this functionality. In order to really do this problem right, you wouldn't want users to have to completely review ALL the information you already know is right. If you're importing a dozen profile fields, the user doesn't have to review all that information. If they want to change it, get them into the site first and then let them change it later. This patch is ruining the *entire point* of Facebook authentication.
I understand the basic idea of this patch. But the implementation is off the mark. What should happen is at most, a few questions about unique and not readily available information should be asked. For example if you had a website about pets, you might ask what pets the user owned. That is a question that may be important to your site, but not available from Facebook.
However, if that were the case, it would be appropriate to ask that question to all users. Not just those going the Facebook authentication. Additionally, if you needed to collect information, you might want to ask the user that question on *every* login until they answer it. Similar to the way Legal module forces you to accept the terms and conditions after they have changed. (Legal module, by the way, works perfectly with FBOAuth using this mechanism).
What should be done here is a separate module should be utilized to ask additional, post-registration questions of the user. FBOAuth can do the work of getting the user information into the site initially, then post (or during) registration, additional questions may be asked, using the same mechanism as Legal module.
I'd actually be very surprised if such a module doesn't exist all ready. And I'm much more inclined to keep this module working as it does currently and depend on a separate module that can do the job better for the additional functionality.
Even though I consider this new patch an improvement, I don't think it (or the original patch) are suitable for this project. After watching multiple Facebook projects crumble under their own weight, I'm keen to keep this project maintainable. But really the stronger reason is just that this module is the wrong place for this functionality in the first place.
Comment #19
quicksketchHere we are: http://drupal.org/project/complete_profile
Comment #20
quicksketchI put a note on the project page mentioning Complete Profile and another module, Profile Fields Force Filling, that does a similar job.
Comment #21
dharmendra singh commentedcan anybody suggest me where is first time fb user registration code,actually i want to add some extra code to get extra info.such as
here we add some more graph query but it only executes when user login.not works first time registration.
so can anyone tell me where we can write this some extra query stuff to get more f info
we need the exact position of user registration. so that we can fetch extra graph query.
in drupal 7
Comment #22
quicksketch@dharmendra singh: I don't normally provide instructions on specific coding questions like this, but there's already a fairly extensive description of how to capture additional information through the hooks FBOAuth provides in the README.txt file. It should only take a skeleton custom module plus what's in README.txt to accomplish what you want.