So i can see that advanced app template has the forgot password functionality built in, but is there example on how to use it ?
For eg, the login form does not come built in with a forgot/reset password link ?
Thx
So i can see that advanced app template has the forgot password functionality built in, but is there example on how to use it ?
For eg, the login form does not come built in with a forgot/reset password link ?
Thx
Sure about that?
My advanced app has a link for password reset…
Directly above the "Login" button.
If you need better understanding in how the reset function works take a look at:
frontend\models\PasswordResetRequestForm;
frontend\models\ResetPasswordForm;
frontend\controllers\SiteController.php
And the controller methods:
actionRequestPasswordReset();
actionResetPassword($token);
Regards
Thanks - I realise what i was doing - even though i’m using advanced template, i am only running the backend, which for some reason does not have that reset password link.
So, in order to replicate the frontend link to backend, I have done the following:
Added to backend/views/site/login.php:
If you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>.
Added to backend/controllers/SiteController:
public function actionRequestPasswordReset()
public function actionResetPassword($token)
Added requestPasswordResetToken.php, resetPassword.php TO backend/views/site/
Added PasswordResetRequestForm.php, ResetPasswordForm.php TO backend/models
It seems I’m still missing something though because when I click the reset link, it just reloads itself (login page)?
Without any error?
Is your environment in DEV?
And do you have enabled the YII Debug Toolbar?
If not I would suggest to do this…
Can help a lot to track down what is going wrong when you press the link.
Also have you copied the models for the forms under frontend/models/ ?
Best Regards
Okay reproduced your problem by following your steps.
AccessControl is not allowing backend users to use the actions.
Change:
[spoiler]
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
[/spoiler]
TO:
[spoiler]
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
// you have to add the actions which are allowed here
'actions' => ['login', 'error', 'request-password-reset', 'reset-password'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
[/spoiler]
But then you probably will receive another error,
because the form models are missing.
Add use statements to your backend/controllers/SiteController:
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
Or copy the models from frontend to backend/models and adjust the namespace and use statements.
Also a addinional tip / suggest for further development:
You could place code which is identical in frontend and backend in "common".
Adjust the namespaces / use statements and create "stand alone" actions for pw-reset-request and pw-reset.
Then you have a signle place for "shared code" between frontend and backend.
If you are new to stand alone actions just google:
"yii2 stand alone action"
Best Regards
Recreat the functions in one of your backend controllers.
This was it !
Thank you very much ! Everything else I had moved/copied correctly except for this.
Weird though - I just checked the frontend/SiteController, and it does not contain those AccessControl behaviors
cheers