将重置密码移动到后端,Yii2

Moving reset password to backend, Yii2

我只有后端用户授权(对于管理员),我正在尝试将密码重置功能移至后端。

\backend\views\site\login.php

<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>

            //fields for username and password

            <div class="form-group">
                <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
            </div>

        <?php ActiveForm::end(); ?>

        <div style="color:#999;margin:1em 0">
               If you forgot your password you can <?= Html::a('reset it', ['request-password-reset']) ?>.
           </div>

\backend\controllers\SiteController.php

public function actionLogin()
{
    if (!\Yii::$app->user->isGuest) {
        return $this->goHome();
    }

    $model = new LoginForm();
    if ($model->load(Yii::$app->request->post()) && $model->login()) {
        return $this->goBack();
    } else {
       //enters here instead
        return $this->render('login', [
            'model' => $model,
        ]);
    }
}
public function actionRequestPasswordReset()
    {
       //not entering here
        $model = new PasswordResetRequestForm(); //placed in \common\models
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($model->sendEmail()) {
                Yii::$app->session->setFlash('success', 'Check your email for further instructions.');

                return $this->goHome();
            } else {
                Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
            }
        }

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

问题是当我单击 reset it 时,该站点再次将我重定向到 login.php,因此 actionRequestPasswordReset() 没有被触发。我是 Yii 的新手,希望得到任何帮助。

更新控制器的 Access Control Filter 以允许尚未登录的用户访问 requestPasswordReset:

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['request-password-reset'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
                ...