L
L
Looking2014-03-25 13:07:52
Yii
Looking, 2014-03-25 13:07:52

What is the best way to organize registration/authorization and 3 roles (Yii)?

Good time of the day.
Do I need to implement RBAC if I need "guest", "authorized", "admin", or can I get by with some simpler architecture?
I find rbac complicated and don't fully understand the details of its implementation (read habrahabr.ru/post/177873 and yii documentation). I just don't understand why there are 3 tables in the database for such a trivial task.
And yet (sorry for the second question), registration and authorization should work through the same model?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Morozov, 2014-03-25
@Looking

These roles are easily implemented using a regular accessFilter, just don't forget to control user access to "foreign" content.
You can make, for example, three parts:
1. general part, for everyone
2. module for users (creating / editing content)
3. module for admin (administration of this whole circus)
The module for users is covered by the accessControl filter with the setting 'users' = > array('@'), and when editing a post, check for owner_id. For convenience, you can put this in a named scope so you can do something like
$record = MyModel::model()->active()->ownedBy(Yii::app()->user->id)-> findByPk($id); if (!$record) {throw 404}
or in general $record = MyModel::model()->active()->own()->findByPk($id); (crooked from the point of view of MVC, but convenient)
The module for admins is covered by accessRules with the setting 'expression' => '$user->isAdmin()',

A
Alexander Zelenin, 2014-03-25
@zelenin

I advise you to look at yii2-app-advanced in the official repository - there is both registration and login.
rbac to implement through the config file, the implementation is the simplest.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question