Register with Facebook Drupal 7

edited February 2016 in Questions
Hello I'm testing the OneAll Drupal 7 module https://www.drupal.org/project/social_login to allow users to register and login using Facebook.
When the user clicks on the facebook icon to register they first have to sign into facebook, and then are auto-redirected to the Drupal register page. When they arrive some fields pre-populated (username and email), but others are empty, specifically "First Name" "Last Name" and "Password".

image


Ideally I want at least the "First Name" "Last Name" fields pre-populated from the user's Facebook account data, and in a perfect world the password too. I'm assuming the password field won't be possible for security reasons (obviously Facebook isn't going to share user passwords) but won't that confuse my users when they return to login in the future? Not sure why the password field is even presented given the user is selecting to use their facebook account and has signed into their fb account to get to this page in the first place?

Any help greatly appreciated :)

Sincerely,

Andrew

Best Answer

  • Fred_PinelFred_PinelMember
    Answer ✓
    Hi,
    Yes, it is custom code changes, not something that is configurable now.
    We can provide this code change as a modification to your installation, or release a new version (or both). Usually, we start with some custom code changes (and validation from the sites, you :-), and if that works well, integrate later.
    In your case, we could send small changes to try out.

    Regards.

Answers

  • Hi Andrew,

    This redirection to the Drupal register page is normally specified in the module's setting (Automatically create a new user account when a user registers with Social Login?).
    It can be changed to automatically create the account (skipping this step), if you want.

    The password listed is for your site only (we do not have access to the user's Facebook password, as you mention), because the user may log in, either with the social network's or your site's credentials. Sometimes you want that. This is only for registration, later social logins will not ask for this password.

    Yes, not all fields are pre-populated (for no special reason other than the default Drupal 7 register form does not show them :-). This is something we could add. But, that depends on what your decide for your registration process.

    Regards.
  • Thank you. Regarding your comment that pre-populated fields are "something we could add" could you further explain? Are you referring to custom functionality added for my oneall account/application specifically by oneall, or it's possible to configure within the module as is? Thanks!
  • Thank you. Would there be a cost for this? or would it be required that we are on a paid plan in order to be eligible for this? Our website is a startup, but obviously if we get above 2500 users we'll be well placed and more than happy to start paying for the module and a larger subscription (as would be the requirement for use anyway). Thanks again!
  • There is no cost, but the other currency is time :-)
    We'll send you some possible changes to try out (by email), and post back here if/when it works.

    Regards
  • Fred_PinelFred_PinelMember
    edited October 2018
    Hi,
    For reference, here is some code changes to preopulate First Name, Last Name to the register form.

    In file: (your drupal base directory)/modules/social_login/social_login_core.module
    At approx. line: 880, after these lines:
    // Prepopulate.
    $form['account']['name']['#default_value'] = $user_login;
    $form['account']['mail']['#default_value'] = $user_email;
    Add this code:
    // User fields (depends on name defined in the administration setup!):
    $user_firstname = empty($identity['name']['givenName']) ? '' : $identity['name']['givenName'];
    $user_lastname = empty($identity['name']['familyName']) ? '' : $identity['name']['familyName'];
    $form['field_first_name'][LANGUAGE_NONE][0]['value']['#default_value'] = $user_firstname;
    $form['field_last_name'][LANGUAGE_NONE][0]['value']['#default_value'] = $user_lastname;
    Warning: this assumes you called the first and last names: First Name, Last Name,
    when adding the custom fields via the User Fields pages.
  • The above worked great, and you can customise the field_first_name and field_last_name to whatever the machine names read on the second column at
    admin/config/people/accounts/fields
    in drupal 7
  • Hi,
    Thanks for pointing this out.
Sign In or Register to comment.