public function actionRegister($profile, $authItems = null, $generatePassword = false, $unlock = false)
    {
        $module = Yii::$app->getModule('usr');
        /** @var ProfileForm */
        $model = $module->createFormModel('ProfileForm', 'register');
        /** @var PasswordForm */
        $passwordForm = $module->createFormModel('PasswordForm', 'register');

        if (($profileData = json_decode($profile)) === null) {
            parse_str($profile, $profileData);
        }
        $model->setAttributes($profileData);
        if (isset($profile['password'])) {
            $passwordForm->setAttributes(['newPassword' => $profile['password'], 'newVerify' => $profile['password']]);
        }
        if ($generatePassword) {
            $diceware = new \nineinchnick\diceware\Diceware(Yii::$app->language);
            $password = $diceware->get_phrase($module->dicewareLength, $module->dicewareExtraDigit, $module->dicewareExtraChar);
            $passwordForm->setAttributes(['newPassword' => $password, 'newVerify' => $password]);
        }

        if ($model->validate() && $passwordForm->validate()) {
            $trx = Yii::$app->db->beginTransaction();
            if (!$model->save() || !$passwordForm->resetPassword($model->getIdentity())) {
                $trx->rollback();
                echo Yii::t('usr', 'Failed to register a new user.')."\n";

                return false;
            } else {
                $trx->commit();
                echo $model->username.' '.$passwordForm->newPassword."\n";
                $identity = $model->getIdentity();
                if ($authItems !== null) {
                    $authItems = array_map('trim', explode(',', trim($authItems, " \t\n\r\b\x0B,")));
                    $authManager = Yii::$app->authManager;
                    foreach ($authItems as $authItemName) {
                        $authManager->assign($authItemName, $identity->getId());
                    }
                }
                if ($unlock) {
                    if (!$identity->isActive()) {
                        $identity->toggleStatus($identity::STATUS_IS_ACTIVE);
                    }
                    if ($identity->isDisabled()) {
                        $identity->toggleStatus($identity::STATUS_IS_DISABLED);
                    }
                }

                return true;
            }
        }
        echo "Invalid data: ".print_r($model->getErrors(), true)."\n";

        return false;
    }