Search code examples
phpsecuritysymfonyroles

How to register different kinds of users in Symfony2


I am a teacher and I want to write my own system for our school to manage all the stuff.

For this I need to register first my school (in the future there will perhaps other schools which want to use our system). Then I want to be able to register new teachers, pupils, parents and other workers like the household personal and so on...

My question now is: is it enough for this usage to get the users different roles or should I create different user classes for every different kind of user? For example Appbundle/Entity/User/teachers.php

Perhaps there are other solutions like ACL or voters which I don't really know much about.


Solution

  • I would use:

    • a User entity with basic data and authentication credentials
    • an Activity entity that link a User to a School with a type enum field (e.g. "teacher", "parent", "pupil", ...)
    • a custom voter based on the Activity of the logged in User in the School he/she try to access to.

    I think it's future proof: a teacher in a school may be a parent in an other one :)