我只在後端有用戶授權(對於管理員),我試圖將密碼重置功能移動到後端。將重置密碼移動到後端,Yii2
\後端\意見\網站\ 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>
\後端\ \控制器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很感興趣,並希望得到任何幫助。
默認後端SiteController有'AccessControl'過濾器,這意味着,如果您還沒有登錄..頁面會重定向你登錄行動 –
謝謝,我使用另一個控制器,它現在可以工作。 –