how can i change destination page after fboauth, default it's user profile page

Comments

dmegatool’s picture

It's getting me to the home page. I'll like to redirect the user to the page he was when it clicked the login link... Don't know how to.

b8x’s picture

i tried rules event "after create new account" action "page_redirect" , but it doesn't work. tried action "execute custom php - code" and write there line drupal_goto('http://'.$_SERVER['SERVER_NAME'].'/afterregister'); it redirects, but user not automaticaly logged in. next step is to hack fboauth module.

dmegatool’s picture

With Rules I was able to redirect users to a specified page. I used "User has logged in". But I don't know how to redirect to the page the user was...

If you ever hack the module, could you post how to do it. I looked around but I'm no programmer so I didn't find how to do it :/

b8x’s picture

in your case module "rules" can help . there is event "User has logged in" just choose action 'page redirect' and type your destination page. this rule will work for simple and fboauth login.

b8x’s picture

ok, problem was "legal" module. when FBauth works it ignore legal checkbox, and can't login user untill this flag = checked.

dmegatool’s picture

But I can't make it work as I don't know what was the page the user was on. I want to redirect to the page they were when they clicked the login button... Know how to do this ?

dmegatool’s picture

Found a solution here : http://drupal.org/node/1314940

Don't know if it works in your case. Here's the template.tlp.php code to add

/**
 * Return a link to initiate a Facebook Connect login or association.
 * Modified theme function to replace theme_fboauth_action__connect().
 *
 * @param $link
 *   An array of properties to be used to generate a login link. Note that all
 *   provided properties are required for the Facebook login to succeed and
 *   must not be changed. If $link is FALSE, Facebook OAuth is not yet
 *   configured.
 * @see fboauth_link_properties()
 */
function theme_fboauth_action__connect($variables) {
  $action = $variables['action'];
  $link = $variables['properties'];

  // modify to return to current path
  $currentDestination = drupal_get_destination();
  $link['query']['redirect_uri'] .= '?destination=' . drupal_encode_path($currentDestination['destination']);

  $url = url($link['href'], array('query' => $link['query']));
  $link['attributes']['class'] = isset($link['attributes']['class']) ? $link['attributes']['class'] : 'facebook-action-connect';
  $attributes = isset($link['attributes']) ? drupal_attributes($link['attributes']) : '';
  $title = isset($link['title']) ? check_plain($link['title']) : '';
  $src = ($GLOBALS['is_https'] ? 'https' : 'http') . '://www.facebook.com/images/fbconnect/login-buttons/connect_light_medium_short.gif';
  return '<a ' . $attributes . ' href="' . $url . '"><img src="' . $src . '" alt="' . $title . '" /></a>';
}
b8x’s picture

cool, will be second way to solve problem :), thank you. do you have a strange stuff at the end of URL after fboauth? like http://my.site.com/register#_=_

dmegatool’s picture

Yes I do. But it doesn't bother me. I've seen other thread about it but I won't fight or try to fix this :) Think people were saying it was something on the Facebook side.

b8x’s picture

good

Alexander Matveev’s picture

Nice thread. Thank you guys. Subscribing.
UP: ops.. there is "Following" button on Drupal.org, I forgot =D

markusa’s picture

This is a really great thread....

How about this twist....I have 2 different Profile2 types. I have created 2 different pages with the fboauth connect block on each....I'd like it to redirect to the edit page for the particular profile2 type depending on the page that the user connects from....I've can redirect to the user edit page with rules but how to set a condition based on the page that the fboauth connect button was pushed on?

hanamizuki’s picture

According to fboauth.api.php, it's supposed to work using "hook_fboauth_actions_alter", isn't it?

I tried this code:
($user->created == $user->login : means this is the first login)

<?php
function MODULE_NAME_fboauth_actions_alter(&$actions) {
  $actions['connect']['callback'] = '_MODULE_NAME_fboauth_action_connect';
}
function _MODULE_NAME_fboauth_action_connect() {
  global $user;
  if($user->uid && $user->created == $user->login){
    drupal_goto('user/me/edit');
  }
}
?>

Sadly it doesn't work, why?

And I found that this code works:

<?php
print fboauth_action_display('connect', 'user');
?>

But I'd like to set the destination to user edit page when first login,
but "global $user" in fboauth_action_display() doesn't have uid yet, so can't write if function here.

Is any one has any idea?

hanamizuki’s picture

Okay I figured it out. I think it's better to use fboauth api than changing it in theme.

Step 1, Print the FBCONNECT Button, anywhere you want

<?php
print fboauth_action_display();
?>

Step 2, Add this to your CUSTOM_MODULE

<?php
/**
* Implements hook_fboauth_actions_alter(): Customise redirect path
*
* @see hook_fboauth_actions_alter();
*/
function CUSTOM_MODULE_fboauth_actions_alter(&$actions) {
  $actions['connect']['callback'] = '_bh_user_fboauth_action_connect';
}

/**
* Callback for CUSTOM_MODULE_fboauth_actions_alter(): Customise redirect path
*
* @see hook_fboauth_actions_alter();
*/
function _CUSTOM_MODULE_fboauth_action_connect($app_id, $access_token) {

  // Call the default action first
  fboauth_action_connect($app_id, $access_token);

  global $user; //dpm($user);

  if($user->uid && $user->created == $user->login){
    drupal_goto("user/$user->uid/edit");
  }
  drupal_goto('<front>');
}
?>
quicksketch’s picture

Status: Active » Closed (duplicate)

Let's consolidate this issue with #1314940: Set Custom Landing Page URL for Login and Register, which is a feature request for the module.

b8x’s picture

this is typical fboauth link -- href="https://www.facebook.com/dialog/oauth?client_id=232874473477309&redirect..."
so, print it by yourself in with any class, page where this link placed must define destination after fbouauth, maybe you want give that throuh the url like, "/page_with_fb_button/?dest=node/67" in template of page_with_fb_button.tpl.php

$dest = $_GET['dest'];
print <a href="https://www.facebook.com/dialog/oauth?client_id=232874473477309&redirect_uri=http%3A//my.site.com/fboauth/connect%3Fdestination%3D<?=$dest?>&scope=email%2Cread_friendlists%2Cuser_about_me">click to link</a>

this is my way

skchan2’s picture

Thanks, #14 works, but not with the popup function from patch #40 in https://drupal.org/node/1364698

Any work arounds?

dunklea’s picture

I second this request. Ideally I would like to reload the current page after the popup closes, but so far I have not no solutions.

Thanks,
Andrew

SherpaHyde’s picture

Issue summary: View changes

This works for me in my template file where I want the Facebook button (Drupal 6).
It logs the site visitor in using Facebook then brings her back to the same page (now logged in).

<?php
// Set the redirect to the current page (unless we're on the login page).
$redirect = (arg(0) === 'user' && (arg(1) === 'login' || arg(1) == '')) ? NULL : $_GET['q'];
print  fboauth_action_display('connect', $redirect) ; 	
?>

(code from fboauth.module)

bovidiu’s picture

@dmegatool #7 theme function works just fine. The hook to theme_fboauth_action__connect($variables), it is correct and the snippet which does the correct redirect is:

// modify to return to current path
  $currentDestination = drupal_get_destination();
  $link['query']['redirect_uri'] .= '?destination=' . drupal_encode_path($currentDestination['destination']);