Kohana 3.3 expanding the Auth module

2019-05-24 07:47发布

I'm building an application using the Auth module for which I need at least 3 account types : Employer, Employee and Client. Since these accounts have different properties, functions and relationships (ex: employers has_many employees) I guess I need to have them on 3 separate ORM models.

The method I thought was to tweak the Auth module to replace the 'User' model with the appropriate sub-model (employer, employee, client), corresponding the the user type in the database.

Can this be done, or is it bad practice?

3条回答
趁早两清
2楼-- · 2019-05-24 08:07

For such rurposes you need to create different Model classes for each account type extending default Auth_ORM's Model_User class.

Then you need to create new Auth_ORM class extending Kohana_Auth_ORM class in your application/classes folder.

In this file you need to rewrite protected _login() method, so its $user variable to point to required account type.

查看更多
姐就是有狂的资本
3楼-- · 2019-05-24 08:16

I have found interesting repository here: https://github.com/alexgisby/MAuth. I have the same problem as You have, so maybe if You manage to resolve it You could share the solution. I think the repository from this link could be a solution, but i didn't manage to implement it so far

查看更多
再贱就再见
4楼-- · 2019-05-24 08:30

You can have 1 model - User and 3 different roles. And depending to role, you can load specific module, which will contain required classes.

For example, if User has role Employee you will load modules/role_employee

查看更多
登录 后发表回答