Posted by gallamine on October 28, 2009 at 2:06am
Jump to:
| Project: | Drupal for Facebook |
| Version: | 6.x-3.x-dev |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | fb3-blocker |
Issue Summary
I need my users to choose a unique and memorable username. I also want them to use Facebook Connect. I've disabled "Create Local Account: " but I want anyone that logs in via Facebook Connect, that doesn't have a Drupal site account, to be redirected to the registration page - so they can enter an email address and username.
Is it possible to redirect a user to the registration page after they successfully logged in via Facebook Connect?
Comments
#1
+1
#2
Two ways to accomplish this (maybe more). With javascript, or PHP. I'm more comfortable with PHP. The first thing I'd try is implementing hook_fb, something like the following (untested code)...
<?phpfunction custom_fb($op, $data, &$return) {
if ($op == FB_OP_APP_IS_AUTHORIZED) {
// This will be called on every page where user has authorized the app.
if (!$GLOBALS['user']->uid) {
// user has not registered.
if (arg(0) != 'user' || arg(1) != 'register') {
drupal_goto('user/register');
}
}
}
}
?>
That code has not been tested. Let me know if it works for you. It's also heavy-handed. You might add some logic to redirect the user only once per session, or allow them to visit more pages than just user/register.
#3
I am trying to achieve something similar to this, except that I am trying to embed the facebook connect button on the user registration page. Right now when the user clicks the connect button, they are logged in and then shown access denied because authenticated users cannot see the registration page. It would be nice to maybe use the value of drupal_get_destination() somehow...
When I look into the javascript, I see that the connect button triggers the following function:
function fb_connect_login_onclick() {// This will execute before the user fills out the login form.
// More important is fb_connect_on_connected, above.
}
which references the function below in its comments but appears to do nothing than register itself as event:
function fb_connect_on_connected(fbu) {//alert("fb_connect_on_connected " + fbu + " settings fbu is " + Drupal.settings.fb_connect.fbu + " fb_connect_fbu is " + fb_connect_fbu);
if (fb_connect_fbu === 0 || Drupal.settings.fb_connect.fbu != fbu) {
// We've gone from not connected to connected.
window.location.reload();
}
fb_connect_fbu = fbu;
}
This function is apparently where the page reload happens, but it looks like having a destination would require a Drupal.settings.fb_connect.destination or something like that to not require too much modification to the code.
For your purposes, gallamine, I think that you can either change this window.location.reload() to a window.location.href = 'user/register' (if you don't mind a hack that could be overwritten with a module update) or writing a custom module which adds a javascript file that overwrites this function (to avoid conflicts with module updates later).
I don't know if this helps or if I am just rambling, but I am also interested in the outcome of this thread, so at least I am subscribing to it.
Sean
#4
The javascript you're quoting is out of date. I recently made some changes (to better support benharper.com which is using this).
The function your talking about (now called FB_Connect.on_connected, but more imporantly there's an event, 'fb_connect_status' which is triggered) is called very frequenly. On every page load, maybe more, not just when the user clicks through the login box. That's why the crazy logic deciding whether to reload the page or not. It's trying to reload so that drupal is aware of who the current user is. This code will get executed after a user clicks through the login box, and it will also get called if the user logs out of facebook then logs back in and visits your site.
If you want to do this in javascript...
Try changing the XFBML of the login button markup. Have it call your javascript function instead of FB_Connect.login_onclick().
In your javascript behaviors, bind to the 'fb_connect_status' event some other function.
In your login_onclick() function set some global so you know later the user is logging in.
In your fb_connect_status handler, check whether your global is set an whether the user is logged in. If both, then redirect to the registration page.
#5
And yet another approach...
Take a look at fb/contrib/fb_permission.module. See fb_permission_fb(), $op == FB_APP_EVENT_POST_AUTHORIZE.
This is code that is called only after the user has authorized the app for the very first time. So if you want to redirect only once, say to the user/edit page if you've allowed DFF to create the user for you, then you can add some javascript to do the redirect. See how fb_permission_fb() calls fb_connect_init_js().
(It's complicated this way because the FB_APP_EVENT_POST_AUTHORIZE is called by facebook, not the user's browser. So the javascript has to be added to a subsequent page load.
I don't think there's any one technique that applies to all sites. But you all should let me know what you end up doing to solve this. If one solution seems really workable I'll add it to modules/fb or modules/fb/contrib.
#6
Sorry for the very long delay. I had a new baby between now and then. Anyway, I tried your original code (post #2). My function is.
<?phpfunction fb_reg_force_fb($op, $data, &$return) {
if ($op == FB_OP_APP_IS_AUTHORIZED) {
// This will be called on every page where user has authorized the app.
if (!$GLOBALS['user']->uid) {
// user has not registered.
if (arg(0) != 'user' || arg(1) != 'register') {
drupal_set_message('You must create a username');
drupal_goto('user/register');
}
}
}
}
?>
It works ok, but there's a few problems:
1) A user can never log out of the Drupal site, but still be logged into facebook - it "traps" them on the user/register page. Is there a way to make the standard drupal /logout also log the user out of Facebook?
2) If a user logs into FB, and has already linked to a Drupal account, the message is still printed, but they aren't directed to the user/register page - I don't know why
I'm still a Drupal n00b when it comes to writing modules, and I have no Javascript experience, so I need to digest what you said in Post #5.
#7
regarding #1, that's how facebook connect works. If a user logs out of facebook, or any connect site, they are logged out of facebook and all connect sites. It's like a single sign-on for all facebook connect sites which the user has authorized.
regarding "traps" them on the user/register page, I thought that's what you wanted.
regarding #2, the fb_user.module uses the same event, FB_OP_APP_IS_AUTHORIZED, to set the
$GLOBALS['user']variable. So perhaps your modules weight needs to be greater than that of fb_user.module for this to work. Try tweakin gthe weight in your system table and see if it helps.#8
Dave,
Sorry if I haven't made myself clear.
1) The issue I had may have been some wierd result of block caching. I turned off block caching (using blockcache_alter module) on the FB Connect block, and now when I hit /logout it logs me out of Drupal & Facebook - but not before sending me back to the user/register page (which I can deal with).
2) I will look into this. For anyone else who may be confused, I found this article on changing a module weight: http://agaric.com/note/set-weight-a-drupal-module
#9
I can't seem to get either #2 or #6 to work
#2 redirects to the user/register page no matter what, so you can't login or view any page on the site.
#6 doesn't redirect at all and the connect with facebook button also seems to not work
I only want to redirect to the user/register page if you select the connect with facebook button and the user doesn't already have an account.
#10
Sorry just realised that #6 does work but I have the same issue where if a user is logged into Facebook they are always directed to the user/register page.
This isn't ideal as the user may not want to register on our site, but if they are logged into facebook they don't get the choice. I really would like the redirection to occur only when they have clicked the connect with facebook button and to ignore whether they are logged into facebook or not.
#11
Marcus178, I think the problem is that you're using a user that's already tried to connect with Facebook Connect. Try this:
find the user's fbu and delete that entry from the fb_user_reg table in the Drupal database, then clear your cookies. Now if you visit your Drupal site, while logged into Facebook, you won't be directed to the user/register page until *after* you've initiated and finished the Facebook Connect procedure.
This took me a bit to figure out, but I've confirmed with my own FB account and with a friends.
#12
There is no fb_user_reg table, I think you mean fb_user_app. But that table does not control the mapping between the local account and the facebook account. Only the authmap table effects that, so if you need to delete a row, that's the row to delete.
This problem of redirecting the user to a particular page... I consider it a Drupal problem and not a Drupal for Facebook problem. That is, drupal gives you ways to customize this kind of behavior. I don't think a new way needs to be added to modules/fb.
#13
Ok I've tried removing the user from authmap and clearing my cookies, but I still get the same behaviour.
If a user is logged into facebook they are always directed to the user/register page. This isn't usable a they could just want to browse our site without creating an account.
Just to confim this is the code I'm using
function fb_reg_fb($op, $data, &$return) {if ($op == FB_OP_APP_IS_AUTHORIZED) {
// This will be called on every page where user has authorized the app.
if (!$GLOBALS['user']->uid) {
// user has not registered.
if (arg(0) != 'user' || arg(1) != 'register') {
drupal_set_message('To connect with Facebook you must create an account first.');
drupal_goto('user/register');
}
}
}
}
#14
Marcus178,
So if you got to Facebook and create a completely new user, then visit your Drupal site, it redirects you?
Dave Cohen,
Are you saying that the authmap table is the ONLY table that links drupal users to facebook users? So if that table is empty, then DFF should never redirect to the user/register page as in the above snippet of code?
#15
No, if a user is logged into facebook then visits my site they are always taken to the user/register page. This is no good as they might not understand why this is happening and might just want to browse the site without registering.
I think I need a different approach to this using javascript so that when they connect using the connect with facebook button they are then redirected to the user/register page if they don't have an account.
#16
Ok, I seem to be having an intermitant problem with this too.
I tried visiting my site (http://beta.robotbox.net) with my wife logged into Facebook (in Firefox). She hasn't used Facebook connect on the site before. When she went to the site, she was immediately redirected to the user/register page. I then looked for her FBUID in the Drupal database and found it in the fb_user_app table, and in the captcha_sessions table. I deleted both instances, and removed all cookies from robotbox.net. I then tried again with the same affect. I also tried in Chrome with the same affect.
I also just had a site visitor email me and ask if I'd turned off anonymous browsing on the site because he's being redirected.
However, if I create a brand new user on Facebook and visit my site, I'm not redirected.
I'm pretty baffled here.
#17
marcus178,
If you log into Facebook and then visit my site, http://beta.robotbox.net - are you redirected to the user/register page? I'm curious.
If you have a page up for your site, I can test on my end too.
Also, Vishal Sood just updated his FConnect module (http://vishalsood.com/projects/drupal/facebook) to let users create an account. You might want to investigate how he's doing that. I haven't had time to look into it yet. I was using his module before switching to DFF (perhaps a bit too soon it may seem).
#18
Hmmm, no I'm not. Yours works exactly how I want it to. Very strange. Please could you repost your code so I can check it against what I have.
#19
Guys, I think there are a number of options here. It's not one-size-fits-all, and I think you're trying to do different things. I think this calls for a page in the documention and the various approaches. For now let's use this thread to see what works...
marcus178, here's a simple approach that may get you most of what you want. Edit the facebook connect login block, and change the connect button to have a different onlogin attribute. It may be as simple as (note I have not tested)...
<fb:login-button onlogin='window.location="/user/register";'></fb:login-button>That would redirect the new users, but also the returning users who's sessions have expired, and therefore clicked the button again. To handle them differently, you could send all users to a custom page callback which either sends them to user/register if the account is new, or somewhere else if they are returning users.
Another approach is to handle that logic in javascript. Take a look at fb_connect.js, specifically the
FB_Connect.statusHandle()function. This gets called whenever the user goes from being not connected to connected and vice versa. Let's say you want to change the logic in there to forward some users to /user/register. To do that, implement a custom_mod module which adds its own custom_mod.js javascript to each page. In custom.js, so something like...Drupal.behaviors.custom_mod = function(context) {
// FB_Connect.statusHandle will reload pages when status changes.
// To prevent that behavior, we unbind that handler.
$(document).unbind('fb_connect_status', FB_Connect.statusHandle)
// Handle changes between connected and not connected.
$(document).bind('fb_connect_status', Custom_Mod.statusHandle);
};
Custom_Mod.statusHandle = function(e, fb_data) {
// if login or logout detected
if (fb_data.changed) {
if (!fb_data.fbu) {
// logged out
// CUSTOM LOGOUT LOGIC GOES HERE.
}
else {
// login
// CUSTOM LOGIN LOGIC GOES HERE.
}
}
};
As far as I know, there's no simple way to learn "is this user brand new, or just returning?" To learn that might take a call to the drupal server or maybe some method of the FB.Connect API. I'm really not sure.
#20
Dave Cohen,
Thanks for the reply. Is there a reason why you think the solution in #2 and #6 won't work? Is it ever possible for a new user, who's currently logging into Facebook in anther tab, to get redirected to the user/register page without ever having clicked on the "Facebook Connect" button (like the problem described in #10 - #17?)
Also, in regards to your latest reply, I need to clarify:
1) Am I correct in understanding that using "onlogin='window.location="/user/register"" directive isn't such a good idea because a user will be redirected to user/register every time they click the Facebook Connect button, not just the first time? So you suggest that instead we direct the onlogin location to a page (you call it a "custom page callback". EDIT: So something like described here http://api.drupal.org/api/drupal/developer--examples--page_example.module/6) that checks to see if the FBU is associated with a drupal UID, and if not then direct them to user/register. How exactly is this different from the solution in #6?
2) The second, javascript based, solution is to override the .statusHandle() function such that a newly created javascript function now handles the logic to try and determine if the current Facebook user has a Drupal account? This javascript function is called when the user clicks the "Facebook Connect" button, and it should then redirect the user to the appropriate location.
It seems that if I want to force my users to create a Drupal username, I will need to either get the solution in #6 to work, or implement the "custom page callback" to work.
Sorry for being so dense. I'm still trying to wrap my head around writing my own Drupal modules (the module in #6 was my first). I may just have to pay someone to help me write it.
#21
Maybe I've misunderstood what you want. Maybe I still do. But now it sounds like what you want is to simply set the "create users" option to "never" on your Facebook Application. That way, users can browse your site to their hearts content, and they won't have an account until they give you name, email and whatever else you ask for on the registration page.
#22
Dave Cohen,
Sorry. My requirement is that each user must have a unique and human readable username before adding any content to the site. I want to link the Facebook Connect and Drupal registration process to remove confusion on my user's part.
In other words, my requirements are:
1) Allow users to log into Drupal site via Facebook Connect
2) Anonymous visitors who click "Facebook Connect" are a) connected via Facebook and b) forced to choose a unique username and c) logged into the Drupal site so they can add content - no content is added to the site without the user having a chosen, readable, username.
3) Existing site users can choose to link their Facebook account w/ their Drupal site account, and subsequently only use Facebook to log in.
4) Make the process of adding a Facebook Application canvas page easier down the road (which is why I'm using this module and not other Facebook Connect type modules).
Does that clarify things?
#23
Hmmmm...
Well using what I described in #19 you can write some javascript to launch when they connect. Maybe there you check for a name and if not known, pop up a dialog.
You could let DFF create the account for you, whether the name is known or not. But don't allow them to post until the name is provided.
Since you also allow them to browse the site before providing a name... maybe use hook_form_alter() to add a name field to forms that would otherwise not have them. So until the user has given a name, prompt for it on the comment or node form.
I invite you to share what you come up with.
#24
Dave - I think I am in the same boat as gallamine and wanted to get your feedback on if what I'm wanting to do is possible. Here are the scenarios I want to have happen...
1. Facebook User (who hasn't authorized connection) ---> Visits site as anonymous user
2. Facebook User (who does not currently have drupal profile) authorizes facebook connect ----> Profile is created and user is redirected to profile page in order to create a unique username and enter email address. This redirect only happens upon new profile creation.
3. Facebook User (who has previous drupal profile) logs into drupal site and facebook connection occurs automatically.
These are all the scenarios I see happening with users of the site. Any advice at how to go about doing this? I'm newer to Drupal and got lost in the last few messages back and forth.
Thanks for your help
#25
Really? You want to redirect the user one time to a form, but you don't care whether they fill it out or submit it?
The code I posted before will force them to fill out a form in order to create a local user account instead of the modules creating an account for them. If you think it over, that may be what you really want.
But if you really want to do something only the first time someone logs onto your system it gets complicated. Facebook sends an event to your server the first time someone authorizes. If you look in fb_permission.module for FB_APP_EVENT_POST_AUTHORIZE you'll see some code that reacts to that event. Just bear in mind...
1) It is facebook pinging your server, not the user's browser. So you cannot for example use drupal_goto() to redirect them.
2) You may never receive this message. A hiccup in the internet and its lost forever.
3) You may get this message more than once. For example if a user un-authorizes then later re-authorizes your app.
On second thought another option is to do this when the local account is created. In that case implement hook_fb() and look for FB_OP_POST_USER. But again it may be called when facebook pings the server or maybe the users browser, you can't be sure.
On the other hand, you could attach some javascript when the user logs in via facebook connect. Trouble is this happens every time they log in, not just the first time they create an account.
Personally I would not build a site like you guys describe. The way I see it, either the extra information is necessary in which case I would force them to fill it out before moving on. Or its not necessary in which case I would let them fill it out whenever they want or never.
#26
Thanks for the quick reply Dave!
I think you and I are saying the same thing but I just didn't say it right. I want a user when they first authorize facebook connect to then be forced into the page to edit their local drupal account that was already created by the module. The information there is necessary and the module only provides their UID from facebook for their username. I want them to feel that this is all part of one process so they authorize and then edit the account to their liking. However it seemed like the solution above would redirect them to register more than just that first time since you are talking about the javascript in #19 with the FB_Connect.statushandle().
Looking through fb_user.module I see the section starting at line 415 that I can ask for the user's email from facebook. Is this the what is handled in extended permissions? If so I can have this email be attached to their drupal user account correct? If this is the case then all I have to do is have them choose a unique UID for the drupal account so I do not run into the NNNNN@facebook.com issue I am having. Is it possible to insert something around line 700 to redirect to a simple page with a username form? Or to push a popup that recommends they visit their user account to create a unique name? By this point I already have a username and email so I my form is complete I just want them to not have to use their fb uid for forms etc. and when I send out sitewide emails and address username it will not look right.
I really appreciate your advice in this. Drupal for Facebook has really allowed me to create a great user experience. I'm just trying to solidify the admin side of things so I can have contact info for all my users.
Thanks Dave!
#27
If you want the user to fill out that form, my recommendation is tell drupal for facebook to not create an account. When they fill out a registration form, drupal will create the account as it normally would. You'll know their name and email then. And Drupal for Facebook will write the authmap entry.
I just don't see a reason to create the account automatically with incomplete information then force them to a page to provide the extra info.
#28
Great point Dave! I think I will do that. The authmap connection works so well that I think it would be best to separate the two.
Thanks for your insight on this and for creating such a powerful module! I look forward to seeing where the development goes and hopefully add as much as I can to it.
#29
I've just looked at the Facebook Connect module as this works great. If your logged in to facebook and click the connect button you are given the option to connect using an existing drupal account or to create a new one.
So I may switch to this for connecting and use Drupal for Facebook for the canvas page side of things as long they work happily with each other.
#30
If someone wants to see a useful example of what we're talking about (not built with Drupal), I'd *LOVE* to be able to implement the signup process that http://www.gdgt.com has. Try hitting "register", then "Connect with Facebook". After connecting with Facebook, you're brought to a modal box that requires you to a) enter a username or b) link to an existing site account. That's *exactly* what I'm looking for. Now I have to figure out how to put it all into a modal box you can't close ...
#31
I think what I'm trying to do is similar to what others have described here, but there seems to be a good deal of confusion and no real solution as of yet. The central issue is that every user wishing to participate on my website must fill out a user account registration form on my website. I need to have them choose a real user name, give me their email and other info, verify that they're over the age of 13 and agree to the terms and conditions of my website. My situation is also complicated slightly by my use of the Content Profile module to store user info. Here's how I see this issue playing out:
If a new user comes to my website, they should see the "Connect to Facebook" button, whether or not they're already logged into Facebook. No accounts should be automatically created on my local website without user initiation.
If a new user clicks the "Connect to Facebook" button, they should first be prompted to authorize the application (and logged into Facebook if they aren't already). They should then automatically be taken to the website's registration form, so they can fill out the rest of the required account information. If there's any way some of the form fields could be pre-filled with Facebook account data, that would be ideal, but I think I remember reading that it be against Facebook's terms to do so. When they submit that form—and only when they submit that form—a local account should be created for them on my website, which is linked to their Facebook account.
If a new user creates a local account through my website's registration form, then I would like them to be prompted to link the account with their Facebook account as part of that process. This could mean that the FB application authorization window automatically pops up after they submit the local account registration form, if—and only if—they didn't already authorize the application by clicking "Connect to Facebook" to initiate the registration process.
If an existing user logs into their local website account and they have not yet authorized the FB application, but they are already logged into Facebook, then they should automatically be prompted to authorize the FB application (at least the first time this happens). If they authorize it then their accounts should be linked, but they should not be redirected anywhere.
If an existing user who has not yet authorized the FB application is logged into their local website account, but not logged into Facebook, and they click the "Connect to Facebook" button, they should be prompted to authorize the application. If they authorize it then they should automatically be logged into Facebook and their accounts should be linked, but they should not be redirected anywhere.
If an existing user who's already authorized the FB application returns to the site and they are currently logged into Facebook, then they should automagically be logged into their local account on my website, without doing anything or being redirected anywhere.
If an existing user who's already authorized the FB application returns to the site and they are NOT currently logged into Facebook, or their local account, and they push the "Connect to Facebook" button, they should be prompted to log into Facebook and then automatically logged into their local account. They should not be redirected anywhere after logging in. If instead they just log into their local account, ideally they should automatically be logged into Facebook too (I don't see why this shouldn't work both ways). If that isn't possible with the Facebook platform, then I would like the option of prompting them to log into their Facebook account after they log into their local account. If that isn't possible, or if they choose not to log into Facebook when first prompted, then they should see the "Connect to Facebook" button. If they push the button, they should be prompted to log into Facebook, but should not be redirected anywhere after authenticating.
I think this covers just about every possible scenario and all of this seems like reasonable expectations from a user experience perspective (at least in my humble view, though I'm open to suggestions). I think it would be extremely beneficial to document some best practices for implementing these features with DFF. Something that people like myself, who do not have a computer science background, can easily follow. Ultimately I think these features should be built into the DFF modules as configuration options. I expect that they are useful to enough websites to warrant their inclusion.
Philosophically speaking, I like DFF's basic approach to supporting multiple Facebook applications and segmenting different features into different modules which can be enabled as needed. I'm interested in using DFF because at some point I may want to create one or more Canvas Facebook applications which link to my website. However, for the time being, it is Facebook Connect which is driving me. Specifically, I want to make it extremely easy for anyone who posts on my site to automatically post on their own wall. The idea being that all their FB friends will see them using my website and be motivated to start using it themselves. I'm essentially trying to steal users from Facebook and get them to spend some time on my site, which means I need to keep my website and its local accounts as the primary focus of this exchange. In fact I would be shocked if anyone was developing Facebook Connect applications out of some altruistic desire to help Facebook's bottom line. We're all just trying to tap a little something from the source to feed our own traffic needs, so anything that makes that easier to implement in a more user friendly way would be a huge benefit.
#32
Dave Cohen,
Since this whole discussion was kicked off because FB wouldn't let you save the user's name into the database permanently, is this now a non-issue because of the new Graph API and all that? I've been reading the new docs, and there isn't anything I can find that makes this against the TOS. Am I correct?
#33
You're correct that the TOS has changed. Now, you can save the user's name and other data learned from facebook.
But I think this is still an issue. For example, to direct the user to a form after they first authorize the app.
#34
Yes. This still doesn't fix my problem with age verification and acceptance of my terms of use. For that They'll still need to go to the registration form. But I assume this means we can pre-fill that form when they get there now?
#35
#34, Have you tried creating a new role with privileges for the user who has verified age and accepted terms? You can then design a simple webform that assigns the role on submit using rules.
#36
@srinikasturi
I'm not exactly sure what you're suggesting. Every user on my site needs to submit the registration form before becoming an authenticated user, so no additional role should be necessary. The question is, when a new user comes to my site and clicks the Facebook Connect button, how do I guide them through that registration process and make it as painless as humanly possible?
#37
What about 2 new fields on the module, where we would specify redirect url for:
1) When automatic registration is enabled
2) When it is not
Also, if the module could grab FB user email, and name, that would be good, because current generated username really doesn't look good.
#38
#36, this requirement has nothing to do with this module, as far as I can see. There are some ways in Drupal for this to be achieved without writing a single line of code. You will first need to remove all permissions for auth user. Now create a new role, say, 'reg_user', and assign the permissions to this user.
Now, whenever someone logs in for the first time using FB Connect, they will get a 403 error.
Now, use the front_page module to define the homepage for the regular auth user role to be 'user/me/edit'. You will need the me alias module to be installed for this. Also, set login destination to front_page.
Now, use the rules module to assign the 'reg_user' role on submission of the user edit form. You can trigger this role to be assigned on any event of your choice. You might even create a separate event that all users go through, even those not using FB so that the role is assigned. It could be something like accepting a t&c page. Role auto assign might not work as FB users might also get the role assigned when their local account is created (unless you turn that off). As you can see, there might be a few possible workflows and you need to see what works for you.
Now the auth user will also have the new role and will stop getting the 403 error, and will be able to enjoy your site. In any case, as a workflow, your user won't see the 403 as they'd go straight into registering, unless they try to click around the menus or any other links.
For a bit more elegance, use a custom 403 message.
That's my suggestion as a person who doesn't know how to write code
#39
subscribing
#40
I've changed the way things work in 3.x.
Now on login, javascript will call ajax, the ajax callback will invoke hook_fb ($op == FB_OP_AJAX_EVENT and $data['event_type'] == 'session_change'). Implement that hook, and in the $return array you can place a bit of javascript, like say window.location('http://foo/bar'), and that will execute when the ajax returns.
I'll post an example when I have one. I just wanted everyone to know this will be fairly easy in 3.x release.
#41
subcribing
#42
@Dave: No pressure, but do you have a rough ETA on the 3.x release?
#43
Subscribing
#44
>> I'll post an example when I have one. I just wanted everyone to know this will be fairly easy in 3.x release.
Something like this Dave?
/*** Implementation of hook_fb
*/
function fb_module_fb($op, $data, &$return) {
switch ($op) {
case FB_OP_AJAX_EVENT:
if ($data['event_type'] == 'session_change') {
$retval = array("window.location('http://foo/bar')");
}
break;
}
return $retval;
}
#45
yes! Something very close to that.
A couple things...
the 'session_change' could be on login, or logout. You can check the $data passed in for an fbu. If the fbu is set, the user is logged in.
If supporting canvas pages, you're better off with "window.location.top = 'http://foo/bar';"
#46
subscribing
#47
subscribing
#48
I couldn't get the above solution to work with the latest 3.x dev release.
I know this isn't pretty but if anyone needs a quick-and-dirty solution to make facebook connect respect a destination query string, you can do it in javascript ( this was taken from fb.js ):
FB_JS.reload = function(destination) {
var locObj = window.location;
var destStr = "?destination=";
// if there was a destination set...use it
if (locObj.href.indexOf(destStr) != -1) {
// the requested destination
var destination = locObj.href.replace(locObj.pathname, "")
destination = destination.replace(destStr,"/");
window.location = destination;
}
else {
// bring them to the user page
window.location = "http://" + locObj.host + "/user";
}
};
I'd definitely appreciate criticism of this approach and a better way of doing this...I just need something to work today
#49
I think the problem is the FB_OP_AJAX_EVENT is not getting triggered. Here are the events that I've seen triggered on login using this snippet.
/*** Implementation of hook_fb
*/
function fb_module_fb($op, $data, &$return) {
dsm($op);
switch ($op) {
case FB_OP_AJAX_EVENT:
if ($data['event_type'] == 'session_change') {
$retval = array("window.location('http://foo/bar')");
}
break;
}
return $retval;
}
fb_op_jsexit
current_app
get_app
init
app_authorized
post init
get_app
#50
this is the correct code snippet...
/*** Implementation of hook_fb
* @param $op
* @param $data
* @param $return
* @return void
*/
function fb_mymodule_fb($op, $data, &$return) {
switch ($op) {
case FB_OP_AJAX_EVENT:
if ($data['event_type'] == 'session_change') {
$return[] = 'window.location = "<your url here>"';
}
break;
};
}
works very well...
#51
Ok. Now I've run into a snag that only David (I think) can help.
David - is it possible for one to get the user UID on login. Here's my code snippet.
/*** Implementation of hook_fb
* @param $op
* @param $data
* @param $return
* @return void
*/
function fb_mymodule_fb($op, $data, &$return) {
global $base_url;
dsm($op);
switch ($op) {
case FB_OP_AJAX_EVENT:
if ($data['event_type'] == 'session_change') {
$user_location = $base_url . '/user/' . $GLOBALS['user']->uid . '/edit/profile';
$return[] = 'window.location = "' . $user_location . '"';
}
break;
};
}
This is redirecting me to user with uid = 0, the anonymous user. Actually, I want to redirect to the current user's UID's profile node.
#52
It's tricky because...
(a) session_change could be a log out (not login), in which case you'll send the user to the front page.
(b) depending on fb_user.module configuration, it might be using this same hook to create a new user. In this case, you'll want your module weighted heavier than fb_user.module
That said, try
// untestedif ($data['fbu']) {
$account = fb_user_get_local_user($data['fbu'], $data['fb_app']);
if ($account) {
$url = url('user/' . $account->uid . '/edit/profile', array('absolute' => TRUE));
$return[] = "FB_JS.reload($url);";
}
}
#53
Right now, fb.js subscribes to the session change event, because that's the one fb_user.module really needs. Customization like you're talking about might be easier if it also subscribes to the login event.
It would mean additional overhead of calling multiple ajax events (one for login and another for session change, and possibly more if we add 'logout' etc). Maybe this is worthwhile, I'm not sure.
#54
If I understand what you're saying, than I definitely think you need to subscribe to the login event. Not so sure about logout. What else does session change encompass?
#55
Yeah I think so too. I'm wondering if it's because we're subscribed to the session change event the user is logged into any Drupal for facebook powered site when s/he logged into Facebook. It's a bit jarring IMO and I don't see the same behavior in many other FB connect sites. If that's the case definitely need to subscribe to login
I tried the code David and it didn't seem to work (probably related to module weight). However, I went a different route and decided to raise a modal iframe on the front page with the prompt for the user to create the profile page in there. I still use Drupal for FB to pull data from the FB profile to help the user out if that's the case.
-R
#56
Here's a snippet for redirecting a user after their account is created: #919072: Provide an option to redirect the user to profile edit page when account is created the first time
It's almost the same thing this thread is talking about.
#57
There's a big difference between allowing someone to edit their profile after they log in and requiring them to register prior to profile creation. Are we any closer to the latter?
#58
The latter is simple. Tell modules/fb to not create new user accounts. There's a checkbox for that.
Then, an account will be created only when the user fills out the registration form.
#59
But will that account automatically be linked to their Facebook account? And better yet, can fields in the registration form be automatically populated with data pulled from said Facebook account?
#60
If the other checkbox, to map accounts, is checked then the accounts will be linked. fb_user.module will fill in the users name and email (if available, requires email extended permission). Anything else, you'd have to write your own hook_form_alter() to fill out.
#61
Marking this as needing documentation before 3.0 release.
BTW a relatively easy way to make a link that will log in a user and send them to a specific page (some/path) is
<a href="#" onclick="Drupal.settings.fb.reload_url='<?php print url('some/path', array('fb_canvas' => fb_is_canvas(), 'absolute' => TRUE))?>';FB.login(function(response) {}, {perms:Drupal.settings.fb.perms}); return false;">Connect with Facebook</a>I think the login button takes a similar onclick attribute but I'm not certain.
#62
See http://drupal.org/node/969242.
#63
Automatically closed -- issue fixed for 2 weeks with no activity.
#64
bookmarking this
#65
hey where should i put this code???