public function actionRecovery()
    {
        /** @var RecoveryForm */
        $model = $this->module->createFormModel('RecoveryForm');
        if (isset($_GET['activationKey'])) {
            $model->scenario = 'reset';
            $model->setAttributes($_GET);
        }
        if ($model->load($_POST)) {
            if (Yii::$app->request->isAjax) {
                Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

                return \yii\widgets\ActiveForm::validate($model);
            }
            /**
             * If the activation key is missing that means the user is requesting a recovery email.
             */
            if ($model->activationKey !== null) {
                $model->scenario = 'reset';
            }
            if ($model->validate()) {
                if ($model->scenario !== 'reset') {
                    /**
                     * Send email appropriate to the activation status. If verification is required, that must happen
                     * before password recovery. Also allows re-sending of verification emails.
                     */
                    if ($this->sendEmail($model, $model->identity->isActive() ? 'recovery' : 'verify')) {
                        Yii::$app->session->setFlash('success', Yii::t('usr', 'An email containing further instructions has been sent to email associated with specified user account.'));
                    } else {
                        Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to send an email.').' '.Yii::t('usr', 'Try again or contact the site administrator.'));
                    }
                } else {
                    // a valid recovery form means the user confirmed his email address
                    $model->getIdentity()->verifyEmail($this->module->requireVerifiedEmail);
                    // regenerate the activation key to prevent reply attack
                    $model->getIdentity()->getActivationKey();
                    if ($model->resetPassword() && $model->login()) {
                        return $this->afterLogin();
                    } else {
                        Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
                    }
                }

                return $this->redirect(['recovery']);
            }
        }

        return $this->render('recovery', ['model' => $model]);
    }