/**
  * Create account user form
  *
  * @Route("/register", name="orob2b_customer_frontend_account_user_register")
  * @Template("OroB2BCustomerBundle:AccountUser/Frontend:register.html.twig")
  *
  * @return array|RedirectResponse
  */
 public function registerAction()
 {
     if ($this->getUser()) {
         return $this->redirect($this->generateUrl('orob2b_customer_frontend_account_user_profile'));
     }
     $isRegistrationAllowed = $this->get('oro_config.manager')->get('oro_b2b_customer.registration_allowed');
     if (!$isRegistrationAllowed) {
         throw new AccessDeniedException();
     }
     $accountUser = new AccountUser();
     /** @var WebsiteManager $websiteManager */
     $websiteManager = $this->get('orob2b_website.manager');
     $website = $websiteManager->getCurrentWebsite();
     $websiteOrganization = $website->getOrganization();
     if (!$websiteOrganization) {
         throw new \RuntimeException('Website organization is empty');
     }
     $defaultRole = $this->getDoctrine()->getManagerForClass('OroB2BCustomerBundle:AccountUserRole')->getRepository('OroB2BCustomerBundle:AccountUserRole')->getDefaultAccountUserRoleByWebsite($website);
     if (!$defaultRole) {
         throw new \RuntimeException(sprintf('Role "%s" was not found', AccountUser::ROLE_DEFAULT));
     }
     $accountUser->addOrganization($websiteOrganization)->setOrganization($websiteOrganization)->addRole($defaultRole);
     $userManager = $this->get('orob2b_account_user.manager');
     $form = $this->createForm(FrontendAccountUserRegistrationType::NAME, $accountUser);
     $handler = new FrontendAccountUserHandler($form, $this->getRequest(), $userManager);
     if ($userManager->isConfirmationRequired()) {
         $registrationMessage = 'orob2b.customer.controller.accountuser.registered_with_confirmation.message';
     } else {
         $registrationMessage = 'orob2b.customer.controller.accountuser.registered.message';
     }
     return $this->get('oro_form.model.update_handler')->handleUpdate($accountUser, $form, ['route' => 'orob2b_customer_account_user_security_login'], ['route' => 'orob2b_customer_account_user_security_login'], $this->get('translator')->trans($registrationMessage), $handler);
 }
Пример #2
0
 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 if ($this->form->get('passwordGenerate')->getData()) {
                     $generatedPassword = $this->userManager->generatePassword(10);
                     $accountUser->setPlainPassword($generatedPassword);
                 }
                 if ($this->form->get('sendEmail')->getData()) {
                     $this->userManager->sendWelcomeEmail($accountUser);
                 }
             }
             $token = $this->securityContext->getToken();
             if ($token instanceof OrganizationContextTokenInterface) {
                 $organization = $token->getOrganizationContext();
                 $accountUser->setOrganization($organization)->addOrganization($organization);
             }
             $this->userManager->updateUser($accountUser);
             return true;
         }
     }
     return false;
 }
 /**
  * @return array
  */
 public function submitProvider()
 {
     $entity = new AccountUser();
     $expectedEntity = new AccountUser();
     $expectedEntity->setSalt($entity->getSalt());
     return ['reset password' => ['defaultData' => $entity, 'submittedData' => ['plainPassword' => 'new password'], 'expectedData' => $expectedEntity]];
 }
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     foreach ($this->users as $user) {
         $entity = new AccountUser();
         $entity->setFirstName($user['first_name'])->setLastName($user['last_name'])->setEmail($user['email'])->setEnabled($user['enabled'])->setPassword($user['password']);
         $this->setReference($entity->getEmail(), $entity);
         $manager->persist($entity);
     }
     $manager->flush();
 }
 /**
  * @return array
  */
 public function submitProvider()
 {
     $entity = new AccountUser();
     $expectedEntity = new AccountUser();
     $expectedEntity->setFirstName('John');
     $expectedEntity->setLastName('Doe');
     $expectedEntity->setEmail('*****@*****.**');
     $entity->setSalt($expectedEntity->getSalt());
     return ['new user' => ['defaultData' => $entity, 'submittedData' => ['firstName' => 'John', 'lastName' => 'Doe', 'email' => '*****@*****.**', 'plainPassword' => '123456'], 'expectedData' => $expectedEntity]];
 }
 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 $this->userManager->register($accountUser);
             }
             $this->userManager->updateUser($accountUser);
             $this->userManager->reloadUser($accountUser);
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  * @dataProvider supportedMethods
  */
 public function testProcessSupportedRequest($method, $isValid, $isProcessed)
 {
     $organization = null;
     if ($isValid) {
         $organization = new Organization();
         $organization->setName('test');
         $organizationToken = $this->getMock('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\OrganizationContextTokenInterface');
         $organizationToken->expects($this->any())->method('getOrganizationContext')->willReturn($organization);
         $this->securityContext->expects($this->any())->method('getToken')->willReturn($organizationToken);
         $this->form->expects($this->at(2))->method('get')->with('passwordGenerate')->will($this->returnValue($this->passwordGenerateForm));
         $this->form->expects($this->at(3))->method('get')->with('sendEmail')->will($this->returnValue($this->sendEmailForm));
         $this->passwordGenerateForm->expects($this->once())->method('getData')->will($this->returnValue(false));
         $this->sendEmailForm->expects($this->once())->method('getData')->will($this->returnValue(false));
     }
     $this->form->expects($this->any())->method('isValid')->will($this->returnValue($isValid));
     $this->request->setMethod($method);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->assertEquals($isProcessed, $this->handler->process($this->entity));
     if ($organization) {
         $this->assertEquals($organization, $this->entity->getOrganization());
         $this->assertTrue($this->entity->hasOrganization($organization));
     }
 }
Пример #8
0
 public function testSendResetPasswordEmail()
 {
     $this->assertSendCalled(Processor::RESET_PASSWORD_EMAIL_TEMPLATE_NAME, ['entity' => $this->user], $this->buildMessage($this->user->getEmail()));
     $this->mailProcessor->sendResetPasswordEmail($this->user);
 }
Пример #9
0
 /**
  * Get the truncated email displayed when requesting the resetting.
  * The default implementation only keeps the part following @ in the address.
  *
  * @param AccountUser $user
  *
  * @return string
  */
 protected function getObfuscatedEmail(AccountUser $user)
 {
     $email = $user->getEmail();
     if (false !== ($pos = strpos($email, '@'))) {
         $email = '...' . substr($email, $pos);
     }
     return $email;
 }
 /**
  * @param AccountUser $accountUser
  * @param boolean $enabled
  * @param string $successMessage
  * @return JsonResponse
  */
 protected function enableTrigger(AccountUser $accountUser, $enabled, $successMessage)
 {
     $userManager = $this->get('orob2b_account_user.manager');
     $accountUser->setEnabled($enabled);
     $userManager->updateUser($accountUser);
     return new JsonResponse(['successful' => true, 'message' => $successMessage]);
 }
Пример #11
0
 /**
  * @param AccountUser $user
  */
 public function sendConfirmationEmail(AccountUser $user)
 {
     $user->setConfirmed(false)->setConfirmationToken($user->generateToken());
     $this->getEmailProcessor()->sendConfirmationEmail($user);
 }
 public function testRegisterConfirmationNotRequired()
 {
     $password = '******';
     $user = new AccountUser();
     $user->setConfirmed(false);
     $user->setPlainPassword($password);
     $this->configManager->expects($this->exactly(2))->method('get')->willReturnMap([['oro_b2b_customer.confirmation_required', false, false, false], ['oro_b2b_customer.send_password_in_welcome_email', false, false, true]]);
     $this->emailProcessor->expects($this->once())->method('sendWelcomeNotification')->with($user, $password);
     $this->userManager->register($user);
     $this->assertTrue($user->isConfirmed());
 }