New to Yii, set it all up and all working great so far.
My question is not handled in any of the docs i could find
On my login controller I’m calling external API of other system, passing email and password over HTTP and in response I receive JSESSIONID cookie.
I’ve create a custom class that implements the Identify interface named CmsUser , I’m creating an instance, setting the property and pass it to the login.
$identity = new \common\models\CmsUser();
$identity->id = $body['id'];
$identity->firstName = $body['firstName'];
$identity->lastName = $body['lastName'];
$identity->isDriver = $body['isDriver'];
$identity->email = $body['email'];
$identity->authorities = $body['authorities'];
$identity->jSessionId = $cookies['JSESSIONID'];
Yii::$app->user->login($identity);
The the login controller redirects to site/index and display the firstname and last name correctly.
Also from layout the next part of code is showing the logout so Yii knows user is logged in
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/login/index']];
} else {
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->fullName() . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>';
}
No cookies are written and also when I click on another link the Logout button is gone so Yii no longer knows the user->identity that is logged in.
What am I missing here?