/** * @param SignupForm $form * @return Entity\User * @throws \Exception */ public function create(SignupForm $form) { $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $data = $form->getData(); $user = new Entity\User(); $objectManager->getConnection()->beginTransaction(); try { $hydrator = new DoctrineHydrator($objectManager); $hydrator->hydrate($form->getData(), $user); $user->setDisplayName($user->getEmail()); $user->setRole($user::ROLE_USER); $user->setConfirm($user->generateConfirm()); $user->setStatus($user::STATUS_UNCONFIRMED); $objectManager->persist($user); $objectManager->flush(); /** * @var $authService \User\Service\Auth */ $authService = $this->getServiceLocator()->get('User\\Service\\Auth'); $authService->generateEquals($user, $data['password']); //use module mail for user registration if ($this->useModuleMail()) { /** @var \Mail\Service\Mail $mailService */ $mailService = $this->getServiceLocator()->get('Mail\\Service\\Mail'); $mailService->signUpMail($user); } else { $html = $this->getServiceLocator()->get('ControllerPluginManager')->get('forward')->dispatch('User\\Controller\\Mail', array('action' => 'signup', 'user' => $user)); $this->signupMail($user, $html); } $objectManager->getConnection()->commit(); } catch (\Exception $exception) { $objectManager->getConnection()->rollback(); throw $exception; } return $user; }