src/Mvc/Controller/RegistrationController.php
public function indexAction()
    {
        $authPlugin = $this->cmsAuthentication();

        // if the user is logged in, we don't need to register
        if ($authPlugin->hasIdentity()) {
            // redirect to the default user route
            $route = $this->getOptions()->getDefaultUserRoute();
            if (is_callable($route)) {
                $route = $route($authPlugin->getIdentity());
            }

            return $this->redirect()->toRoute($route);
        }

        // if registration is disabled
        if (!($enableRegistration = $this->getOptions()->getEnableRegistration())) {
            return new ViewModel(compact('enableRegistration'));
        }

        if ($this->getOptions()->getUseRegistrationRedirectParameter()) {
            $redirect = $this->params()->fromQuery('redirect', false);
        } else {
            $redirect = false;
        }

        $url = $this->url()->fromRoute(null, [],
            $redirect ? ['query' => ['redirect' => rawurldecode($redirect)]] : []
        );

        $prg = $this->prg($url, true);
        // Return early if prg plugin returned a response
        if ($prg instanceof ResponseInterface) {
            return $prg;
        }

        $post = $prg;

        $this->flashMessenger()->setNamespace($this->registrationNamespace)->clearCurrentMessages();

        $form = $this->getUserService()->getRegisterForm();
        $form->setAttribute('action', $this->url()->fromRoute());
        if ($redirect && $form->has('redirect')) {
            $form->get('redirect')->setValue($redirect);
        }

        if ($post && $form->setData($post)->isValid()) {

            $redirect = empty($post['redirect']) ? $redirect : $post['redirect'];

            $identity = $this->getUserService()->register($post);

            // Return early if an user service returned a response
            if ($identity instanceof ResponseInterface) {
                return $identity;
            } elseif ($identity) { // We are registered

                if ($this->identityElement && $this->credentialElement
                    && $this->getOptions()->getLoginAfterRegistration()
                ) {
                    // Create authentication data
                    $identityFields = $this->getOptions()->getIdentityFields();
                    if ($this->getOptions()->getEnableUsername()) {
                        $post[$this->identityElement->getName()] = $identity->getEmail();
                    } elseif (in_array('username', $identityFields)) {
                        $post[$this->identityElement->getName()] = $identity->getUsername();
                    }
                    $post[$this->credentialElement->getName()] = $post['password'];
                    if ($redirect) {
                        $post['redirect'] = $redirect;
                    }

                    $this->flashMessenger()->addSuccessMessage($this->translate(
                        'Congratulations! You have successfully registered. ' .
                        'Please, check your inbox to confirm your email address ' .
                        'and to complete registration.'
                    , 'CmsUser'));

                    $this->getRequest()->setPost(new Parameters($post));
                    return $this->forward()->dispatch(
                        $this->getOptions()->getAuthenticationController(),
                        ['action' => 'authenticate']
                    );
                }

                if ($redirect) {
                    return $this->redirect()->toUrl($redirect);
                }

                // redirect to the default user route
                $route = $this->getOptions()->getDefaultUserRoute();
                if (is_callable($route)) {
                    $route = $route($authPlugin->getIdentity());
                }

                return $this->redirect()->toRoute($route);
            }
        }

        return new ViewModel(compact('enableRegistration', 'form'));
    }
public function indexAction()
    {
        $authPlugin = $this->cmsAuthentication();

        // if the user is logged in, we don't need to register
        if ($authPlugin->hasIdentity()) {
            // redirect to the default user route
            $route = $this->getOptions()->getDefaultUserRoute();
            if (is_callable($route)) {
                $route = $route($authPlugin->getIdentity());
            }

            return $this->redirect()->toRoute($route);
        }

        // if registration is disabled
        if (!($enableRegistration = $this->getOptions()->getEnableRegistration())) {
            return new ViewModel(compact('enableRegistration'));
        }

        if ($this->getOptions()->getUseRegistrationRedirectParameter()) {
            $redirect = $this->params()->fromQuery('redirect', false);
        } else {
            $redirect = false;
        }

        $url = $this->url()->fromRoute(null, [],
            $redirect ? ['query' => ['redirect' => rawurldecode($redirect)]] : []
        );

        $prg = $this->prg($url, true);
        // Return early if prg plugin returned a response
        if ($prg instanceof ResponseInterface) {
            return $prg;
        }

        $post = $prg;

        $this->flashMessenger()->setNamespace($this->registrationNamespace)->clearCurrentMessages();

        $form = $this->getUserService()->getRegisterForm();
        $form->setAttribute('action', $this->url()->fromRoute());
        if ($redirect && $form->has('redirect')) {
            $form->get('redirect')->setValue($redirect);
        }

        if ($post && $form->setData($post)->isValid()) {

            $redirect = empty($post['redirect']) ? $redirect : $post['redirect'];

            $identity = $this->getUserService()->register($post);

            // Return early if an user service returned a response
            if ($identity instanceof ResponseInterface) {
                return $identity;
            } elseif ($identity) { // We are registered

                if ($this->identityElement && $this->credentialElement
                    && $this->getOptions()->getLoginAfterRegistration()
                ) {
                    // Create authentication data
                    $identityFields = $this->getOptions()->getIdentityFields();
                    if ($this->getOptions()->getEnableUsername()) {
                        $post[$this->identityElement->getName()] = $identity->getEmail();
                    } elseif (in_array('username', $identityFields)) {
                        $post[$this->identityElement->getName()] = $identity->getUsername();
                    }
                    $post[$this->credentialElement->getName()] = $post['password'];
                    if ($redirect) {
                        $post['redirect'] = $redirect;
                    }

                    $this->flashMessenger()->addSuccessMessage($this->translate(
                        'Congratulations! You have successfully registered. ' .
                        'Please, check your inbox to confirm your email address ' .
                        'and to complete registration.'
                    , 'CmsUser'));

                    $this->getRequest()->setPost(new Parameters($post));
                    return $this->forward()->dispatch(
                        $this->getOptions()->getAuthenticationController(),
                        ['action' => 'authenticate']
                    );
                }

                if ($redirect) {
                    return $this->redirect()->toUrl($redirect);
                }

                // redirect to the default user route
                $route = $this->getOptions()->getDefaultUserRoute();
                if (is_callable($route)) {
                    $route = $route($authPlugin->getIdentity());
                }

                return $this->redirect()->toRoute($route);
            }
        }

        return new ViewModel(compact('enableRegistration', 'form'));
    }
Register index action

Displays user registration form

@return ResponseInterface|ViewModel