I have a situation where I want to assign a default password when a user is registered in the CP, but only if they are assigned to a specific user group. Plugin code looks like this:
craft()->on('users.onActivateUser', function(Event $event)
{
$user = $event->params['user'];
// Test to see if a user is in group
if ($user->isInGroup('groupName'))
{
$user->newPassword = 'Password123';
craft()->users->saveUser($user);
}
});
I've tried latching on to both the users.onSaveUser and users.onActivateUser events, and in both situations, there are no groups are assigned to the user. Is there an event that is at the absolute end of user registration that I can watch to access their user groups?
var_dump($user->getGroups());
andvar_dump($user->getErrors());
both return empty arrays.die('here');
inside theif $user->isInGroup()
check for a user you know belongs to that group, does it stop?