Answer the question
In order to leave comments, you need to log in
Determining the type of user in the program. What database structure to choose?
Hello. There is a program with a single entry point, workstation. There is a tree-like structure of access to the functionality. Let's say an administrator can create users, users can write to the database, but cannot create other users.
First approach. The table of administrators and tables of users (different types) is created. When you enter a login/password pairing, matches are searched for in different tables and the user type is displayed depending on which table matches. Disadvantage if the user is in multiple groups.
Second. Store everything in one table, with a privileges field, if there are several privileges, offer to choose which one to enter.
Which method is better to choose or refuse and come up with another one? :(
Thank you very much.
Answer the question
In order to leave comments, you need to log in
there must be a table of groups and a table of users (+ their connection), one of the groups is the admins
The opinion of the student.
Choose the first option and check at the entrance (I will write in broken Delphi, because I don’t know what language you write in)
var
user:string; // создаём переменную типа string
...
begin
user:=username; //тут парсим никнейм и присваиваем к переменной
if user=table1 then begin //если нашли пользователя в первой таблице, тогда..
if user=table2 then begin //тогда проверяем есть ли он во второй таблице..
showmessage('Ты куда зайти хочешь, алло?'); // Спрашиваем у пользователя под какимими правами ему войти
end else begin // Если не находим то..
... // входим как пользователь первой таблицы
end;
end else begin // Тут проверяем в случае того, если не нашли пользователя в первой таблице
if user=table2 then begin // ну тут понятно
...// входим как пользователь второй таблицы
end else begin // А если и во второй не нашли то..
showmessage('Регистрироваться я за тебя должен, или как?');
end;
end;
Table with roles 'role':
id | parent_id | role
--+------------+--------
1 | NULL | quest
2 | 1 | user3
| 2 | admin
--+------------+--------
Role to user 'user_role_linker' mapping table:
---------+------ --
user_id | role_id
---------+--------
Examples:
https://github.com/bjyoungblood/BjyAuthorize
https://github.com/ZF-Commons/zfc-rbac/tree/ master/docs
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question