I am using Ion Auth for user authentication. The system i am trying to build needs two different users tables for client and admin. As in the application/config/ion_auth.php i can change only one table name, how i can make sure two controllers uses two different users table?
Why not create groups instead? You can use the create_group method
then just check if the user belongs to that group.
Just create a Client group and an Admin group. You can also add more like Moderator group, etc.
This way is more convenient that having more than 1 users table
Make new tables with needed fields and relate it to group_id in users_groups.
Each table in a database should represent an entity. Since you need an entity User for authentication purposes you should have one table for all users. After that you can create tables for Admin and Client and create relationships between those and the Users table.
Related
I am using Laravel built-in Authentication for users which I run from the terminal php artisan make:auth
It has one table in the database, users table and has an isAdmin column, so I am assuming it has two roles an admin and not_amin account.
Now, what I want is to modify this built-in functionality of Laravel make:auth to be able to add some roles like isEmployee and/or isCustomer.
How can I achieve this using the available option I have?
I hope, I somewhat explained my case. Thanks.
Having a column is_admin is targeted to only one role. This tells you if user is an admin or not.
I would suggest you to change depending on any of below cases :
1. If user can have just 1 role :
Modify users table and change is_admin to role. Inside role column, you can store the role of that particular user like admin, employee, 'customer` etc.
2. If user has multiple roles(many-to-many) :
Remove column is_admin from users table and create a new table role_user which will have user_id and role_id. You will need to have another table called roles to store all available roles in your system.
I want to design a DB which will be connected to PHP Application. In the app there are two types of users: company and person. Some functionality like adding articles will be done by both so in other tables there are author_id columns. So firstly I decided to create user column.
That's easy: id, username, password, role, active, created where role defines whether user is person or company.
Now I want to add profile table or profile tables depends on what you'd suggest (joined with the previous table by adding profile_id column there).
Both roles have different fields, which are required during registration.
The easiest thing would be to create one table with all required fields for both roles, allow them NULL values and in the PHP app (made in Yii Framework in this case) define requirements for each role in models.
The nicest thing would be to create separate tables for both roles BUT the questions is how to connect these two tables to one table using Foreign Key? Is it even possible. I know I may omit foreign key creation then based on role choose table, and from that table choose profile_id.
Or maybe you have another solution to my problem.
Thanks in advance for replies.
Adrian
You need an intermediary between the page and the database to assign the user to a group that has specific privileges. It's usually accomplished with a user-group-role design.
You can have a table for users system info (username , pass ...), and another for users profile (firstname , birthday ...), and another for groups(superuser , ...).
where user table can have multiple groups: user:one->group:many
user can have one profile user:one->profile:one
I think this is a decent solution.
I know we can create groups in ion auth. But I need sub group inside members and staff groups.The following user roles are required for my project.
Admin
Members
plan A members
plan B members
plan C members
Staff
technical staff
management staff
general staff
Based on plan selected by member, the 'views' and functionalities will change.
I was thinking of adding a new column to users table to specify the plan used.
Another option is to create 3 plan groups without parent member group.
Is there any other way to add sub groups using ion auth?
#Arunu - your idea to make them each groups, not subgroups, is the best way to go.
There is no real reason to have a hierarchy of permissions (I think you may be mixing authentication with ACL a bit, a very easy thing to do).
Ion_auth is set up so that a user can have multiple groups - so, for example, all your users could have a Members record, and then a separate record for each sub group.
Each controller entry point simply says what groups are allowed in or not - it treats them all the same.
also, you can dynamically display data based on what groups the user belongs to
I have the hierarchy where there are different categories of users like
Staff Admins
Teachers
Parents
Students
I was thinking to put them all in one database table called usertable
But then all categories will their different attributes and then students will also have their parents. SO there will be many to many relationships with own usertable.
But if i make different tables then the login process will be different for different people.
HOw should i go
Since the users will all share common details, like username, password, etc., you only need one user table for them. You should actually use the FOSUserBundle for this. If different types of users have different sets of unique details, I suggest creating additional tables per user type, and use a foreign key to link users from the user table to the new table (perhaps named something like parent_profile, student_profile, etc.)
In regards to the hierarchy of users, you should be using roles. The Symfony2 docs have all the info you'll need on this subject.
If you need to link users to each other, read up on Doctrine 2's support for one-to-one self referencing and one-to-many self referencing associations. If you use separate entity classes for user user type, you can use the regular one-to-one and one-to-many association techniques.
Hope this helps.
I'm using Codeigniter with Ion Auth for user management. I'd like to create two different user roles - one for volunteers and one for organizations. I know that I can use Ion Auth's groups for things like access control, but what would be a good way to add fields to the different user types (for instance - the volunteer user will have a 'languages spoken' field while the organization will have a 'mission' field)? Should I extend the Ion Auth class for each new user type and handle CRUD seperately for each type, or use the 'groups' field and the user id to reference the fields in another table? Any insight as to an approach to this common problem?
I would recommend just adding all the fields you need into the meta table and only updating the ones you need per user group. If you need multiple groups per user check out Ion Auth v2.
I had the same problem before, what I ended up doing was building relation tables to handle different groups with different fields. Then I modified the profile() code a bit, to join the additional relation table according to the user's group settings.
I would start off building a relational database.
example:
**volunteers table**
id
user_id
languages
**organizations table**
id
user_id
mission
Then depending on user group, join the table in profile() function.
Hope this helps!