public function saveData()
 {
     if ($this->model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             // perform AJAX validation
             echo ActiveForm::validate($this->model);
             Yii::$app->end();
             return '';
         }
         /** @var User|bool $registeredUser */
         $registeredUser = $this->model->register();
         if ($registeredUser !== false) {
             $module = UsersModule::module();
             // login registered user if there's no need in confirmation
             $shouldLogin = $module->allowLoginInactiveAccounts || $module->emailConfirmationNeeded === false;
             if ($module->emailConfirmationNeeded === true && $registeredUser->is_active) {
                 $shouldLogin = true;
             }
             if ($shouldLogin && $registeredUser->login(UsersModule::module()->loginDuration)) {
                 $returnUrl = Yii::$app->request->get('returnUrl');
                 if ($returnUrl !== null) {
                     return $this->controller->redirect($returnUrl);
                 }
             }
             return $this->controller->goBack();
         }
     }
     return '';
 }
 public function socialRegistrationScenario(RegistrationForm &$registrationForm, BaseClient &$client)
 {
     if (empty($registrationForm->username)) {
         $registrationForm->generateUsername($client->getUserAttributes());
         $registrationForm->username_is_temporary = true;
     }
     if (empty($registrationForm->password)) {
         $registrationForm->password = PasswordHelper::generate(UsersModule::module()->generatedPasswordLength);
     }
 }