RegisterController::confirmAction PHP Method

confirmAction() public method

public confirmAction ( )
    public function confirmAction()
    {
        $translator = \Zend_Registry::get('container')->getService('translator');
        $session = \Zend_Registry::get('container')->getService('session');
        $user = $this->getAuthUser();
        $social = $this->_getParam('social');
        $form = $this->_helper->form('confirm');
        $form->setMethod('POST');
        $form->setDefaults(array('first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'username' => $this->_helper->service('user')->generateUsername($user->getFirstName(), $user->getLastName())));
        if ($this->auth->hasIdentity()) {
            $form->removeElement('password');
            $form->removeElement('password_confirm');
        }
        $request = $this->getRequest();
        if ($request->isPost() && $form->isValid($request->getPost())) {
            $values = $form->getValues();
            try {
                if (!empty($values['image'])) {
                    $imageInfo = array_pop($form->image->getFileInfo());
                    $values['image'] = $this->_helper->service('image')->save($imageInfo);
                }
                $this->_helper->service('user')->savePending($values, $user);
                $this->_helper->service('dispatcher')->dispatch('user.register', new GenericEvent($this, array('user' => $user)));
                $this->_helper->service('user.token')->invalidateTokens($user, 'email.confirm');
                $auth = \Zend_Auth::getInstance();
                if ($auth->hasIdentity()) {
                    $this->_helper->flashMessenger('User registered successfully.');
                    $this->_helper->redirector(null, null, 'default');
                } else {
                    $adapter = $this->_helper->service('auth.adapter');
                    $adapter->setEmail($user->getEmail())->setPassword($values['password']);
                    $auth->authenticate($adapter);
                    $token = $this->_helper->service('user')->loginUser($user, 'frontend_area');
                    $session->set('_security_frontend_area', serialize($token));
                    $OAuthtoken = $this->_helper->service('user')->loginUser($user, 'oauth_authorize');
                    $session->set('_security_oauth_authorize', serialize($OAuthtoken));
                    if (isset($values['_target_path']) && !empty($values['_target_path'])) {
                        $this->_helper->redirector->gotoUrl($values['_target_path']);
                    }
                    $this->_helper->redirector('index', 'dashboard', 'default', array('first' => 1));
                }
            } catch (InvalidArgumentException $e) {
                $form->username->addError($translator->trans('Username is used. Please use another one.', array(), 'users'));
            }
        }
        $this->view->form = $form;
        $this->view->user = new \MetaUser($user);
        $this->view->social = $social ?: false;
    }