/**
  * @param User  $user
  * @param array $options
  * @throws InvalidArgumentException
  */
 protected function updateUser(User $user, $options)
 {
     if (!empty($options['user-role'])) {
         $role = $this->getEntityManager()->getRepository('OroUserBundle:Role')->findOneBy(array('role' => $options['user-role']));
         if (!$role) {
             throw new InvalidArgumentException('Invalid Role');
         }
         $user->addRole($role);
     }
     if (!empty($options['user-business-unit'])) {
         $businessUnit = $this->getEntityManager()->getRepository('OroOrganizationBundle:BusinessUnit')->findOneBy(array('name' => $options['user-business-unit']));
         if (!$businessUnit) {
             throw new InvalidArgumentException('Invalid Business Unit');
         }
         $user->setOwner($businessUnit)->addBusinessUnit($businessUnit);
     }
     if (!empty($options['user-name'])) {
         $user->setUsername($options['user-name']);
     }
     if (!empty($options['user-password'])) {
         $user->setPlainPassword($options['user-password']);
     }
     $properties = ['email', 'firstname', 'lastname'];
     foreach ($properties as $property) {
         if (!empty($options['user-' . $property])) {
             $user->{'set' . str_replace('-', '', $property)}($options['user-' . $property]);
         }
     }
     $this->getUserManager()->updateUser($user);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var UserManager $userManager */
     $userManager = $this->container->get('oro_user.manager');
     $role = $manager->getRepository('OroUserBundle:Role')->findOneByRole('ROLE_ADMINISTRATOR');
     $group = $manager->getRepository('OroUserBundle:Group')->findOneByName('Administrators');
     $unit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneByName('Main');
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $user = new User();
     $user->setUsername('owner_User');
     $user->addGroup($group);
     $user->addRole($role);
     $user->addBusinessUnit($unit);
     $user->setFirstname('Test Owner  FirstName');
     $user->setLastname('Test Owner LastName');
     $user->setEmail('*****@*****.**');
     $user->setOwner($unit);
     $user->addGroup($group);
     $user->setPlainPassword('test password');
     $user->setSalt(md5(mt_rand(1, 222)));
     $user->setOrganization($organization);
     $userManager->updateUser($user);
     $this->setReference('owner_user', $user);
     $manager->flush();
 }
 /**
  * @param User  $user
  * @param array $options
  * @throws InvalidArgumentException
  */
 protected function updateUser(User $user, $options)
 {
     if (!empty($options['user-name'])) {
         $user->setUsername($options['user-name']);
     }
     if (!empty($options['user-password'])) {
         $user->setPlainPassword($options['user-password']);
     }
     $this->setRole($user, $options)->setBusinessUnit($user, $options)->setOrganizations($user, $options)->setProperties($user, $options);
     $this->getUserManager()->updateUser($user);
 }
 /**
  * Process form
  *
  * @param  User $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(User $entity)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $entity->setPlainPassword($this->form->get('password')->getData());
             $entity->setPasswordChangedAt(new \DateTime());
             try {
                 $this->mailerProcessor->sendChangePasswordEmail($entity);
             } catch (\Exception $e) {
                 $this->form->addError(new FormError($this->translator->trans('oro.email.handler.unable_to_send_email')));
                 $this->logger->error('Email sending failed.', ['exception' => $e]);
                 return false;
             }
             $this->userManager->updateUser($entity);
             return true;
         }
     }
     return false;
 }
Exemple #5
0
 /**
  * {@inheritDoc}
  */
 protected function onSuccess(User $user)
 {
     $user->setPlainPassword($this->form->getData()->getPlainPassword())->setConfirmationToken(null)->setPasswordRequestedAt(null)->setEnabled(true);
     $this->manager->updateUser($user);
 }
 public function testPassword()
 {
     $user = new User();
     $pass = '******';
     $user->setPassword($pass);
     $user->setPlainPassword($pass);
     $this->assertEquals($pass, $user->getPassword());
     $this->assertEquals($pass, $user->getPlainPassword());
     $user->eraseCredentials();
     $this->assertNull($user->getPlainPassword());
 }