function fboauth_action_connect in Facebook OAuth (FBOAuth) 6
Same name and namespace in other branches
- 7.2 includes/fboauth.fboauth.inc \fboauth_action_connect()
- 7 includes/fboauth.fboauth.inc \fboauth_action_connect()
Facebook OAuth callback for initiating a Facebook connection.
1 string reference to 'fboauth_action_connect'
- fboauth_fboauth_actions in ./
fboauth.module - Implements hook_fboauth_actions().
File
- includes/
fboauth.fboauth.inc, line 71 - Provides functions used during Facebook login processes.
Code
function fboauth_action_connect($app_id, $access_token) {
global $user;
$fbuser = fboauth_graph_query('me', $access_token);
$uid = fboauth_uid_load($fbuser->id);
// If the user has logged in before, load their account and login.
if (!$user->uid && $uid && ($account = user_load($uid))) {
fboauth_login_user($account);
}
elseif (!empty($fbuser->email) && ($account = user_load(array(
'mail' => $fbuser->email,
)))) {
fboauth_save($account->uid, $fbuser->id);
// Logins will be denied if the user's account is blocked.
if ($user->uid || fboauth_login_user($account)) {
drupal_set_message(t('You\'ve connected your account with Facebook.'));
}
}
else {
// If the user is already logged in, associate the two accounts.
if ($user->uid) {
fboauth_save($user->uid, $fbuser->id);
drupal_set_message(t('You\'ve connected your account with Facebook.'));
}
elseif (variable_get('user_register', 1)) {
$account = fboauth_create_user($fbuser);
// Load the account fresh just to have a fully-loaded object.
$account = user_load($account->uid);
// If the account requires administrator approval the new account will
// have a status of '0' and not be activated yet.
if ($account->status == 0) {
_user_mail_notify('register_pending_approval', $account);
drupal_set_message(t('An account has been created for you on @sitename but an administrator needs to approve your account. In the meantime, a welcome message with further instructions has been sent to your e-mail address.', array(
'@sitename' => variable_get('site_name', ''),
)));
}
elseif (fboauth_login_user($account)) {
drupal_set_message(t('Welcome to @sitename. Basic information has been imported from Facebook into your account. You may want to <a href="!edit">edit your account</a> to confirm the details and set a password.', array(
'@sitename' => variable_get('site_name', ''),
'!edit' => url('user/' . $account->uid . '/edit'),
)));
}
// If the login fails, fboauth_login_user() throws its own error message.
}
else {
drupal_set_message(t('Your Facebook e-mail address does not match any existing accounts. If you have an account, you must first log in before you can connect your account to Facebook. Creation of new accounts on this site is disabled.'));
}
}
}