我只在后端拥有用户授权(对于管理员),我正在尝试将密码重置功能移到后端。
\后端\视图\站点\ 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的新手,非常感谢任何帮助。
答案 0 :(得分:1)
更新您的控制器Access Control Filter,以允许尚未登录的用户访问public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['request-password-reset'],
'allow' => true,
'roles' => ['?'],
],
...
:
TestClass<"StringValue"> obj = new TestClass<"StringValue">()