Answer the question
In order to leave comments, you need to log in
How to login in Yii2 without DB involvement?
Lord, please help.
I googled everything, the same manual walks both here and over the hill.
I can not get to the idea of how to log in simply forcibly.
The maximum I got to: \Yii::$app->getUser()->login(User::findByRoot());
And in the User model :
public static function findByRoot()
{
$model = new User();
$model->id = '1000';
$model->username = 'vasya';
$model->status = 10;
return $model;
}
public static function findByRoot()
{
$arr = [
'id' => 100,
'username' => 'vasya',
'status' => 10,
];
return new static($arr);
}
$arr = [
'id' => 100,
'created_at' => 1444322024,
'updated_at' => 1444322024,
'username' => 'vasya',
'auth_key' => 'aagsdghfgukfyrtweri',
'email_confirm_token' => NULL,
'password_hash' => 'aa2gsdg123hfgukfyrtweri',
'password_reset_token' => NULL,
'email' => '[email protected]',
'status' => 10,
];
return new static($arr);
Answer the question
In order to leave comments, you need to log in
Resolved the issue. The problem was that Yii2 rechecks UserIdendity and makes a new request, in which case it is necessary to return fake data again with the findIdentity method
public static function findIdentity($id)
{
if($id == 1385)
return self::findByRoot();
else
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
I didn’t understand the question very well, but I suppose that you need something like a fixed set of accounts right in the code and a login under them. This is done in the basic application. See what it says there. The point is that IdentityInterface should be hung on the class that is responsible for authorization.
class User implements IdentityInterface
{
...
}
Your example is the most correct thing you can do, you just mistyped/underwritten somewhere. Yii::$ap->user->isGuest == false
implies that there is Yii::$ap->user->identity
, pointing to the user model.
And the standard solution will help you solve your problem: https://github.com/yiisoft/yii2-app-basic/blob/mas...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question