Setting User's Groups - Integrity Constraint Error
UserGroupsService->assignUserToGroups takes a user's ID as the first parameter and you're passing in the entire UserModel.

Change it to this and it should work:

craft()-&gt;userGroups-&gt;assignUserToGroups($user-&gt;id, $groupIds);