/** * Register new Diamante User and grant API access for it. * Sends confirmation email. While registration is not confirmed API access is not active * @param Command\RegisterCommand $command * @return void */ public function register(Command\RegisterCommand $command) { $diamanteUser = $this->diamanteUserFactory->create($command->email, $command->firstName, $command->lastName); $apiUser = $this->apiUserFactory->create($command->email, $command->password); if ($this->diamanteUserRepository->findUserByEmail($command->email)) { throw new \RuntimeException('An account with this email address already exists'); } $diamanteUser->setApiUser($apiUser); $this->diamanteUserRepository->store($diamanteUser); $this->registrationMailer->sendConfirmationEmail($diamanteUser->getEmail(), $apiUser->getHash()); }
public function testRegister() { $apiUser = $this->createApiUser(); $diamanteUser = $this->createDiamanteUser(); $this->diamanteUserFactory->expects($this->once())->method('create')->with($diamanteUser->getEmail(), $diamanteUser->getFirstName(), $diamanteUser->getLastName())->will($this->returnValue($diamanteUser)); $this->apiUserFactory->expects($this->once())->method('create')->with($apiUser->getEmail(), $apiUser->getPassword())->will($this->returnValue($apiUser)); $this->diamanteUserRepository->expects($this->once())->method('store')->with($diamanteUser); $this->registrationMailer->expects($this->once())->method('sendConfirmationEmail')->with($diamanteUser->getEmail(), $apiUser->getHash()); $command = new RegisterCommand(); $command->email = $diamanteUser->getEmail(); $command->password = $apiUser->getPassword(); $command->firstName = $diamanteUser->getFirstName(); $command->lastName = $diamanteUser->getLastName(); $this->service->register($command); }
/** * @param Message $message * @param Ticket $ticket */ private function processWatchers(Message $message, $ticket) { if (!$ticket) { return; } /** @var Message\MessageRecipient $recipient */ foreach ($message->getRecipients() as $recipient) { $email = $recipient->getEmail(); if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) { continue; } $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email); $oroUser = $this->oroUserManager->findUserByEmail($email); if ($oroUser) { $user = new User($oroUser->getId(), User::TYPE_ORO); } elseif ($diamanteUser) { $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE); } else { $diamanteUser = $this->diamanteUserFactory->create($email, $recipient->getFirstName(), $recipient->getLastName()); $this->diamanteUserRepository->store($diamanteUser); $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE); } $this->watchersService->addWatcher($ticket, $user); } }
public function testProcessWhenDiamanteUserNotExists() { $dummyFrom = $this->getDummyFrom(); $message = new Message(self::DUMMY_UNIQUE_ID, self::DUMMY_MESSAGE_ID, self::DUMMY_SUBJECT, self::DUMMY_CONTENT, $dummyFrom, self::DUMMY_MESSAGE_TO); $assigneeId = 1; $this->diamanteUserRepository->expects($this->once())->method('findUserByEmail')->with($this->equalTo(self::DUMMY_MESSAGE_FROM))->will($this->returnValue(null)); $diamanteUser = new DiamanteUser('test_email', $dummyFrom->getFirstName(), $dummyFrom->getLastName()); $this->diamanteUserFactory->expects($this->once())->method('create')->with($this->equalTo(self::DUMMY_MESSAGE_FROM))->will($this->returnValue($diamanteUser)); $this->diamanteUserRepository->expects($this->once())->method('store')->with($this->equalTo($diamanteUser)); $reporter = new User($diamanteUser->getId(), User::TYPE_DIAMANTE); preg_match('/@(.*)/', self::DUMMY_MESSAGE_FROM, $output); $customerDomain = $output[1]; $this->branchEmailConfigurationService->expects($this->once())->method('getConfigurationBySupportAddressAndCustomerDomain')->with($this->equalTo(self::DUMMY_MESSAGE_TO), $this->equalTo($customerDomain))->will($this->returnValue(null)); $this->emailProcessingSettings->expects($this->once())->method('getDefaultBranchId')->will($this->returnValue(self::DEFAULT_BRANCH_ID)); $this->messageReferenceService->expects($this->once())->method('createTicket')->with($this->equalTo($message->getMessageId()), self::DEFAULT_BRANCH_ID, $message->getSubject(), $message->getContent(), $reporter, $assigneeId); $this->branchEmailConfigurationService->expects($this->once())->method('getBranchDefaultAssignee')->with($this->equalTo(1))->will($this->returnValue(1)); $this->ticketStrategy->process($message); }
/** * @param \Diamante\UserBundle\Api\Command\CreateDiamanteUserCommand $command * * @return int */ public function createDiamanteUser(CreateDiamanteUserCommand $command) { $user = $this->diamanteUserRepository->findUserByEmail($command->email); if (!is_null($user)) { if (true === $user->isDeleted()) { $this->restoreUser($user); return $user->getId(); } else { throw new DiamanteUserExistsException('An account with this email address already exists'); } } $user = $this->factory->create($command->email, $command->firstName, $command->lastName); $apiUser = new ApiUserEntity($command->email, static::generateRandomSequence(16), static::generateRandomSequence(64), $user); $apiUser->generateHash(); $user->setDeleted(false); $user->setApiUser($apiUser); $this->notifier->notifyByScenario('created', $user, ['activation_hash' => $user->getApiUser()->getHash()]); $this->diamanteUserRepository->store($user); return $user->getId(); }