public function load(ObjectManager $manager) { $admin = new User(); $admin->setUsername('admin')->setPassword('admin')->setEmail('*****@*****.**')->addRole(User::ROLE_SUPER_ADMIN); $normalUser = new User(); $normalUser->setUsername('user')->setPassword('user')->setEmail('*****@*****.**')->addRole(User::ROLE_USER); $manager->persist($admin); $manager->persist($normalUser); $manager->flush(); }
/** * @param User $user * @return JsonResponse * * @Route("/secured/users/{slug}/projects.json", name="user_projects") * @Route("/users/{slug}/projects.json", name="public_user_projects") * @Method({"GET"}) */ public function getProjectsAction(User $user) { $visibilityPolicy = [2]; if ($this->getUser() instanceof User) { $visibilityPolicy[] = 1; if ($this->getUser() === $user) { $visibilityPolicy[] = 0; } } $projects = $this->getDoctrine()->getRepository('Project:Project')->findBy(['user' => $user->getId(), 'visibility' => $visibilityPolicy]); if (empty($projects)) { return $this->errorResponse('No project found', 404); } return $projects; }
function it_should_encode_password_when_attribute_changed(EncoderFactoryInterface $encoderFactory, User $user, PasswordEncoderInterface $encoder, LifecycleEventArgs $args, UnitOfWork $unitOfWork, EntityManager $entityManager, \Doctrine\ORM\Mapping\ClassMetadata $meta) { $args->getEntityManager()->willReturn($entityManager); $entityManager->getUnitOfWork()->willReturn($unitOfWork); $entityManager->getClassMetadata(Argument::any())->willReturn($meta); $unitOfWork->computeChangeSet(Argument::cetera())->willReturn(); $user->getPassword()->willReturn('pass'); $user->getSalt()->willReturn('salt'); $args->getEntity()->willReturn($user); $encoderFactory->getEncoder($user)->willReturn($encoder); $encoder->encodePassword(Argument::any(), Argument::any())->willReturn('encoded_pass'); $unitOfWork->getEntityChangeSet($user)->willReturn(['password' => 'password']); $user->setPassword('encoded_pass')->shouldBeCalled(); $this->postPersist($args); }
/** * @param string $saltKey */ public static function setSaltKey(string $saltKey) { User::$saltKey = $saltKey; }