A
A
Artyom Temnikov2020-07-02 06:35:30
Yii
Artyom Temnikov, 2020-07-02 06:35:30

How to create 2 types of users in YIi2?

There are clients, there are partners.

Clients have certain fields in the database, while partners have others.

The bottom line is to have 2 tables of users and if a user from 'Clients' is authorized, then Yii2 does not recognize him as authorized in the module ('partners'). Well, vice versa. Is this even possible? (I understand that there is an option to create a user table, with fields: email, pass, user_type - then create other tables and output depending on the type of user, but this is not about that).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2020-07-02
@arttech01

Clients are not always users of the system.
Partners are not always users of the system.
If you think in this way, then you need to share these responsibilities. It will be more correct. You will get a system divided into modules. This will allow you to make independence both at the code level and at the base level. Divide your code and base by responsibility.

  • Auth module - Authentication management system: login, password, phone, social networks (for social network login), roles, permissions, and so on.
  • Partners module - Partner management system.
  • CRM Module - Customer Relationship Management System.

In clients, partners there is a link to user_id (account). Thus, your system is divided into its responsibilities (modules) and each system solves one specific task / problem. Your code becomes less coupled and more independent.
User you need to just log in. And when it is authorized, you work with a Client or Partner. In the UI interface, you create two personal accounts or one with switching (client's account, partner's account)
PS: An important comment. By modules, I do not mean Yii modules, but an area of ​​code that is focused on solving a specific task and is loosely connected to other modules. There are no modules in Yii3 at all. Modules can be separated by folders:
src/Model/User
src/Model/СRM

T
Timur Khudiyev, 2020-07-02
@t_khudiyev

You can assign roles to different types of users and set the rights to certain actions in the controller. This is done using RBAC as mentioned above. It is easy to google, but it may not be clear the first time, because there are many connections between each other. The idea is this: when a user registers, he is assigned a role. This role has a permission associated with it (there may be more than one.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question