/**
  * If a User already exists with the same email or phone number but
  * that it was never enabled, we delete that previous user (this case
  * may happen if the user stop the registration process before sending
  * the validation code and then change phone etc.).
  * However to not confuse user, we keep the same confirmation token.
  *
  * @param User $user User to check the existence of
  *
  * @return string|null
  */
 public function deleteIfNonEnabledExists(User $user)
 {
     $email = $user->getEmail();
     $inDatabaseUser = null;
     if (!is_null($email)) {
         $inDatabaseUser = $this->findUserByUsernameOrEmail($email);
     }
     $phoneNumber = $user->getPhoneNumber();
     if (is_null($inDatabaseUser) && !is_null($phoneNumber)) {
         $phoneNumber = $this->normalizePhone($phoneNumber);
         $inDatabaseUser = $this->repository->findOneByPhoneNumber($phoneNumber);
     }
     $token = null;
     if (!is_null($inDatabaseUser) && !$inDatabaseUser->isEnabled()) {
         $token = $inDatabaseUser->getConfirmationToken();
         $this->deleteUser($inDatabaseUser);
     }
     return $token;
 }
 public function load(ObjectManager $objectManager)
 {
     $u1 = new User();
     $u1->setUsername('allan');
     $u1->setEmail('*****@*****.**');
     $u1->setPlainPassword('plop');
     $u1->setRoles(array('ROLE_USER'));
     $u1->setConfirmationToken('123456');
     $u1->setEnabled(false);
     $u1->setLocked(true);
     $this->addReference('new-user', $u1);
     $u2 = new User();
     $u2->setUsername('Raphael');
     $u2->setEmail('*****@*****.**');
     $u2->setPlainPassword('plop');
     $u2->setRoles(array('ROLE_USER'));
     $u2->setPhoneNumber('123456789');
     $u2->setConfirmationToken('');
     $u2->setEnabled(true);
     $u2->setLocked(false);
     $this->addReference('user-without-confirmation-token', $u2);
     $u3 = new User();
     $u3->setUsername('Bobthesponge');
     $u3->setEmail('*****@*****.**');
     $u3->setPlainPassword('plop');
     $u3->setRoles(array('ROLE_USER'));
     $u3->setConfirmationToken('123456');
     $u3->setEnabled(true);
     $u3->setLocked(false);
     $this->addReference('user-with-confirmation-token', $u3);
     $u4 = new User();
     $u4->setUsername('admin');
     $u4->setEmail('*****@*****.**');
     $u4->setPlainPassword('admin');
     $u4->setRoles(['ROLE_ADMINPANEL']);
     $u4->setConfirmationToken('123456');
     $u4->setEnabled(true);
     $u4->setLocked(false);
     $this->addReference('admin', $u4);
     $objectManager->persist($u1);
     $objectManager->persist($u2);
     $objectManager->persist($u3);
     $objectManager->persist($u4);
     $objectManager->flush();
 }
 /**
  */
 private function updateUserPassword(User $user, $newPassword)
 {
     $user->setPlainPassword($newPassword);
     $manager = $this->get('fos_user.user_manager');
     $manager->updateUser($user);
 }
 /**
  * @param User    $user
  * @param Request $request
  *
  * @Annotations\put("/users/{id}/password")
  *
  * @return Response
  */
 public function putUsersPasswordAction(User $user, Request $request)
 {
     $this->throwIfClientNot('backend');
     if (!$this->isCurrentUserAdmin()) {
         return $this->handleView(new View(['message' => 'bst.admin.only'], Response::HTTP_FORBIDDEN));
     }
     $requestData = $this->requestIsJsonWithKeysOrThrow($request, ['new_password']);
     $user->setPlainPassword($requestData['new_password']);
     $this->get('fos_user.user_manager')->updateUser($user);
     return $this->handleView(new View(null, Response::HTTP_NO_CONTENT));
 }