Hi again
I have this new issue which I just noticed today. I’m playing around with pages that require authentication and when my user (I have only one in the database) logs in, I’m taken to the home page as expected, but I’m not logged in. I can see this by var dumping the session, as well as Yii:$app->user. Also, it still says Login in the top menu.
I haven’t extended any of the associated classes so it’s really weird. it’s like that session is being unset at some point.
Here is my code (which is pretty much unchanged from the generated advanced template)
siteController
// behaviors - access control
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'register'],
'rules' => [
[
'actions' => ['register'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
// actionLogin
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
//var_dump(Yii::$app->user);
// exit;
//return $this->goBack();
$this->redirect('site/index');
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
As you can see in actionLogin(), I have some commented out debugging code to check if the login actually works. When I uncomment this, I can see that my user logs in, but once I put the comments back on, the login is unset somehow. Anyway, it redirects just fine to site/index so I know it is passing the login. To double check, I have tried putting but data into the login form and it fails with validation errors as expected.
Has anyone got any ideas about this?