Aller directement à la fin des métadonnées
Aller au début des métadonnées

Creating a Drupal User for CiviCRM Contacts

Note!

Import User Module method tested on CiviCRM 1.2 / CivicSpace 0.8.2 & CiviCRM 4.2.2/Drupal 6. Drush method, below, is tested on CiviCRM 4.2.0.

Concept

In CiviCRM, there is an administration function that allows the synchronisation of Drupal Users with CiviCRM contacts. However, the reverse function - to sychronise CiviCRM contacts with Drupal Users - is not a default service.

To register a new account, a Drupal User is required to enter only three pieces of information: a) an arbitrary username, b) a password and c) a valid email.

If a Drupal User registers before her details have been entered into CiviCRM, a new CiviCRM contact profile is created and matched with the Drupal User profile. If a Drupal User registers after her details have been entered in CiviCRM, the information in her CiviCRM contact is automatically associated with her Drupal User Profile. This is done through the primary email address.

An administrator can take information from CiviCRM and use it to create users in bulk.

Why would I want to do this?

  • To enable all your CiviCRM contacts to be able to maintain their own details
  • To give all your CiviCRM contacts access to Drupal's services, such as lists, forums and collaborative working environments.

What do I need to do this?

By using Rules

  • The Drupal Rules and CiviCRM entity modules
  • A rule which triggers when a contact is updated or created.

Overview

Create a rule with the following elements:


EVENT

  • CiviCRM Contact has been updated
  • CiviCRM Contact has been created

CONDITION

  • NOT Drupal User Account exists for Contact

ACTION

  • Create Linked Drupal User Account

Or import the following:

{ "rules_drupal_gebruiker_van_civicrm_contact" : {
"LABEL" : "Drupal-gebruiker van CiviCRM-contact",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "civicrm" ],
"ON" : { "civicrm_contact_edit" : [], "civicrm_contact_create" : [] },
"IF" : [
{ "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm_contact" ] } }
],
"DO" : [
{ "civicrm_entity_action_create_user" : {
"USING" : {
"civicrm_contact" : [ "civicrm-contact" ],
"is_active" : "1",
"notify" : "0",
"signin" : "0"
},
"PROVIDE" : { "civicrm_user" : { "username" : "Created Drupal User" } }
}
}
]
}
}

By using User Import

  • You will need administration level access rights to Drupal, and not just CiviCRM.
  • The Drupal User Import Module (http://drupal.org/node/31940) must be installed and enabled on your CiviCRM for Drupal or you can import users also using the more simple http://drupal.org/project/node_importthat from 12 december can imort also uses generating password and can apply the email on the username too. 
    • It is likely there will not be a Drupal 7 version of Node import  as the Feeds module provides similar functionality (or even better, e.g. updating content) and has more active developers.

How do I go about it?

Warning

Please do a test run with some dummy data! To quickly create test data, use a Gmail account in the following way: yourusername+test_X@gmail.com (x being ascending numbers for each test contact)

  1. Import your contacts into CiviCRM. Let's assume you have an email address, and first and last names in each CiviCRM contact. You can find more about importing contacts here.
  2. Set up a CiviCRM profile that enables authenticated Drupal Users to edit at least the first and second names of their CiviCRM profile by using the "My Account" window. You can find more about setting up a profile here.
  3. Go into CiviCRM and select the contacts for whom you wish to create a Drupal User.
  4. In the "more actions" pull-down box, select "Export Contacts". A new dialogue will appear: select "Export PRIMARY Contact Fields", and hit "Continue". You will be prompted to save a Comma Separated Values (CSV) file labelled "CiviCRM_Contact_Search.csv". Do so.
  5. Head to the User Import Module: administer » Settings » users import.
  6. Upload the CSV you just exported from CiviCRM.
  7. The User Import is relatively intuitive, and has helpful explanatory notes throughout. Make sure you check the "Ignore First Line" box. You also have the option to send an email to the new Drupal User informing them of their registration details. Remember that you can customise the registration message (administer -> users -> configure: "Body of welcome e-mail")
  8. The dialogue will then ask you to associate one field with "email" and another with "password" . Select the field you wish to associate with the new Drupal User's email. Don't bother associating a field with password, since one will be generated randomly. You can create a username by associating particular fields with the Username pulldown box. Remember that Drupal Users can change username, email and password once their account is created. This means if User Import creates a rather incomprehensible username, the Drupal User isn't stuck with it.
  9. Once done, click the "import" button at the bottom of the screen.
  10. To test whether the import has been successful, log in as one of the test Drupal Users and modify one of the CiviCRM contact fields (which you have made accessible through a CiviCRM profile) in the My Account screen.
  11. Finally, navigate to that contact record via CiviCRM and verify that the user update has been performed.

Using drush

Another approach is to use the Drupal shell tool drush (http://drupal.org/project/drush).  Installing drush is beyond the scope of this article.  You must have at least drush version 4.

The syntax for creating a user using drush is:

drush user-create <username> --mail="<email>"

Substitute <username> and <email> with the appropriate username and e-mail.

  1. Import your contacts into CiviCRM. Let's assume you have an email address, and first and last names in each CiviCRM contact. You can find more about importing contacts here.
  2. Go into CiviCRM, click search, find contacts, and select the contacts for whom you wish to create a Drupal User.
  3. In the "more actions" pull-down box, select "Export Contacts" click go. A new dialogue will appear: select "Export PRIMARY Contact Fields", and hit "Continue". You will be prompted to save a Comma Separated Values (CSV) file labelled "CiviCRM_Contact_Search.csv". Do so.
  4. Open the CSV file in a spreadsheet program, such as LibreOffice Calc, Google Docs Spreadsheets, or Microsoft Excel.
  5. Remove all the columns except the e-mail address and username fields.
  6. Create a formula in the third column that concatenates the username and e-mail fields into a command that matches the syntax above.
    1. For LibreOffice, if your username is in Column A and e-mail in column B, this might look like: ="drush user-create " & A1 & " --mail=""" & B1 & """"
    2. If you wish the newly created users to be blocked until activated in Drupal, use:
      ="drush user-create " & A1 &" --mail=""" & B1 & """" & " && drush user-block --name=" & A1
    3. Note that you can use the e-mail address as the username if you like.  You can also concatenate multiple fields (e.g. First Name + Last Name) to make a username.
    4. Note that the multiple quotation marks in a row are necessary so that LibreOffice interprets your quotation mark literally.
  7. Copy the formula down to the other rows.
  8. Copy the entire column with your commands, and paste it into an SSH terminal window on your Drupal/CiviCRM server.
    1. If you have a very large list, it's more reliable to create a shell script.  Open a new text file, put #!/bin/sh as the first line, then paste your drush commands into the text file.  You can save and upload this file to the server and execute it as you would any shell script.
  9. You can also set a password with drush (see http://drush.ws/help/5#user-create ), but it's usually preferable to send a welcome message with a one-time login link instead. 
  10. A popular way to do this is to create the users as blocked users (see above Step 6b) and then modify the "User Activated" message in Drupal to be your welcome message. 
    You do this by going to http://yourdomain.org/admin/config/people/accounts,
    Go to "Account Activation", check the box "Notify user when account is activated". Then edit the e-mail to have the welcome message of your choice.
    "Account activation" is the e-mail that gets sent when you unblock users
    Then, unblock the users, either through the UI (50 users at a time), or using: drush user-unblock
  11. To test whether the import has been successful, log in as one of the test Drupal Users and modify one of the CiviCRM contact fields (which you have made accessible through a CiviCRM profile) in the My Account screen.
  12. Finally, navigate to that contact record via CiviCRM and verify that the user update has been performed.



Link to Email Discussion about this topic

http://lists.caltha.pl/pipermail/crm-dev/2006-January/002425.html

="/home/palante/drush/drush ucrt " &E54 &" --mail=""" & E54 & """" & " && drush user-block --name=" & E54
Étiquette
  • Aucun
  1. Feb 22, 2018

    Peter Davis dit :

    Just tested the drupal 7 version of user_import - works well - not sure why i lost my ability to edit this page