Felix
Felix

Reputation: 5619

Typo3 FE User assign to FEUserGroup

I'm creating a FEUser programmatically (works fine) in the second Step I want to assign this FE User to an existing FEUsergroup.

I Thought it works fine but it didn't. In database the entry is set and the counter goes up.

But If i check the usergroup in List-View there are no users inside :(

My code looks like this:

$usergroup = $this->FrontendUserGroupRepository->findByUid($this->request->getArgument(self::USRGROUP));

$newFEUser = new \Typo3\CMS\Extbase\Domain\Model\FrontendUser();
$newFEUser->setUsername($this->userfunctions->genuserNAME($newPruefling->getVorname(), $newPruefling->getNachname()));
$randomPW = $this->passfunctions->genpassword();
$saltedPW = $this->passfunctions->hashPassword($randomPW);
$newFEUser->setPassword($saltedPW);
$newFEUser->setNAME($randomPW);
$newFEUser->setFirstNAME($newPruefling->getVorname());
$newFEUser->setLastNAME($newPruefling->getNachname());
$newFEUser->setEmail($this->request->getArgument(self::EMAIL));

// Wenn Usergroup vorhanden dann wird diese gesetzt.
$newFEUser->addUsergroup($usergroup);

$this->FrontendUserRepository->add($newFEUser);

Whats going wrong? Have I forgotten something?

Upvotes: 1

Views: 836

Answers (2)

Jay Böttcher
Jay Böttcher

Reputation: 534

If you have your users in a sysfolder you have to give your users the pid of your sysfolder. Otherwise you will not see any users in your List View.

Upvotes: 1

pgampe
pgampe

Reputation: 4578

Do not use new object but use the ObjectManager of TYPO3. Otherwise this will not work.

$newFEUser = $this->objectManger->get(\Typo3\CMS\Extbase\Domain\Model\FrontendUser::class);

Upvotes: 0

Related Questions