C
C
Crash2018-06-11 18:44:57
Yii
Crash, 2018-06-11 18:44:57

Is it possible to split authentication in Yii2 basic template?

I am building a website that will provide for work with a client base - a user profile, a personal account, etc.
Accordingly, there will be an admin panel, which will be used by a group of people - admin, managers, operators, etc.
I would not want to store all these accounts in one users table, separation is clearly needed here. For example, users for the site administration group and clients for clients.
As far as I understand, the yii\web\User class is responsible for authentication in yii2, and it is common in the yii2-basic template. Those. if the admin's id from the users table is 1, and the client's id from the clients table is also 1, then they will overlap each other.
Do I understand the scheme of work correctly and is it possible to separate authentication without transferring the project to an advanced template? Maybe the question is lamer, then it’s not even finished yet)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2018-06-11
@Maksclub

Take the ready-made module https://github.com/dektrium/yii2-rbac
With it, the database will already be perfectly divided, there will be 4 tables with rights, with roles and profile (here personal data is stored)
Only the login and accesses will be stored in the native table

M
Maxim Timofeev, 2018-06-12
@webinar

I would not want to store all these accounts in one users table, there is clearly a need for separation

Why? If they differ only in role, then it is not true to split them into different tables, and from which side you don’t look. At least how will you uniquely identify the user? You doom yourself to a bunch of hemorrhoids in the absence of at least any benefit. Meaning?
There is related data for that. But the User table itself will be alone. Approximate, simplified scheme:
User: id | username | pass
User_dop_fields: id | field_name | some_fild_settings
User_dop_fields_value: id | user_id | dop_field_id | value
Dop_fields_by_role: id | role_name | dop_fild_id
and plus 4 standard tables for rbac. All Your user has a different set of parameters depending on the role + they can be added dynamically.

S
Sergey Zimoglyadov, 2018-06-13
@wppdevelop

Alternatively, you can do this in the config:

'components' => [
        ...
        'userAdmin' => [
            'identityClass' => 'common\models\UserAdmin',
        ],
        'userClient' => [
            'identityClass' => 'common\models\UserClient',
        ],
        ...
},

And then for admins and clients to use their classes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question