function fbconnect_login_login_page in Facebook Connect 8.2
Same name and namespace in other branches
- 7.2 fbconnect_login/fbconnect_login.pages.inc \fbconnect_login_login_page()
Menu callback. Logs user into site or redirects.
File
- fbconnect_login/
fbconnect_login.pages.inc, line 43 - User pages callbacks for the fbconnect module.
Code
function fbconnect_login_login_page($form, $form_state = array()) {
$data = fbconnect_get_user_info(array(
'name',
'email',
));
// User not logged into Facebook we dont have any information for them, let them log in.
if (empty($data)) {
return facebook_login_page($form, $form_state);
}
// Check if user has already registered with their Facebook account.
$user_id = _is_fbconnect_user($data['id']);
if ($user_id) {
// User already registered Facebook account to site, log them in
$form_state['uid'] = $user_id;
user_login_submit($form, $form_state);
drupal_set_message(t('You have been successfully logged in.'));
if (!empty($_GET['destination'])) {
drupal_goto($_GET['destination']);
}
else {
drupal_goto('<front>');
}
}
elseif (_email_already_exist($data['email'])) {
// The user was not found in the fbconnect_users table, but the emial from Facebook might already have an account on coracle.
// Redirect user to the login page with a message.
drupal_set_message(t('This email address is already registered to an account. Please log in to this account with the username and password provided during registration'));
$options = array(
'query' => array(
'fbconnect' => 'true',
),
);
drupal_goto('user/login', $options);
}
else {
drupal_set_message(t('You do not have an account with this site. Create an account on this site with through Facebook <a href="!here">here</a>'), array(
'!here' => url('fbconnect/authorize'),
));
}
}