Answer the question
In order to leave comments, you need to log in
How to make authorization in yii2 through the database?
In the standard Users model, the basic template has an array:
private static $users = [
'100' => [
'id' => '100',
'username' => 'admin',
'password' => 'admin',
'authKey' => 'test100key',
'accessToken' => '100-token',
],
'101' => [
'id' => '101',
'username' => 'demo',
'password' => 'demo',
'authKey' => 'test101key',
'accessToken' => '101-token',
],
];
Answer the question
In order to leave comments, you need to log in
In general stuck with crutches in the existing code.
in the findIdentity($id) method, by this id, I look for a record about the user, form an array, as a standard one, and override it with the values of this array. This method checks the logged in user.
And for validation, I did the same in findByUsername($username)
Well, in the validatePassword($password) method, I had to add md5 password generation, that's all.
If anyone needs a file /public_html/models/Users.php with these methods, write - I will send it. Email in profile.
You have two very simple ways
1) install the advanced template, where user is the standard functionality that works with the database, you only need to enter the database settings and run migrations
2) https://github.com/dektrium/yii2-user install this extension.
It will be easier. than to make you a bicycle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question