Many people are looking for a feature to let people create content before registering on the site. One of the places where it is described in detail is http://data.agaric.com/agaric-wants-registration-flow-let-people-registe...

After a few unsuccessful attempts to get the "lazy registration" pattern working with separate modules, I was able to design a workflow with a couple of rule sets. It has its limitations, but it works. You will need a good understaning of Rules in Drupal 7.

Generally speaking:

  1. In your entity (article, any node, whatever a visitor should be creating) add a field for an email. You can add it to the end of your entity form and hide it from authenticated users via permissions. This way the anonymous user will be required to type in only his email to create an account.
  2. Create a Rules Component of type Rules. Add a variable of type node called new_node, it will make the component take the newly created node as an argument.
  3. Create a rule in your component. I named it "Create new user".
    -On the conditions tab check that the user (new_node:author) is not an authenticated user
    -As a second condition check that your entity has an email field
    - As an action, create a new entity of type "User". For the name an email address choose the email token that you get from the node.
    This action will create a new user for you. If you have email verification in the registration settings, this will also send an email to the provided email.
  4. Now we need a Rules Set Component component that will connect the node to the user. I called it "Assign content to new user". As an input variable select "User". I called it new_user.
    - Create a rule in the component, called "Fetch User Email". It will only have an action "add a variable", and the variable should be new_user:mail. We're getting that email address for the next rule
    - Create another rule in the component called "Get list of nodes and assign author". It will have two actions. First to fetch all entities where email field is equal to new_user:mail. Second is a loop that loops over the fetched entities and fires action "set data value", and we are setting is the author of the entity to new_user.
  5. Create a normal rule that fires on "content is saved". For the first action put the "Create new user" component, and choose the node as input variable. Then add another action and select the component, and choose "Assign content to new user" component, feed the new_user variable as input.
  6. Give it a try! Log out and try creating a new node. If everything you did is correct, then the rule should create a new user and assign the node to it

Now, I omitted one important thing: you will also need to check if the email that a visitor enters already belongs to some user, and decide what to do in that situation (if you don't create a rule for that, your visitor will get an SQL constraint violation when he tries to save)
There are also a few deficiencies that you may want to address somehow:
- In the method I described above, the user will not be able to choose a username. You might want to add a field for that.
- I don't know how the user can get their password if your site doesn't use email verification. Maybe you want to add another field in your node for the password, but I haven't tried it.
- If some evil visitor decides to put someone else's email in the entity, the email owner might be assigned authorship of nodes that he has no idea about.

Hope this is helpful to someone. If you have discovered a better way, do write a comment.

Comments

dasjo’s picture

great, thanks for writing this up!

you could export the named functionality as a feature so people can go and reuse at and add this as a tutorial at http://drupal.org/node/878700

mitchell’s picture

Status: Active » Fixed

+1 for packaging this into a feature and creating a sandbox project...
That would be a great way to continue working on this and improving the idea.

Until then, I'd like to mark this issue as fixed until something actionable comes along.

xcono’s picture

In my case, i use hook_node_validate. Something like this:

function MY_MODULE_node_validate($node, $form, &$form_state)
{
  global $user;
  if($node->type == 'MY_CONTENT_TYPE' && ($user->uid == 0))
    {
      if ((bool)db_query('SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:name)', array(':name' => $form_state['values']['MY_CUSTOM_FIELD']['und'][0]['value']))->fetchField())
        {
          form_set_error('MY_CUSTOM_FIELD', t('E-mail address already exists. ') . l('Forgot your password?', 'user/password'));
        }
    }
}

You can also handle the error and appoint a different name. Such as adding numbers.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gomino’s picture

The module conversion does this too

marcoBauli’s picture

Does anybody know if there was any more progress on this: Feature, Rulesets, modules or other? Thanks a lot

ThePickwickProject’s picture

@zualas

I followed your tutorial and everything went fine until point 5: could you please explain this part in a bit more detail?

Create a normal rule that fires on "content is saved". For the first action put the "Create new user" component, and choose the node as input variable.

This works fine, but I did not fully understand why the node is assigned in the "create new user" part.

Then add another action and select the component, and choose "Assign content to new user" component, feed the new_user variable as input.

Here I was completely lost: could you please rephrase it? It's not so clear which component to select. Whatever I tried, I got the message that new_user is not available.