Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function updatePassword(UserInterface $user)
 {
     if (0 !== strlen($password = $user->getPlainPassword())) {
         $user->setPassword($this->userPasswordEncoder->encode($user));
         $user->eraseCredentials();
     }
 }
 /**
  * {@inheritDoc}
  */
 public function login(UserInterface $user, $firewallName = 'main')
 {
     if (!$user->isEnabled()) {
         return;
     }
     parent::login($user, $firewallName);
 }
    function it_should_connect_oauth_account_with_given_user(
        $userManager,
        $oauthRepository,
        UserInterface $user,
        UserResponseInterface $response,
        ResourceOwnerInterface $resourceOwner,
        UserOAuthInterface $oauth
    ) {
        $resourceOwner->getName()->willReturn('google');

        $response->getEmail()->willReturn(null);
        $response->getUsername()->willReturn('username');
        $response->getResourceOwner()->willReturn($resourceOwner);
        $response->getAccessToken()->willReturn('access_token');

        $oauthRepository->createNew()->willReturn($oauth);

        $oauth->setIdentifier('username');
        $oauth->setProvider('google');
        $oauth->setAccessToken('access_token');

        $user->addOAuthAccount($oauth)->shouldBeCalled();

        $userManager->persist($user)->shouldBeCalled();
        $userManager->flush()->shouldBeCalled();

        $this->connect($user, $response);
    }
 function it_does_nothing_if_plain_password_is_empty(UserPasswordEncoderInterface $userPasswordEncoder, UserInterface $user)
 {
     $user->getPlainPassword()->willReturn('');
     $userPasswordEncoder->encode($user)->willReturn('topSecretEncodedPassword');
     $user->setPassword(Argument::any())->shouldNotBeCalled();
     $user->eraseCredentials()->shouldNotBeCalled();
     $this->updatePassword($user);
 }
 function it_encodes_password(EncoderFactoryInterface $encoderFactory, PasswordEncoderInterface $passwordEncoder, UserInterface $user)
 {
     $user->getPlainPassword()->willReturn('topSecretPlainPassword');
     $user->getSalt()->willReturn('typicalSalt');
     $encoderFactory->getEncoder($user)->willReturn($passwordEncoder);
     $passwordEncoder->encodePassword('topSecretPlainPassword', 'typicalSalt')->willReturn('topSecretEncodedPassword');
     $this->encode($user)->shouldReturn('topSecretEncodedPassword');
 }
 /**
  * {@inheritDoc}
  */
 public function updatePassword(UserInterface $user)
 {
     if (0 !== strlen($password = $user->getPlainPassword())) {
         $encoder = $this->encoderFactory->getEncoder($user);
         $user->setPassword($encoder->encodePassword($password, $user->getSalt()));
         $user->eraseCredentials();
     }
 }
 function it_logs_user_in($securityContext, $userChecker, $eventDispatcher, UserInterface $user)
 {
     $user->getRoles()->willReturn(array('ROLE_TEST'));
     $userChecker->checkPreAuth($user)->shouldBeCalled();
     $securityContext->setToken(Argument::type('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken'))->shouldBeCalled();
     $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type('Sylius\\Bundle\\UserBundle\\Event\\UserEvent'))->shouldBeCalled();
     $this->login($user);
 }
 function it_logs_user_in(TokenStorageInterface $tokenStorage, UserCheckerInterface $userChecker, EventDispatcherInterface $eventDispatcher, UserInterface $user)
 {
     $user->getRoles()->willReturn(['ROLE_TEST']);
     $userChecker->checkPreAuth($user)->shouldBeCalled();
     $userChecker->checkPostAuth($user)->shouldBeCalled();
     $tokenStorage->setToken(Argument::type(UsernamePasswordToken::class))->shouldBeCalled();
     $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type(UserEvent::class))->shouldBeCalled();
     $this->login($user);
 }
Exemple #9
0
 function it_logs_user_in($securityContext, $userChecker, $eventDispatcher, UserInterface $user)
 {
     $user->getRoles()->willReturn(array('ROLE_TEST'));
     $userChecker->checkPreAuth($user)->shouldBeCalled();
     $userChecker->checkPostAuth($user)->shouldBeCalled();
     $securityContext->setToken(Argument::type(UsernamePasswordToken::class))->shouldBeCalled();
     $eventDispatcher->dispatch(UserEvents::SECURITY_IMPLICIT_LOGIN, Argument::type(UserEvent::class))->shouldBeCalled();
     $this->login($user);
 }
 public function it_does_nothing_if_plain_password_is_empty($encoderFactory, PasswordEncoderInterface $encoder, UserInterface $user)
 {
     $user->getPlainPassword()->willReturn('');
     $user->getSalt()->willReturn('typicalSalt');
     $encoderFactory->getEncoder($user)->shouldNotBeCalled();
     $encoder->encodePassword('', 'typicalSalt')->shouldNotBeCalled();
     $user->setPassword(Argument::any())->shouldNotBeCalled();
     $user->eraseCredentials()->shouldNotBeCalled();
     $this->updatePassword($user);
 }
Exemple #11
0
 /**
  * @param UserInterface $user
  */
 private function blame(UserInterface $user)
 {
     $cart = $this->getCart();
     if (null === $cart) {
         return;
     }
     $cart->setCustomer($user->getCustomer());
     $this->cartManager->persist($cart);
     $this->cartManager->flush();
 }
 function it_does_not_allow_to_delete_currently_logged_user(GenericEvent $event, UserInterface $userToBeDeleted, UserInterface $currentlyLoggedInUser, $tokenStorage, $flashBag, TokenInterface $token)
 {
     $event->getSubject()->willReturn($userToBeDeleted);
     $userToBeDeleted->getId()->willReturn(1);
     $tokenStorage->getToken()->willReturn($token);
     $currentlyLoggedInUser->getId()->willReturn(1);
     $token->getUser()->willReturn($currentlyLoggedInUser);
     $event->stopPropagation()->shouldBeCalled();
     $flashBag->add('error', 'Cannot remove currently logged in user.')->shouldBeCalled();
     $this->deleteUser($event);
 }
Exemple #13
0
 function it_does_not_log_user_in_if_user_was_not_found($userRepository, $session, UserInterface $user, Session $minkSession)
 {
     $userRoles = ['ROLE_USER'];
     $userRepository->findOneBy(array('username' => '*****@*****.**'))->willReturn(null);
     $user->getRoles()->willReturn($userRoles);
     $user->getPassword()->willReturn('xyz');
     $user->serialize()->willReturn('serialized_user');
     $session->set('_security_user', Argument::any())->shouldNotBeCalled();
     $session->save()->shouldNotBeCalled();
     $session->getName()->willReturn('MOCKEDSID');
     $session->getId()->willReturn('xyzc123');
     $minkSession->setCookie('MOCKEDSID', 'xyzc123')->shouldNotBeCalled();
     $this->shouldThrow(new \InvalidArgumentException(sprintf('There is no user with email sylius@example.com')))->during('logIn', array('*****@*****.**', 'default', $minkSession));
 }
 function it_does_not_update_username_when_customer_email_is_the_same(OnFlushEventArgs $onFlushEventArgs, EntityManager $entityManager, UnitOfWork $unitOfWork, CustomerInterface $customer, UserInterface $user, ClassMetadata $userMetadata)
 {
     $onFlushEventArgs->getEntityManager()->willReturn($entityManager);
     $entityManager->getUnitOfWork()->willReturn($unitOfWork);
     $unitOfWork->getScheduledEntityInsertions()->willReturn([]);
     $unitOfWork->getScheduledEntityUpdates()->willReturn([$customer]);
     $user->getUsername()->willReturn('*****@*****.**');
     $customer->getUser()->willReturn($user);
     $customer->getEmail()->willReturn('*****@*****.**');
     $user->setUsername('*****@*****.**')->shouldNotBeCalled();
     $entityManager->persist($user)->shouldNotBeCalled();
     $unitOfWork->recomputeSingleEntityChangeSet($userMetadata, $user)->shouldNotBeCalled();
     $this->onFlush($onFlushEventArgs);
 }
 /**
  * {@inheritdoc}
  */
 protected function executeRoleCommand(OutputInterface $output, UserInterface $user, array $securityRoles)
 {
     $error = false;
     foreach ($securityRoles as $securityRole) {
         if (!$user->hasRole($securityRole)) {
             $output->writeln(sprintf('<error>User "%s" didn\'t have "%s" Security role.</error>', (string) $user, $securityRole));
             $error = true;
             continue;
         }
         $user->removeRole($securityRole);
         $output->writeln(sprintf('Security role <comment>%s</comment> has been removed from user <comment>%s</comment>', $securityRole, (string) $user));
     }
     if (!$error) {
         $this->getEntityManager()->flush();
     }
 }
Exemple #16
0
 /**
  * @param UserInterface $user
  */
 private function prepareUserVerification(UserInterface $user)
 {
     $token = 'marryhadalittlelamb';
     $this->sharedStorage->set('verification_token', $token);
     $user->setEmailVerificationToken($token);
     $this->userManager->flush();
 }
Exemple #17
0
 /**
  * @Given /^(I) have already placed an order (\d+) times$/
  */
 public function iHaveAlreadyPlacedOrderNthTimes(UserInterface $user, $numberOfOrders)
 {
     $customer = $user->getCustomer();
     for ($i = 0; $i < $numberOfOrders; $i++) {
         $order = $this->createOrder($customer, '#00000' . $i);
         $order->setPaymentState(PaymentInterface::STATE_COMPLETED);
         $order->setCompletedAt(new \DateTime());
         $this->orderRepository->add($order);
     }
 }
Exemple #18
0
 /**
  * @param Request $request
  * @param RequestConfiguration $configuration
  * @param UserInterface $user
  * @param string $newPassword
  *
  * @return RedirectResponse
  */
 protected function handleChangePassword(Request $request, RequestConfiguration $configuration, UserInterface $user, $newPassword)
 {
     $user->setPlainPassword($newPassword);
     $dispatcher = $this->container->get('event_dispatcher');
     $dispatcher->dispatch(UserEvents::PRE_PASSWORD_CHANGE, new GenericEvent($user));
     $this->manager->flush();
     $this->addFlash('success', 'sylius.user.password.change.success');
     $dispatcher->dispatch(UserEvents::POST_PASSWORD_CHANGE, new GenericEvent($user));
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
     }
     $redirectRouteName = $request->attributes->get('_sylius[redirect]', 'sylius_account_profile_show', true);
     return new RedirectResponse($this->container->get('router')->generate($redirectRouteName));
 }
 /**
  * {@inheritdoc}
  *
  * @throws \LogicException when the algorithm is not supported
  */
 public function encode(UserInterface $user)
 {
     return $this->encodePassword($user->getPlainPassword(), $user->getSalt());
 }
Exemple #20
0
 /**
  * @param UserInterface $user
  */
 protected function assignCustomer(UserInterface $user = null)
 {
     if (null !== $user) {
         $user->setCustomer($this);
     }
 }
 function it_refreshes_user($userRepository, UserInterface $user, UserInterface $refreshedUser)
 {
     $userRepository->find(1)->willReturn($refreshedUser);
     $user->getId()->willReturn(1);
     $this->refreshUser($user)->shouldReturn($refreshedUser);
 }
Exemple #22
0
 /**
  * @param UserInterface $user
  * @param string        $newPassword
  *
  * @return RedirectResponse
  */
 protected function handleChangePassword(UserInterface $user, $newPassword)
 {
     $user->setPlainPassword($newPassword);
     $dispatcher = $this->get('event_dispatcher');
     $dispatcher->dispatch(UserEvents::PRE_PASSWORD_CHANGE, new GenericEvent($user));
     $this->domainManager->update($user, 'sylius.user.password.change.success');
     $dispatcher->dispatch(UserEvents::POST_PASSWORD_CHANGE, new GenericEvent($user));
     if ($this->config->isApiRequest()) {
         return $this->handleView($this->view($user, 204));
     }
     return new RedirectResponse($this->generateUrl('sylius_account_profile_show'));
 }
Exemple #23
0
 /**
  * @param UserInterface $user
  * @param string        $firewallName
  *
  * @return UsernamePasswordToken
  */
 protected function createToken(UserInterface $user, $firewallName)
 {
     return new UsernamePasswordToken($user, null, $firewallName, $user->getRoles());
 }
Exemple #24
0
 /**
  * @param Request $request
  * @param RequestConfiguration $configuration
  * @param UserInterface $user
  * @param string $newPassword
  *
  * @return Response
  */
 protected function handleChangePassword(Request $request, RequestConfiguration $configuration, UserInterface $user, $newPassword)
 {
     $user->setPlainPassword($newPassword);
     $dispatcher = $this->container->get('event_dispatcher');
     $dispatcher->dispatch(UserEvents::PRE_PASSWORD_CHANGE, new GenericEvent($user));
     $this->manager->flush();
     $this->addFlash('success', 'sylius.user.change_password');
     $dispatcher->dispatch(UserEvents::POST_PASSWORD_CHANGE, new GenericEvent($user));
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
     }
     $redirectRouteName = $this->getSyliusAttribute($request, 'redirect', null);
     Assert::notNull($redirectRouteName, 'Redirect is not configured.');
     return new RedirectResponse($this->container->get('router')->generate($redirectRouteName));
 }
 /**
  * {@inheritdoc}
  */
 public function logIn(UserInterface $user)
 {
     $token = new UsernamePasswordToken($user, $user->getPassword(), 'randomstringbutnotnull', $user->getRoles());
     $this->setToken($token);
 }
 /**
  * @param UserInterface $user
  * @param string $password
  */
 protected function changePassword(UserInterface $user, $password)
 {
     $user->setPlainPassword($password);
     $this->getContainer()->get('sylius.user.password_updater')->updatePassword($user);
 }
 /**
  * @param UserInterface $user
  * @param string        $newPassword
  *
  * @return RedirectResponse
  */
 protected function handleChangePassword(UserInterface $user, $newPassword)
 {
     $user->setPlainPassword($newPassword);
     $this->domainManager->update($user);
     $dispatcher = $this->get('event_dispatcher');
     $dispatcher->dispatch(UserEvents::PASSWORD_RESET_SUCCESS, new GenericEvent($user));
     if ($this->config->isApiRequest()) {
         return $this->handleView($this->view($user, 204));
     }
     $this->addFlash('success', 'sylius.user.password.change.success');
     return new RedirectResponse($this->generateUrl('sylius_account_homepage'));
 }
 /**
  * Check if a wishlist is publicly available, or the
  * user has special privileges to access it.
  *
  * @param $user
  * @param $wishlist
  * @return bool
  */
 protected function userCanAccessWishlist(UserInterface $user = null, WishlistInterface $wishlist)
 {
     if ($wishlist->isPublic()) {
         return true;
     }
     if ($user) {
         if ($user->hasRole('ROLE_ADMINISTRATION_ACCESS') || $user->getCustomer() && $user->getCustomer()->getId() == $wishlist->getCustomer()->getId()) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param UserInterface $user
  */
 public function updateUserPassword(UserInterface $user)
 {
     if (null !== $user->getPlainPassword()) {
         $this->passwordUpdater->updatePassword($user);
     }
 }
Exemple #30
0
 /**
  * @param UserInterface $user
  * @param string        $newPassword
  *
  * @return RedirectResponse
  */
 protected function handleChangePassword(RequestConfiguration $configuration, UserInterface $user, $newPassword)
 {
     $user->setPlainPassword($newPassword);
     $dispatcher = $this->container->get('event_dispatcher');
     $dispatcher->dispatch(UserEvents::PRE_PASSWORD_CHANGE, new GenericEvent($user));
     $this->manager->flush();
     $this->addFlash('success', 'sylius.user.password.change.success');
     $dispatcher->dispatch(UserEvents::POST_PASSWORD_CHANGE, new GenericEvent($user));
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle(View::create($user, 204));
     }
     return new RedirectResponse($this->container->get('router')->generate('sylius_account_profile_show'));
 }