2

I want to assign a role to a user after the user confirms his/her email.

How do I do this?

  • Please mention your Drupal version (6 or 7 ?) – AyeshK Oct 23 '12 at 18:43
2

You'll want to take a look at Rules and LoginToboggan (as per this answer on Drupal Answers).

Rules will allow you to add a "trigger", such as adding a role to a user, and LoginToboggan will provide the "trigger" for when the account is validated.

| improve this answer | |
0

You can use hook_user_login(&$edit, $account) which is called from user_login_finalize().

When $edit parameter is empty is because is called from user_pass_reset() menu callback:

// user_login_finalize() also updates the login timestamp of the
// user, which invalidates further use of the one-time login link.
user_login_finalize();

This example should work:

function MYMODULE_user_login(&$edit, $account) {
  if (empty($edit)) {
    // @todo Add role to $account->roles array
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.