src/Service/UserService.php
public function register($data)
    {
        /* @var $user UserInterface */
        if (!($user = $this->hydrate($data, $this->getRegisterForm()))) {
            return;
        }

        $eventManager = $this->getEventManager();
        $eventManager->trigger(__FUNCTION__, $this, compact('user'));

        if ($user instanceof StateableInterface) {
            $user->setState($this->getOption('default_user_state'));
        }

        $user->setRegistrationToken($this->getRegistrationToken());

        if ($user instanceof PasswordableInterface) {
            $cryptoService = $this->getMapper()->getPasswordService();
            $password = $cryptoService->create($user->getPassword());
            $user->setPassword($password);
        }

        $viewModel = new ViewModel(compact('user'));
        $viewModel->setTemplate('mail-message/user-register');

        $mailService = $this->getMailService();
        $message = $mailService->getMessage();
        $message->setTo($user->getEmail(), $user->getDisplayName());

        $subject = 'Please, complete your registration!';
        if ($this->getTranslator() && $this->isTranslatorEnabled()) {
            $subject = $this->getTranslator()->translate(
                $subject,
                $this->getTranslatorTextDomain()
            );
        }
        $message->setSubject($subject);

        $mailService->setBody($viewModel)->sendMessage();

        $this->getMapper()->add($user)->save();

        $eventManager->trigger(__FUNCTION__ . '.post', $this, compact('user'));

        return $user;
    }
public function register($data)
    {
        /* @var $user UserInterface */
        if (!($user = $this->hydrate($data, $this->getRegisterForm()))) {
            return;
        }

        $eventManager = $this->getEventManager();
        $eventManager->trigger(__FUNCTION__, $this, compact('user'));

        if ($user instanceof StateableInterface) {
            $user->setState($this->getOption('default_user_state'));
        }

        $user->setRegistrationToken($this->getRegistrationToken());

        if ($user instanceof PasswordableInterface) {
            $cryptoService = $this->getMapper()->getPasswordService();
            $password = $cryptoService->create($user->getPassword());
            $user->setPassword($password);
        }

        $viewModel = new ViewModel(compact('user'));
        $viewModel->setTemplate('mail-message/user-register');

        $mailService = $this->getMailService();
        $message = $mailService->getMessage();
        $message->setTo($user->getEmail(), $user->getDisplayName());

        $subject = 'Please, complete your registration!';
        if ($this->getTranslator() && $this->isTranslatorEnabled()) {
            $subject = $this->getTranslator()->translate(
                $subject,
                $this->getTranslatorTextDomain()
            );
        }
        $message->setSubject($subject);

        $mailService->setBody($viewModel)->sendMessage();

        $this->getMapper()->add($user)->save();

        $eventManager->trigger(__FUNCTION__ . '.post', $this, compact('user'));

        return $user;
    }
Register user

@param array|UserInterface $data
@return UserInterface|void