I want to assign a role to a user after the user confirms his/her email.
How do I do this?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityYou'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.
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
}
}