Hi Nathan,

I've got a problem which I don't know how to solve. I've connected my site to Facebook primarly to alow users to comment without the need of going through the registration process.

Now, I'd like to have Facebook users active (non-blocked) the moment they pass the Facebook auth and are redirected back/registered to a Drupal site. Currently they all got the "blocked" status.

Yes, I could go to admin/config/people/accounts and set "Who can register accounts?" to "Visitors". But that way, the users could log in via Drupal and become active without the admin approval, which I don't like.

I take Facebook as the authority for authenticating users, so I don't need to approve them if they logged in from FB.

What I would like to see is some kind of switch for skipping the admin approval when authenticated via FB.

Thanks in advance

PS. -> GREAT module! :)

Comments

magtak’s picture

same issue here.

magtak’s picture

Wrong. After reading #1 and configuring users to register by themselves without admin interference it all works great, 1 click and the user is logged in. Thanks for the awesome module.

kevcol’s picture

I'd love the same feature danko requested. This would keep out the non-facebook spammers.

aaronschachter’s picture

could you not write a custom menu_alter hook to unset the 'user/register' page to keep out spammers?

function yomama_menu_alter(&$items) {
$items['user/register']['access callback'] = FALSE;
}

I could see this being an option in the module settings actually, where if you check "Facebook registration only" it calls this hook.

sime’s picture

I intend to provide a snippet for this that modifies the user after successful response from Facebook, I just need to work out which user hook to use.

If quicksketch wants this in as a feature I will provide a patch.

sime’s picture

As a feature, I would suggest:
-- a setting in fboauth settings page "Automatically confirm user accounts connected with Facebook"
-- an appropriate hook/code (i haven't done this in D7 so would need to look)

okday’s picture

hi,

i need this feature too.

quicksketch’s picture

I believe we could implement this request with just a single option on the Facebook OAuth settings page. I don't think there's a need for an additional hook or code (though I would suggest theming the user login form). Since the concept of "registration" effectively disappears when using Facebook Connect, it makes sense that you would disable user registration entirely (via the normal Drupal configuration at admin/config/people/accounts).

I think the new options could be named something like this (a checkbox with additional description):

[ ] Allow Login with Facebook users to skip administrator account approval
This setting allows any user who is presented with the Facebook Connect button to bypass all administrator approval requirements for new accounts. This setting may be useful if you wish to disable normal registration and have users register exclusively through Facebook.

In addition, we should probably put a note on the admin/config/people/accounts form letting administrators know if their settings are going to be bypassed by Facebook OAuth.

quicksketch’s picture

Title: Making Facebook users active immediately » Making Facebook users active immediately (bypass administrator approval or admin-only account creation)
semei’s picture

This would be a great feature. Any news on this? In my opinion, completely disabling the usual registration but allowing Facebook registration would be best.

mtoscano’s picture

Issue summary: View changes

Two years later and this feature has not been implemented, even if I see it as quite important.
Am I wrong or being able to register users just with Facebook (disabling core registration) can be a common scenario?
It should also help reducing spamming users, isn't it?

mtoscano’s picture

Version: 7.x-1.5 » 7.x-1.7
AlexKirienko’s picture

Hello, mato.

Right now we working on v2 release, which will be ready on next week. After v2 release I will check this issue closely.

mxt’s picture

Hi all, I'm interest in this also.

Thank you for considering this.

2pha’s picture

This is pretty easy to do in your own module with HOOK_fboauth_actions.
Here is the full code of a module I created which basically copies the fboauth action but removes the checking for registration permissions, allowing anyone to sign in with facebook without having to create a password and they are signed in straight away.
This leaves the default registration alone, so you could have the people who sign up with the normal form, still have to confirm their email. Or in my case, not allow people to register the normal way, only with facebook.
The module name is "dfj_fbc", so remember to rename these parts of the code.
To add the connect button anywhere, you would use fboauth_action_display('dfj_fbc', '/'.request_path())

/**
 * Implements hook_fboauth_actions().
 */
function dfj_fbc_fboauth_actions() {
  $actions['dfj_fbc'] = array(
    'title' => t('Connect'),
    'callback' => 'dfj_fbc_connect',
    'theme' => 'fboauth_action__connect',
    'permissions' => array(
      'email',
    ),
  );
  return $actions;
}

function dfj_fbc_connect($app_id, $access_token) {
  global $user;
  
  // Save access_token in session for future use.
  $_SESSION['fboauth']['access_token'] = $access_token;
  
  $fbuser = fboauth_graph_query('me', $access_token);
  // Use fake email if user email not available.
  if (empty($fbuser->email)) {
    $fbuser->email = $fbuser->id . '@facebook.com';
  };
  
  $uid = fboauth_uid_load($fbuser->id);
  // If the user isn't logged in.
  if (!$user->uid) {
    // See if they are connected to FB & is an association between FB & Drupal.
    if ($uid && ($account = user_load($uid))) {
      fboauth_login_user($account);
    }
    // No association between FB & this Drupal site, yet.
    // So lets check & see if the FB address matches a Drupal email address.
    else {
      if (!empty($fbuser->email)) {
        $account = NULL;
  
        // Check and see if multiple_email module is in use.
        if (module_exists('multiple_email')) {
          if ($multiple_email_object = multiple_email_find_address($fbuser->email)) {
            $account = user_load($multiple_email_object->uid);
            if ($multiple_email_object->confirmed) {
              // we're good
            }
            else {
            // note:  drupal security team doesn't consider it a vulnerabilty that UID is publicly available
              // https://www.drupal.org/node/1004778
              drupal_set_message(t("We found your e-mail @email in the @sitename system, but it hasn't been confirmed. " .
                  'Please <a href="!login">login manually</a> and then <a href="!edit">' .
                      'resend your confirmation code</a> to confirm that you are the owner of this email address. This is required before you can connect to the site from Facebook with it.',
                          array(
                          '@email'    => $fbuser->email,
                          '@sitename' => variable_get('site_name', ''),
                          '!login'    => url('user/login'),
                          '!edit'     => url('user/' . $account->uid . '/edit/email-addresses'))));
              return;
            }
          }
          else {
            // Email address not found in System
          }
        }
        else {
          // Just use the e-mail from the users table.
          $account = user_load_by_mail($fbuser->email);
        }
        // If the Facebook e-mail address matches an existing account, bind them
        // together and log in as that account.
        if ($account) {
          // Connect the account only if we allow anonymous users to connect accounts that have
          // never been connected before.
          if (variable_get('fboauth_anon_connect', TRUE)) {
            // Logins will be denied if the user's account is blocked.
            if (fboauth_login_user($account)) {
              fboauth_save($account->uid, $fbuser->id);
              drupal_set_message(t("You've connected your account with Facebook."));
            }
          }
          else {
            drupal_set_message(t('We found your e-mail @email in the @sitename system, but the account has never been connected to Facebook before. ' .
                'Please <a href="!login">login manually</a> and <a href="!edit">connect to Facebook</a> while logged in. ' .
                'Once you have completed this step, you may login through Facebook whenever you like.',
                array(
                '@email'    => $fbuser->email,
                '@sitename' => variable_get('site_name', ''),
                '!login'    => url('user/login'),
                '!edit'     => url('user/' . $account->uid . '/edit'))));
          }
        }
        // Register a new user only if allowed.
        //elseif (variable_get('user_register', 1)) {
        else {
          $account = fboauth_create_user($fbuser, array('status' => 1, 'pass' => dfj_random_password()));
  
          if ( !isset($account) || empty($account) ) {
            drupal_set_message(t('Unable to create a new account using your Facebook profile.'), 'warning');
            return;
          }
  
          // 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.
          //dpm($account);
          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', ''))));
          }
          // Log in the user if no approval is required.
          elseif (fboauth_login_user($account)) {
            drupal_set_message(t('Welcome to @sitename',
                array(
                '@sitename' => variable_get('site_name', '')
                )));
          }
          // If the login fails, fboauth_login_user() throws an error message.
        }
        // Since user's can't create new accounts on their own, show an error.
        /*
        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.'));
        }
        */
      }
      // Email not provided by Facebook.
      else {
        drupal_set_message(t("Facebook didn't provide an e-mail address " .
            "to be associated with your account, so we can't log you in."));
        return;
      }
      // Done if no e-mail address provided by facebook.
    }
  }
  else {
    // The user is already logged in to Drupal.
    // So just associate the two accounts.
    fboauth_save($user->uid, $fbuser->id);
    drupal_set_message(t("You've connected your account with Facebook."));
  }
}

function dfj_fbc_fboauth_user_presave(&$edit, $fbuser) {
  // Save the user's first name into a field provided by Profile module.
  //if (isset($fbuser->first_name)) {
    //$edit['profile_first_name'] = $fbuser->first_name;
  //}
  $edit['pass'] = dfj_random_password();
}

function dfj_random_password() {
  $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  $pass = array(); //remember to declare $pass as an array
  $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  for ($i = 0; $i < 15; $i++) {
    $n = rand(0, $alphaLength);
    $pass[] = $alphabet[$n];
  }
  return implode($pass); //turn the array into a string
}
mxt’s picture

@AlexKirienko, could you please consider to integrate 2pha solution in #15 in the official release as an new option?

Thank you very much.

AlexKirienko’s picture

@MXT
Hi. Sorry, I was to busy on DrupalCon. There are lot of issues need to be fixed in this module. Module need new stable version ASAP. I will check this issue on next week.

AlexKirienko’s picture

Status: Active » Needs review