Recently, when I was reading an Asp.net book (written by Chinese people), I mentioned a small example of simple permission. I think it is clear and representative,
Therefore, the implementation principle is briefly introduced here.
Its core is to establish the relationship between users, roles, functions, and module functions. The database design is as follows:
1. User Role table
User table
Field: userid auto-incrementing Field
Username
Password
Roletable (role table)
Field
Roleid auto-incrementing Field
Rolename
User Role table userrole
Field
Userroleid (auto-incrementing field)
Userid
Roleid
User tables and role tables are associated through the user role table. The relationship between users and roles is many-to-many.
2 Role permission table roleright
Field
rolerightid auto-incrementing field
roleid
modulefunctionid
here, we will parse it. For example, the user Tom has an administrator role (assuming that the role is in the roletable table, if the next record
roleid rolename
2 Admin
appears in the roleright table, there are records in the following form
rolerightid roleid modulefunctionid
1 2 10
2 2 11
That is to say, roleid = 2 administrator role, with moduleidfunctionid = 10 and 11 Permissions
Next, let's look at it.
3. module table)
Field
Moduleid modulename URL
1. Student profile XXXXX
2. Instructor profile xxxxxxx
4 modulefunction table (module-menu)
Field
Modulefunctionid moduleid functionid
.....................
10 1 1
11 1 2
5 function table (menu)
Field
Functionid functioname
1 add
2 update
3 Delete
4 search
You can see that the Administrator has 10 or 11 permissions, which can be found in the modulefunction table, that is, in the moduleid = 1 (student profile) module, there are two types
What is the executable function? You can check functionid. The ADD and update functions are available.
The advantage is that "modules", "functions", "groups", and "people" can be added at will without affecting each other. You can grant permissions directly to each user, assign permissions to a type of user, and grant permissions to the role.
But in fact, it is generally not necessary to set up a function table to grant these permissions, and crud will be used in both the following steps.