We have two types of memeberships on our site that is invite-only. Is there a way to auto assign a role with the invite? Perhaps a different invite code? or a checkbox with the role selection before the invite?

Any ideas?

Thanks,
Andrey.

Comments

mr.andrey’s picture

Found a way...

Auto Assign Role module gives the option to assign from a path, so if I can assign /user/register/role1 to auto assign role1 for user when they register.

Now there's just the invite module bit.

invite_accept() looks like this:

function invite_accept($invite) {
  global $user;  

  if (!$user->uid && invite_validate($invite)) {
    $_SESSION[INVITE_SESSION] = $invite->reg_code;
    drupal_goto('user/register');
  }

  drupal_goto();
}

So if I can make it go to a different path based on a variable parameter, we'll be in business.

The easiest way to enter a bit of variable data is through the custom invite message. It's stored in the 'data' field of the 'invite' table and is accessible in invite_accept through $invite->data['message'].

So let's say that "-" will mean role1 and "--" role2. This will look fairly inconspicuous added to the bottom of the invite email.

in invite.module, invite_accept(), replace:

    drupal_goto('user/register');

with:

    if ($invite->data['message'] == '-') {
      drupal_goto('user/register/role1');
    } elseif ($invite->data['message'] == '--') {
      drupal_goto('user/register/role2');
    }

That should do the trick. A bit jerry-rigged, but since it's essential for our invite-only setup to have different roles assigned at registration, it will have to do.

Best,
Andrey.

robin van emden’s picture

I cobbled together a quick solution along these lines as well. But it seems to me the "path to registration page" ought to be role-specific. For now I send the role id(s) along with the invite as extra vars & redirect according to this information. If I find the time, I might create a patch to enable this the right way (ie including admin setting etc).

avpaderno’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

I am closing this issue, since it's for a Drupal version no longer supported.