/**
* Syncronizes the data of the given user with the FOSRestBundle
*
* @throws \Exception If the password was not set
*
* @param $user
*/
public function syncData(User $user)
{
if ($user->getProvider()->getType() !== self::BUILTIN_PROVIDER) {
return;
}
$FOSUser = $this->userManager->findUserByUsername($user->getUsername());
if ($FOSUser === null) {
if ($user->getNewPassword() == "") {
throw new \Exception("Password must be set");
}
$FOSUser = $this->userManipulator->create($user->getUsername(), $user->getNewPassword(), "", true, false);
$user->setLegacy(false);
}
if ($user->getNewPassword() != "") {
$this->userManipulator->changePassword($user->getUsername(), $user->getNewPassword());
}
$FOSUser->setEmail($user->getEmail());
$FOSUser->setEnabled($user->isActive());
}