updateCanonicalFields() public method

Updates the canonical username and email fields for a user
public updateCanonicalFields ( FOS\UserBundle\Model\UserInterface $user ) : void
$user FOS\UserBundle\Model\UserInterface
return void
 public function postBind(DataEvent $event)
 {
     $user = $event->getForm()->getData();
     if ($user instanceof UserInterface) {
         $this->userManager->updateCanonicalFields($user);
     }
 }
示例#2
0
 /**
  * This must be called on prePersist and preUpdate if the event is about a
  * user.
  *
  * @param UserInterface $user
  */
 protected function updateUserFields(UserInterface $user)
 {
     if (null === $this->userManager) {
         $this->userManager = $this->container->get('fos_user.user_manager');
     }
     $this->userManager->updateCanonicalFields($user);
     $this->userManager->updatePassword($user);
 }
示例#3
0
 private function handleEvent(LifecycleEventArgs $args)
 {
     if (null === $this->userManager) {
         $this->userManager = $this->container->get('fos_user.user_manager');
     }
     $entity = $args->getEntity();
     if ($entity instanceof UserInterface) {
         $this->userManager->updateCanonicalFields($entity);
         $this->userManager->updatePassword($entity);
     }
 }
示例#4
0
 private function handleEvent(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     if ($entity instanceof UserInterface) {
         if (null === $this->userManager) {
             $this->userManager = $this->container->get('fos_user.user_manager');
         }
         $this->userManager->updateCanonicalFields($entity);
         $this->userManager->updatePassword($entity);
         if ($args instanceof PreUpdateEventArgs) {
             // We are doing a update, so we must force Doctrine to update the
             // changeset in case we changed something above
             $dm = $args->getDocumentManager();
             $uow = $dm->getUnitOfWork();
             $meta = $dm->getClassMetadata(get_class($entity));
             $uow->recomputeSingleDocumentChangeSet($meta, $entity);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userInfo = $this->getUserInfo($response);
     $service = $response->getResourceOwner()->getName();
     $user = $this->userManager->findUserBy(array("{$service}Id" => $userInfo['id']));
     if ($user instanceof PersonInterface) {
         $user = parent::loadUserByOAuthUserResponse($response);
         $serviceName = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
         $user->{$setter}($response->getAccessToken());
         return $user;
     }
     $userInfo = $this->checkEmail($service, $userInfo);
     $user = $this->userManager->createUser();
     $this->setUserInfo($user, $userInfo, $service);
     if ($userInfo['first_name']) {
         $user->setFirstName($userInfo['first_name']);
     }
     if ($userInfo['family_name']) {
         $user->setSurname($userInfo['family_name']);
     }
     if ($service === 'facebook') {
         $this->setFacebookData($user, $response->getResponse());
     }
     $username = Uuid::uuid4()->toString();
     if (!UsernameValidator::isUsernameValid($username)) {
         $username = UsernameValidator::getValidUsername();
     }
     $availableUsername = $this->userManager->getNextAvailableUsername($username, 10, Uuid::uuid4()->toString());
     $user->setUsername($availableUsername);
     $user->setEmail($userInfo['email']);
     $user->setPassword('');
     $user->setEnabled(true);
     $this->userManager->updateCanonicalFields($user);
     /** @var ValidatorInterface $validator */
     $validator = $this->container->get('validator');
     /** @var ConstraintViolationList $errors */
     $errors = $validator->validate($user, ['LoginCidadaoProfile']);
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             if ($error->getPropertyPath() === 'email' && method_exists($error, 'getConstraint') && $error->getConstraint() instanceof UniqueEntity) {
                 throw new DuplicateEmailException($service);
             }
         }
     }
     $form = $this->formFactory->createForm();
     $form->setData($user);
     $request = $this->container->get('request');
     $eventResponse = new RedirectResponse('/');
     $event = new FormEvent($form, $request);
     $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
     $this->userManager->updateUser($user);
     $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $eventResponse));
     return $user;
 }
 /**
  * This must be called on prePersist and preUpdate if the event is about a
  * user.
  *
  * @param UserInterface $user
  */
 protected function updateUserFields(UserInterface $user)
 {
     if (null === $this->userDiscriminator) {
         $this->userDiscriminator = $this->container->get('rollerworks_multi_user.user_discriminator');
     }
     // Can only use the user manager when there is an user-system active
     if (null === $this->userDiscriminator->getCurrentUser() || true !== $this->userDiscriminator->getCurrentUserConfig()->getConfig('use_listener', true)) {
         return;
     }
     if (null === $this->userManager) {
         $this->userManager = $this->container->get('fos_user.user_manager');
     }
     $this->userManager->updateCanonicalFields($user);
     $this->userManager->updatePassword($user);
 }
示例#7
0
 public function updateCanonicalFields(UserInterface $user)
 {
     $this->FOSUserManager->updateCanonicalFields($user);
 }