Open source a set of universal background framework developed based on ASP.Net Core

Write in front

This is the framework for me to build in the learning process. It would be great if it helps you. If you find an error, please let me know and I will correct it as soon as possible. Knowing the reason, knowing the reason, is not repetitive making the wheel. Because during this period of time, I found that the code I wrote for a long time, and then I look at other people's code, it will feel like a sudden realization. It's not only used, and I don't know why it is used in this way. Really, I just can't knock, I can't always learn.

Demo address:  http://app.guoddy.com  Source code address:  https://github.com/jellydong/LJDAPP The  data will not be saved in real life. The test mode is set, so login is not required.

development tools

1.Visual Studio 2019 2.SQL Server 2017 3.Power Design

Overall effect

Homepage

 

Menu management

) Role management and permission configuration

 

 

Permission Design & Why

 

 

I mainly involve seven tables, four data tables, and three association tables here. Why is it designed like this? I think it may be the requirement of most systems. 1. There are many-to-many users and roles. A user can have multiple roles. Otherwise, the design of roles will be meaningless. In fact, there may be multiple roles for one person. 2. You can directly grant or cancel a certain authority to the user. Some people may think this is unnecessary, so if this is not involved, there are five tables. But I keep it here, because in many cases, this is a normal demand. 3. The menu can have unlimited levels, and the system configuration parameters can be modified according to actual needs.

Detailed description

ObjectID, Remark, Status, CreatedBy, CreatedTime, ModifiedBy, ModifiedTime, SortIt is the default field.

SysUserInfo user table

  • If the user data is large, then, this table actually only need to retain ObjectID, ULoginName, ULoginPWDon it, so can improve the speed, no need to put all the information stored.
  • Many-to-many users and roles R_sysUserInfo_sysRole
  • Many to many users and permission items (direct authorization or prohibition) R_UserPermissions

| Name | Description | Type | Primary Key | | -------------| ------------- | ------------ -| ------------- |
|ObjectID |Primary Key|nvarchar(50)|TRUE| |ULoginName | Username| nvarchar(20)| | |ULoginPWD | Password| nvarchar(50) | | |URealName | Real Name| nvarchar(10) | | |UTelphone | Phone| nvarchar(20) | | |UMobile | Mobile Number| nvarchar(11) | | |UEmail | Email | nvarchar(50) | | |UQQ | QQ | nvarchar(20) | | |UGender| Gender:0-Female;1-Male;2-Confidential | int | | |UDepID | Department| nvarchar(50) | | |Remark | Remarks| nvarchar(500) | | |Status | Status: 0-enabled; 1-disabled | int | | |CreatedBy | Created by | nvarchar(50) | | |CreatedTime| Created time | datetime | | |ModifiedBy | Modified by | nvarchar(50) | | |ModifiedTime | Modified Time | datetime | | |Sort | Sort value | int| |

SysRole role table

  • Classification of roles, such as administrators, ordinary users, etc.
  • Role user many-to-many R_sysUserInfo_sysRole
  • Role permissions many-to-many R_RolePermission

| Name | Description | Type | Primary Key | | -------------| ------------- | ------------ -| ------------- |
| ObjectID| Primary Key| nvarchar(50)| TRUE| | RName| Role Name| varchar(50)| | | Remark| Remarks| nvarchar(500) | | | Status| Status: 0-enabled; 1-disabled | int | | | CreatedBy | Created by | nvarchar(50) || | CreatedTime| Created time | datetime| |
| ModifiedBy| Modified by | nvarchar(50) | | | ModifiedTime | Modified Time | datetime | | | Sort | Sort value | int | |

SysMenus menu table

  • The menu table is the one that has been changed the most after the initial design. The subsequent increase in the development process IsLast, ; HierarchyremovedMAction
  • IsLast is used to mark whether it is the last level. If it is the last level, we will automatically add default methods such as adding, deleting, and modifying.
  • Hierarchy is used to mark the level. We said earlier that it can be infinite, but usually it will be level three, so this needs to be set according to the actual system parameters, and the restrictions can be checked during maintenance.
  • Whether IsMenuShow is displayed as a menu, that is, the left menu is recursive, because some APIs do not need to be displayed as a menu, and the authorization method will be different.
  • Menu role many-to-many R_RolePermission
  • Menu permission items one-to-many

| Name | Description | Type | Primary Key | | -------------| ------------- | ------------ -| ------------- |
| ObjectID| Primary Key| nvarchar(50)| TRUE| | MName | Name| nvarchar(100)| | | MUrl| URL| nvarchar(100)| | | MArea| Area| nvarchar(100)| | | MController| Controller| nvarchar(100)| | | MIcon | Icon| nvarchar(100)| | | IsLast| Is it the last menu: 0-Yes; 1- No | int | | | IsMenuShow| Is it displayed as a menu: 0-Yes; 1-No| int | | | Remark| Remark| nvarchar(500)| | | ParentID | Parent ID | nvarchar(50)| | | Status | Status: 0-enabled; 1-disabled | int | | | Hierarchy| Hierarchy| int | | | CreatedBy | Created by | nvarchar(50)| | | CreatedTime| Created time| datetime| | | ModifiedBy| Modified by (50)| | | ModifiedTime| Modified Time| datetime| | | Sort| Sort value| int | |

SysFunction  menu button table  (menu permission item table)

  • At the beginning, I called the menu button table for SysFunction. I planned to control query, add, edit, delete, and other permissions, but later found that this was not good, so all were separated, and each method had to be recorded. Of course, for convenience, a common method will be automatically added when adding a menu.
  • The menu permission item menu is a many-to-one relationship

| Name | Description | Type | Primary Key | | -------------| ------------- | ------------ -| ------------- |
| ObjectID| Primary Key| nvarchar(50)| TRUE |
| FName| Name| nvarchar(50)| | | FFunction | Method | nvarchar(50)| | | FIcon| Icon| nvarchar(50) | | | ParentID| Owning Menu| nvarchar(50)| | | Remark| Remarks| nvarchar(500)| | | | CreatedBy | Created By| nvarchar(50)| | | CreatedTime | Created Time| datetime| | | ModifiedBy| Modified By| nvarchar(50)| | | ModifiedTime | Modified Time| datetime| | |

R_sysUserInfo_sysRole user and role association table, which records the correspondence between users and roles.

R_RolePermission Association table of role menu permission items.

For example, if a role has query and delete permissions under a certain menu, then this table should have two records.

R_UserPermissions User menu permission item association table.

HavePermission Record whether the user has permission: 0-no permission; 1-when there is permission for subsequent processing, the records that directly have no permission should be excluded from the permission records obtained, and the permission is added.

to sum up

In fact, there are many articles about permissions on the Internet. When I read it by myself before, I always felt confused, so I finally decided to do it myself. It was only when I was done that I understood it. I don’t know if what I described here is unclear or if the design is reasonable. If you think there is a problem, please let me know and I will correct it immediately! Don't look at the master and knock it with your hands. Like Power Design, it's the first time I use it, and it's the first time I use MarkDown to write a blog. This framework can quickly build applications, T4 template generates code, suitable for learning and use. If you have any questions, please contact me

Demo address:  http://app.guoddy.com  Source code address:  https://github.com/jellydong/LJDAPP The  data will not be saved in real life. The test mode is set, so login is not required.

Original address: https://zhuanlan.zhihu.com/p/83034152

Guess you like

Origin blog.csdn.net/weixin_56492685/article/details/115293943