Answers.Body: <p>I've been using the CMS user extension <a href="https://civicrm.org/extensions/cms-users" rel="nofollow noreferrer">https://civicrm.org/extensions/cms-users</a> (with Drupal 9 / CiviRules) successfully.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-09T20:28:23.137Z
Answers.Text: Agree this is the approach we use for D9
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-09T18:59:22.297Z
Answers.LastActivityDate: 2023-04-09T18:59:22.297Z
Answers.UserDisplayName: kathc
Answers.Body: <p>You can register users through <a href="https://www.drupal.org/project/webform_registration" rel="nofollow noreferrer">Webform Registration</a> module. This module allows maximum flexibility to control the user registration process.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T21:57:53.060Z
Answers.Text: Hi Hassan, can you confirm that this results in the Drupal user being connected to the civi record? Also the modules says "Development version: 7.x-1.x-dev updated 10 Nov 2015" so seems to be largely unmaintained.
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-08T16:58:29.393Z
Answers.Text: Yes , i have tested the connectivity of drupal user with civicrm contact that gets created through that module. I understand your concern and i agree that this module is not well maintained and do not have any security release yet. I am afraid you would have to review the code base for any vulnerabilities.
Answers.UserDisplayName: Hassan Farooq
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T17:34:32.383Z
Answers.LastActivityDate: 2018-01-04T17:34:32.383Z
Answers.UserDisplayName: Hassan Farooq
Body: <p>I have a simple Drupal webform that is integrated with Civi and creates a tagged contact. I use the approach described by @petednz at <a href="https://civicrm.org/blog/petednz/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and" rel="nofollow noreferrer">https://civicrm.org/blog/petednz/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and</a> to create a Drupal user and log them in when the form is submitted. In my case this then gives them access to a larger form where I want them to be able to save a draft and return later, hence the need for the user account.</p>
  
  <p>Here's the rule that I'm using:</p>
  
  <pre><code>{ "rules_friends_tag_account_create" : {
  "LABEL" : "Self Create User Account and login",
  "PLUGIN" : "reaction rule",
  "OWNER" : "rules",
  "TAGS" : [ "CiviCRM", "CiviCRM User" ],
  "REQUIRES" : [ "civicrm", "rules" ],
  "ON" : { "civicrm_entity_tag_create" : [] },
  "IF" : [
    { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ] } },
    { "data_is" : {
        "data" : [ "civicrm-entity-tag:entity-table" ],
        "value" : "civicrm_contact"
      }
    },
    { "data_is" : { "data" : [ "civicrm-entity-tag:tag-id" ], "value" : "6" } }
  ],
  "DO" : [
    { "civicrm_entity_action_create_user" : {
        "USING" : {
          "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ],
          "is_active" : "1",
          "notify" : "1",
          "signin" : "1",
          "username_format" : "first last"
        },
        "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
      }
    },
    { "user_unblock" : { "account" : [ "civicrm-user" ] } },
    { "user_add_role" : { "account" : [ "civicrm-user" ], "roles" : { "value" : { "7" : "7" } } } }
  ]
  </code></pre>
  
  <p>}
  }</p>
  
  <p>This has been working reliably for some months, and seems rock solid when I test it.</p>
  
  <p>However I'm seeing behaviour from users that suggests that it isn't working all the time: i.e. sometimes I see that they have submitted the first form two or three times in quick succession, suggesting that they are not reaching the second form, but getting an access denied message instead, which is what would happen if the user account wasn't created for them.</p>
  
  <p>Also, in recent days, I've seen on two or three occasions now the following error message in the Drupal log:</p>
  
  <pre><code>Unable to get variable civicrm_user, it is not defined.
  </code></pre>
  
  <p>Why might this rule be working fine for much of the time, but not consistently? How can I debug this? Is there a more robust approach that I could take?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-13T23:58:03.020Z
Comments.Text: Have you changed versions of something since this was working well?
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-15T12:21:52.690Z
Comments.Text: ""username_format" : "first last"" looks like it is the culprit in some cases at least. Users being human are adding a space after their first name and then Drupal complains that it can't have multiple consecutive spaces in a username. Got round that one by changing to use email address as the username.
Comments.UserDisplayName: Graham
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-15T17:52:43.557Z
Comments.Text: oh right. on a webform could you have validated the field with webform_validation. worth adding yours, or this, as an answer?
Comments.UserDisplayName: petednz - fuzion
Tags: <drupal><drupal-rules>
Title: Problem creating Drupal users using Rules and Webform integration
ThreadText: # Problem creating Drupal users using Rules and Webform integration
  
  (Asked by: username_0 on 2017-03-13)
  
  I have a simple Drupal webform that is integrated with Civi and creates a tagged contact. I use the approach described by @petednz at https://civicrm.org/blog/petednz/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and to create a Drupal user and log them in when the form is submitted. In my case this then gives them access to a larger form where I want them to be able to save a draft and return later, hence the need for the user account.
  Here's the rule that I'm using:
  { "rules_friends_tag_account_create" : {
  "LABEL" : "Self Create User Account and login",
  "PLUGIN" : "reaction rule",
  "OWNER" : "rules",
  "TAGS" : [ "CiviCRM", "CiviCRM User" ],
  "REQUIRES" : [ "civicrm", "rules" ],
  "ON" : { "civicrm_entity_tag_create" : [] },
  "IF" : [
    { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ] } },
    { "data_is" : {
        "data" : [ "civicrm-entity-tag:entity-table" ],
        "value" : "civicrm_contact"
      }
    },
    { "data_is" : { "data" : [ "civicrm-entity-tag:tag-id" ], "value" : "6" } }
  ],
  "DO" : [
    { "civicrm_entity_action_create_user" : {
        "USING" : {
          "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ],
          "is_active" : "1",
          "notify" : "1",
          "signin" : "1",
          "username_format" : "first last"
        },
        "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
      }
    },
    { "user_unblock" : { "account" : [ "civicrm-user" ] } },
    { "user_add_role" : { "account" : [ "civicrm-user" ], "roles" : { "value" : { "7" : "7" } } } }
  ]
  
  }
  }
  This has been working reliably for some months, and seems rock solid when I test it.
  However I'm seeing behaviour from users that suggests that it isn't working all the time: i.e. sometimes I see that they have submitted the first form two or three times in quick succession, suggesting that they are not reaching the second form, but getting an access denied message instead, which is what would happen if the user account wasn't created for them.
  Also, in recent days, I've seen on two or three occasions now the following error message in the Drupal log:
  Unable to get variable civicrm_user, it is not defined.
  
  Why might this rule be working fine for much of the time, but not consistently? How can I debug this? Is there a more robust approach that I could take?
  
  **Tags:** drupal, drupal-rules
  
  > **Comments:**
  > **username_1**: Have you changed versions of something since this was working well?  
  > **username_0**: ""username_format" : "first last"" looks like it is the culprit in some cases at least. Users being human are adding a space after their first name and then Drupal complains that it can't have multiple consecutive spaces in a username. Got round that one by changing to use email address as the username.  
  > **username_1**: oh right. on a webform could you have validated the field with webform_validation. worth adding yours, or this, as an answer?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2023-04-09. Score: 1
  
  I've been using the CMS user extension <https://civicrm.org/extensions/cms-users> (with Drupal 9 / CiviRules) successfully.
  
  > **Comments:**
  > **username_1**: Agree this is the approach we use for D9  
  
  ---
  
  ### Answer by username_3 on 2018-01-04. Score: 0
  
  You can register users through [Webform Registration](https://www.drupal.org/project/webform_registration) module. This module allows maximum flexibility to control the user registration process.
  
  > **Comments:**
  > **username_1**: Hi Hassan, can you confirm that this results in the Drupal user being connected to the civi record? Also the modules says "Development version: 7.x-1.x-dev updated 10 Nov 2015" so seems to be largely unmaintained.  
  > **username_3**: Yes , i have tested the connectivity of drupal user with civicrm contact that gets created through that module. I understand your concern and i agree that this module is not well maintained and do not have any security release yet. I am afraid you would have to review the code base for any vulnerabilities.  
  
  ---
  
  