application\modules\social\controllers\UserController::actionRegister PHP Method

actionRegister() public method

public actionRegister ( )
    public function actionRegister()
    {
        $authData = $this->service->getAuthData();
        if (null === $authData || Yii::app()->getUser()->isAuthenticated()) {
            $this->redirect(Yii::app()->getUser()->returnUrl);
        }
        $module = Yii::app()->getModule('user');
        if ($module->registrationDisabled) {
            throw new CHttpException(404, Yii::t('SocialModule.social', 'Page not found!'));
        }
        $form = new RegistrationForm();
        if (isset($authData['email'])) {
            $form->email = $authData['email'];
        }
        $form->disableCaptcha = true;
        if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['RegistrationForm'])) {
            $form->setAttributes(Yii::app()->getRequest()->getPost('RegistrationForm'));
            if (!isset($authData['email']) && Yii::app()->userManager->isUserExist($form->email)) {
                Yii::app()->getUser()->setFlash(YFlashMessages::INFO_MESSAGE, Yii::t('SocialModule.social', 'Account with this email address already exists!  Please, login if you want to join this social network to your account.'));
                $this->redirect(['/social/connect', 'service' => $this->service->getServiceName()]);
            }
            $password = Yii::app()->userManager->hasher->generateRandomPassword();
            $form->setAttributes(['password' => $password, 'cPassword' => $password, 'verifyCode' => null]);
            if ($form->validate()) {
                if ($user = Yii::app()->userManager->createUser($form)) {
                    $social = new SocialUser();
                    $social->user_id = $user->id;
                    $social->provider = $authData['service'];
                    $social->uid = $authData['uid'];
                    if ($social->save()) {
                        Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SocialModule.social', 'Registration is successful!'));
                        $this->redirect([$module->registrationSuccess]);
                    }
                }
            }
            $form->addError('', Yii::t('SocialModule.social', 'Error!'));
        }
        $this->render('register', ['model' => $form, 'module' => $module]);
    }