1. 程式人生 > >RBAC許可權框架_MVC許可權框架

RBAC許可權框架_MVC許可權框架

RBAC許可權框架(Role-Based Access Control)基於角色的許可權訪問控制的框架,通過使用者-角色-許可權的關聯,非常方便的進行許可權管理,在這裡不再說明什麼是RBAC,請自行百度.

謝謝大家的捧場,如文章中有錯誤或者,請聯絡我或者給我發郵件[email protected],修正後將會有小禮品送出,謝謝

思路

小張、小王、小李要去動物園看動物,小張和小王提前在網上買好票了,小李沒買到票。

三人到了動物園公共展區,這裡不需要驗票,三人可以看這一片的動物(允許匿名訪問)。

繼續向前走,到了特別展區,需要驗證門票,小張和小王有門票順利的進入特別展區,小李被攔了下來(身份認證)。

小李不甘心啊,找了個角落,偷偷FQ景區,結果被景區人員抓了被帶到了警察局進行教育(非法訪問)。

小王在特別展區嫌慢,自己偷偷一不小心走到沒有許可權的地方而被抓。

 

相對關係

 

許可權:許可權是指是否允許可被訪問(被檢視)和被使用的一種手段,通常設計具有上下級的關係,在本文中用的是樹形結構。

使用者:該作業系統的使用者,通過這個作業系統來完成某部分的工作生活。

角色:對使用者的一種分類,對許可權的一中整理,比如:普通員工有普通員工的許可權,經理又經理 的許可權。

在實際生活中,一個人有多個身份,比如,爸爸媽媽的孩子,孩子的父母,上班的職工等等。而一個公司的普通員工就有很多人。so,使用者和角色是多對多的關係。

而一個角色,也可能有多個許可權。比如,一個醫生除了治病救人之外,也可以醫療護理。一個警察在打擊犯罪的同時,也可以根據法律法規幫助別人。

而一個許可權,可能是多個角色擁有的。一個警察在打擊犯罪,普通市民也可以參與。往往一件事的事情(類比於一個許可權),會有多個角色的參與。

所以,角色和許可權也是多對多的關係

 

資料庫設計

因為是RBAC,所以肯定有使用者、角色、許可權,使用者和角色是多對多的關係,角色和許可權是多對多的關係。所以,需要有使用者表、使用者角色關聯表、角色表、角色許可權關聯表、許可權表。

使用者表:使用者程式碼、使用者名稱、密碼。

角色表:角色程式碼、角色名稱。

使用者角色關聯表:使用者程式碼、角色程式碼。

許可權表:許可權程式碼、許可權名稱、連結地址、父級許可權程式碼。

角色許可權關聯表:角色程式碼、許可權程式碼。

這些已經是基礎的表,往往生活工作中會比這複雜多了。在有的時候,還需要特殊使用者許可權關聯管理表。

程式的設計

根據需求,管理員可以管理許可權和維護使用者資訊等,使用者可以實現自己的任務需求。

那麼,最基礎的是獲取許可權和判斷是否有相應的許可權,在頁面上展示相應 的功能呢以及在操作的時候判斷有木有操作的許可權。

比如管理員登陸,可以新增角色使用者許可權等。而使用者登入,能夠管理商品,訂單的資訊等。

環境

使用vs2015,sql server2017程式設計,Win10 Home x64系統軟體,相容IE8,IE9,IE10,谷歌瀏覽器等,使用PowerDesigner建模,等等

框架技術

整體框架使用了MVC+多層,頁面使用了MiniUI框架,考慮到使用者量不是很多,使用了Code First。

Code

由於保密條例,不展示業務部分,只有許可權

* 獲取許可權,使用者登入後,根據使用者所屬的角色資訊獲取相應的許可權。

* 判斷是否有許可權,在使用者進行操作前判斷是否有許可權

實現

*登入: 使用者開啟網站時,首先判斷當前頁面不允許匿名訪問,判斷Session是否有使用者會話資訊,存在則載入使用者資訊,不存在讀取Cookie,Cookie有登入資訊並且沒有過期,這載入使用者資訊,否者跳轉登入頁面

  登入成功之後或者載入完使用者資訊之後,獲取許可權列表,顯示對應的模組

* 操作: 當用戶點選功能後或者在位址列裡輸入地址訪問,首先通過面向切面程式設計的思路,使用動作過濾器或者許可權過濾器判斷是否有對應的許可權,有許可權就允許操作,沒有許可權則視為無效操作或者非法操作

   無效操作: 返回上一頁或者上一步

  非法操作: 清空登入資訊,清空Session,釋放Cookie,跳轉到非法訪問警告頁面,3秒後跳轉到登入頁面

----------------  Common  ----------------

 1  public class UserPermissionFilter:System.Web.Mvc.ActionFilterAttribute
 2     {
 3         public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
 4         {
 5             #region 判斷是否有 此 controller 和 action 的許可權
 6             LoginUserViewModel user = AdminUserBll.GetLoginUser();
 7             var permissionListAll = ModuleBll.Instance.GetLevelModuleListIsArrayAllInCache();
 8             if (null != user && !string.IsNullOrEmpty(user.user_name))
 9             {
10                 bool ret = true;
11                 if (user.PermissionList != null && user.PermissionList.Count > 0)
12                 {
13                     string action = filterContext.ActionDescriptor.ActionName;
14                     string controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
15                     string url = (controller + "/" + action).ToUpper();
16                     var module = permissionListAll.FirstOrDefault(c => c.action_url.ToUpper() == url);
17                     if ((controller.ToUpper() != "HOME" && action.ToUpper() != "LOGIN") &&
18                         controller.ToUpper() != "MENU" && module != null) /*此Action下的不作許可權*/
19                                                          //&& module != null
20                     {
21                         ret = AdminUserBll.LoginUserIsPermission(controller, action, user);
22                     }
23                     if (!ret)
24                     {
25                         filterContext.HttpContext.Response.Redirect("/Home/NoRight", true);
26                         //throw new System.Web.HttpException(403, "無權訪問");
27                     }
28                 }
29             }
30             else
31             {
32                 filterContext.HttpContext.Response.Redirect("/login", true);
33 
34             }
35 
36 
37             #endregion
38 
39             base.OnActionExecuting(filterContext);
40         }
41     }
判讀是否有操作許可權
1         /// <summary>
2         /// 獲取全部一維的模組View列表,在快取中
3         /// </summary>
4         /// <returns></returns>
5         public List<LevelModuleViewModel> GetLevelModuleListIsArrayAllInCache()
6         {
7             return SystemCacheManager.GetCache("ModuleBll_GetLevelModuleListIsArrayAllInCache", 60, GetLevelMudleListIsArrayAll);
8         }
在快取中獲取模組列表
 1 public static class SystemCacheManager
 2     {
 3         /// <summary>
 4         /// 
 5         /// </summary>
 6         /// <param name="key"></param>
 7         /// <param name="timeOut"></param>
 8         /// <param name="function"></param>
 9         /// <returns></returns>
10         public static T GetCache<T>(string key, int timeOut, Func<T> function)
11         {
12             if (string.IsNullOrEmpty(key)) return default(T);
13             var configs = HttpContext.Current.Cache[key];
14             if (configs == null)
15             {
16                 configs = function();
17                 if (timeOut > -1)
18                 {
19                     HttpContext.Current.Cache.Insert(key, configs,
20                                                 null, DateTime.Now.AddSeconds(timeOut),
21                                                 System.Web.Caching.Cache.NoSlidingExpiration);
22                 }
23                 else
24                 {
25                     HttpContext.Current.Cache.Insert(key, configs);
26                 }
27                 return (T)configs;
28             }
29             return (T)configs;
30         }
31 
32 
33         /// <summary>
34         /// 
35         /// </summary>
36         /// <param name="key"></param>
37         /// <param name="timeOut"></param>
38         /// <param name="function"></param>
39         /// <returns></returns>
40         public static T GetCache<T,Z>(string key, int timeOut, Func<Z,T> function,Z u1)
41         {
42             if (string.IsNullOrEmpty(key)) return default(T);
43             var configs = HttpContext.Current.Cache[key];
44             if (configs == null)
45             {
46                 configs = function(u1);
47                 if (timeOut > -1)
48                 {
49                     HttpContext.Current.Cache.Insert(key, configs,
50                                                 null, DateTime.Now.AddSeconds(timeOut),
51                                                 System.Web.Caching.Cache.NoSlidingExpiration);
52                 }
53                 else
54                 {
55                     HttpContext.Current.Cache.Insert(key, configs);
56                 }
57                 return (T)configs;
58             }
59             return (T)configs;
60         }
61     }
獲取快取資料
 /// <summary>
        /// 判斷登入使用者對請求是否有許可權
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="action"></param>
        /// <param name="login"></param>
        /// <returns></returns>
        public static bool LoginUserIsPermission(string controller, string action, LoginUserViewModel login)
        {
            if (login.PermissionList != null && login.PermissionList.Count > 0)
            {
                string strUrl = controller + "/" + action;
                if (login.PermissionList.FirstOrDefault(c => c.action_url.ToUpper() == strUrl.ToUpper()) != null)
                {
                    return true;
                }
            }
            return false;
        }
判斷使用者對當前請求是否有操作許可權

 

 1 /// <summary>
 2         /// 獲取登入使用者
 3         /// </summary>
 4         /// <returns></returns>
 5         public static LoginUserViewModel GetLoginUser()
 6         {
 7             if (System.Web.HttpContext.Current.Session["LoginUser"] != null)
 8             {
 9                 return (LoginUserViewModel)System.Web.HttpContext.Current.Session["LoginUser"];
10             }
11             else
12             {
13                 string userName = Library.Web.Cookie.CookieManager.GetCookie(userCookieKey);
14                 if (!string.IsNullOrEmpty(userName))
15                 {
16                     userName = StringDes.DesDecrypt(userName);
17                     AdminUserDb user = Instance.GetModel(userName);
18                     if (user != null)
19                     {
20                         LoginUserViewModel view = Instance.IniLogin(user);
21                         return view;
22                     }
23                 }
24             }
25             return new LoginUserViewModel();
26         }
在Session和Cookie中獲取登入使用者
public ActionResult Login(string loginName, string passWord)
        {

            ViewBag.LoginName = loginName;
            ViewBag.PassWord = passWord;
            ViewBag.ErrorMessage = "";
            string md5PassWord = Library.Tools.Text.StringMd5.Md5Hash32Salt(passWord);
            AdminUserDb user = AdminUserBll.Instance.GetModel(loginName);
            if (user != null)
            {
                if (user.pass_word.ToUpper() == md5PassWord.ToUpper()&&user.user_status==1)
                {
                    user.last_lgoin_date = DateTime.Now;
                    user.last_login_ip = Request.UserHostAddress;
                    AdminUserBll.Instance.IniLogin(user);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ViewBag.errorMessage = "使用者密碼錯誤";
                }
            }
            else
            {
                ViewBag.errorMessage = "使用者密碼錯誤";
            }
            return View();
        }
使用者登入
 1         /// <summary>
 2         /// 獲取指定使用者名稱的使用者
 3         /// </summary>
 4         /// <param name="userName"></param>
 5         /// <returns></returns>
 6         public AdminUserDb GetModel(string userName)
 7         {
 8 
 9             return PermissionDal.GetModel(c => c.user_name == userName);
10 
11         }
獲取使用者資訊
 1         /// <summary>
 2         /// 初始化登入使用者
 3         /// </summary>
 4         /// <param name="user">登入使用者</param>
 5         /// <returns></returns>
 6         public LoginUserViewModel IniLogin(AdminUserDb user)
 7         {
 8             if (user != null)
 9             {
10                 LoginUserViewModel loginUserViewModel = new LoginUserViewModel();
11                 loginUserViewModel.user_full_name = user.user_full_name;
12                 loginUserViewModel.user_name = user.user_name;
13                 List<ModuleDb> moduleDbList = ModuleBll.Instance.GetModuleList(user.user_name).ToList();
14                 if (moduleDbList != null && moduleDbList.Count > 0)
15                 {
16                     loginUserViewModel.PermissionList = moduleDbList;
17                     loginUserViewModel.PermissionListLevel = ModuleBll.Instance.IniLevelModuleList(moduleDbList);
18                 }
19                 UpdateUserLogin(user);
20                 System.Web.HttpContext.Current.Session["LoginUser"] = loginUserViewModel;
21                 Library.Web.Cookie.CookieManager.SetCookie(userCookieKey, StringDes.DesEncrypt(loginUserViewModel.user_name));
22                 return loginUserViewModel;
23             }
24             return new LoginUserViewModel();
25         }
初始化使用者資訊

 

  1 --CREATE DATABASE center 
  2 --USE center
  3 --GO 
  4 CREATE TABLE [dbo].[admin_user](
  5     [user_name] [nvarchar](50) PRIMARY KEY NOT NULL,
  6     [pass_word] [nvarchar](100) NOT NULL,
  7     [user_full_name] [nvarchar](100) NULL,
  8     [user_status] [int] NOT NULL,
  9     [last_lgoin_date] [datetime] NULL,
 10     [last_login_ip] [nvarchar](255) NULL,
 11     [creator_name] [nvarchar](50) NOT NULL,
 12     [creator_date] [datetime] NOT NULL,
 13     [modifi_name] [nvarchar](50) NULL,
 14     [modifi_date] [datetime] NULL,
 15     [user_img] [varchar](max) NULL
 16 )
 17 GO
 18 
 19 CREATE TABLE [dbo].[admin_user_role_relation](
 20     [id] [INT] PRIMARY KEY IDENTITY(1,1) NOT NULL,
 21     [user_name] [nvarchar](50) NOT NULL,
 22     [role_id] [int] NOT NULL,
 23     [creator_name] [nvarchar](50) NOT NULL,
 24     [creator_date] [datetime] NOT NULL
 25 )
 26 GO
 27 
 28 CREATE TABLE [dbo].[dictionary_table](
 29     [dt_key] [nvarchar](100) PRIMARY KEY NOT NULL,
 30     [dt_type_key] [nvarchar](100) NOT NULL,
 31     [dt_name] [nvarchar](100) NOT NULL,
 32     [dt_status] [int] NOT NULL,
 33     [dt_orderby] [decimal](18, 2) NOT NULL,
 34     [creator_name] [nvarchar](50) NOT NULL,
 35     [creator_date] [datetime] NOT NULL,
 36     [modifi_name] [nvarchar](50) NULL,
 37     [modifi_date] [datetime] NULL
 38 )
 39 GO
 40 
 41 CREATE TABLE [dbo].[dictionary_type_table](
 42     [dt_type_key] [nvarchar](100) PRIMARY KEY NOT NULL,
 43     [dt_type_name] [nvarchar](100) NOT NULL,
 44     [dt_type_remark] [nvarchar](200) NULL,
 45     [dt_type_orderby] [decimal](18, 0) NOT NULL,
 46     [creator_name] [nvarchar](50) NOT NULL,
 47     [creator_date] [datetime] NOT NULL,
 48     [modifi_name] [nvarchar](50) NULL,
 49     [modifi_date] [datetime] NULL
 50 )
 51 GO
 52 
 53 CREATE TABLE [dbo].[module_db](
 54     [module_code] [nvarchar](50) PRIMARY KEY NOT NULL,
 55     [module_name] [nvarchar](100) NOT NULL,
 56     [parent_code] [nvarchar](50) NOT NULL,
 57     [module_level] [int] NOT NULL,
 58     [is_menu] [int] NOT NULL,
 59     [is_action] [int] NOT NULL,
 60     [action_url] [nvarchar](500) NULL,
 61     [order_by] [decimal](10, 0) NOT NULL,
 62     [module_status] [int] NOT NULL,
 63     [creator_name] [nvarchar](50) NOT NULL,
 64     [creator_date] [datetime] NOT NULL,
 65     [modifi_name] [nvarchar](50) NULL,
 66     [modifi_date] [datetime] NULL
 67 )
 68 GO
 69 
 70 CREATE TABLE [dbo].[role_db](
 71     [role_id] [INT] PRIMARY KEY IDENTITY(1,1) NOT NULL,
 72     [role_name] [nvarchar](50) NOT NULL,
 73     [role_status] [int] NOT NULL,
 74     [creator_name] [nvarchar](50) NOT NULL,
 75     [creator_date] [datetime] NOT NULL,
 76     [modifi_name] [nvarchar](50) NULL,
 77     [modifi_date] [datetime] NULL
 78 )
 79 GO
 80 
 81 CREATE TABLE [dbo].[role_module_relation](
 82     [id] [INT] PRIMARY KEY IDENTITY(1,1) NOT NULL,
 83     [role_id] [int] NOT NULL,
 84     [module_code] [nvarchar](255) NOT NULL,
 85     [creator_name] [nvarchar](50) NOT NULL,
 86     [creator_date] [datetime] NOT NULL
 87 )
 88 GO
 89 INSERT [dbo].[admin_user] ([user_name], [pass_word], [user_full_name], [user_status], [last_lgoin_date], [last_login_ip], [creator_name], [creator_date], [modifi_name], [modifi_date], [user_img]) VALUES (N'adm', N'dc2e86a6ae8315a3da26cae880baae8e', N'adm', 1, NULL, NULL, N'admin', CAST(N'2019-05-28T12:44:12.380' AS DateTime), NULL, NULL, NULL)
 90 INSERT [dbo].[admin_user] ([user_name], [pass_word], [user_full_name], [user_status], [last_lgoin_date], [last_login_ip], [creator_name], [creator_date], [modifi_name], [modifi_date], [user_img]) VALUES (N'admin', N'dc2e86a6ae8315a3da26cae880baae8e', N'管理員', 1, CAST(N'2019-05-28T14:48:15.503' AS DateTime), N'::1', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), NULL, NULL, NULL)
 91 INSERT [dbo].[admin_user] ([user_name], [pass_word], [user_full_name], [user_status], [last_lgoin_date], [last_login_ip], [creator_name], [creator_date], [modifi_name], [modifi_date], [user_img]) VALUES (N'test', N'dc2e86a6ae8315a3da26cae880baae8e', N'測試賬戶', 1, CAST(N'2019-05-21T11:29:30.137' AS DateTime), N'::1', N'admin', CAST(N'2019-05-05T14:02:23.687' AS DateTime), NULL, NULL, NULL)
 92 SET IDENTITY_INSERT [dbo].[admin_user_role_relation] ON 
 93 
 94 INSERT [dbo].[admin_user_role_relation] ([id], [user_name], [role_id], [creator_name], [creator_date]) VALUES (40, N'admin', 2, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
 95 INSERT [dbo].[admin_user_role_relation] ([id], [user_name], [role_id], [creator_name], [creator_date]) VALUES (120, N'admin', 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
 96 INSERT [dbo].[admin_user_role_relation] ([id], [user_name], [role_id], [creator_name], [creator_date]) VALUES (123, N'test', 2, N'admin', CAST(N'2019-05-05T14:02:23.687' AS DateTime))
 97 INSERT [dbo].[admin_user_role_relation] ([id], [user_name], [role_id], [creator_name], [creator_date]) VALUES (124, N'adm', 1, N'admin', CAST(N'2019-05-28T12:44:12.380' AS DateTime))
 98 INSERT [dbo].[admin_user_role_relation] ([id], [user_name], [role_id], [creator_name], [creator_date]) VALUES (125, N'adm', 2, N'admin', CAST(N'2019-05-28T12:44:12.380' AS DateTime))
 99 SET IDENTITY_INSERT [dbo].[admin_user_role_relation] OFF
100 INSERT [dbo].[dictionary_table] ([dt_key], [dt_type_key], [dt_name], [dt_status], [dt_orderby], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-sex-false', N'fa-sex', N'女', 1, CAST(1.00 AS Decimal(18, 2)), N'admin', CAST(N'2019-05-07T13:51:17.207' AS DateTime), NULL, NULL)
101 INSERT [dbo].[dictionary_table] ([dt_key], [dt_type_key], [dt_name], [dt_status], [dt_orderby], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-sex-true', N'fa-sex', N'男', 1, CAST(0.00 AS Decimal(18, 2)), N'admin', CAST(N'2019-05-07T13:50:48.100' AS DateTime), NULL, NULL)
102 INSERT [dbo].[dictionary_type_table] ([dt_type_key], [dt_type_name], [dt_type_remark], [dt_type_orderby], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-sex', N'性別', N'性別', CAST(0 AS Decimal(18, 0)), N'admin', CAST(N'2019-05-07T13:49:48.733' AS DateTime), NULL, NULL)
103 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-book', N'字典管理', N'fa-puzzle-piece', 3, 1, 1, N'DictionaryManager/List', CAST(0 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), NULL, NULL)
104 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-desktop', N'系統管理', N'yixin_public', 2, 1, 2, N'', CAST(0 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
105 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-graduation-cap', N'模組選單管理', N'fa-desktop', 3, 1, 1, N'ModuleManager/list', CAST(3 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
106 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-paw', N'角色管理', N'fa-desktop', 3, 1, 1, N'rolemanager/list', CAST(1 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), NULL, NULL)
107 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-puzzle-piece', N'配置管理', N'yixin_public', 2, 1, 2, N'', CAST(2 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), NULL, NULL)
108 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-th-list', N'字典類別管理', N'fa-puzzle-piece', 3, 1, 1, N'DictionaryTypeManager/List', CAST(1 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
109 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'fa-user', N'使用者管理', N'fa-desktop', 3, 1, 1, N'AdminUserManager/list', CAST(3 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), NULL, NULL)
110 INSERT [dbo].[module_db] ([module_code], [module_name], [parent_code], [module_level], [is_menu], [is_action], [action_url], [order_by], [module_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (N'yixin_public', N'XX公共平臺', N'', 1, 1, 2, N'', CAST(0 AS Decimal(10, 0)), 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), N'admin', NULL)
111 SET IDENTITY_INSERT [dbo].[role_db] ON 
112 
113 INSERT [dbo].[role_db] ([role_id], [role_name], [role_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (1, N'管理員', 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
114 INSERT [dbo].[role_db] ([role_id], [role_name], [role_status], [creator_name], [creator_date], [modifi_name], [modifi_date]) VALUES (2, N'使用者', 1, N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime), N'admin', CAST(N'2019-05-21T11:29:05.307' AS DateTime))
115 SET IDENTITY_INSERT [dbo].[role_db] OFF
116 SET IDENTITY_INSERT [dbo].[role_module_relation] ON 
117 
118 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (127, 1, N'yixin_public', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
119 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (128, 1, N'fa-desktop', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
120 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (131, 1, N'fa-puzzle-piece', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
121 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (132, 1, N'fa-paw', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
122 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (133, 1, N'fa-graduation-cap', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
123 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (134, 1, N'fa-user', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
124 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (135, 1, N'fa-th-list', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
125 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (136, 1, N'fa-book', N'admin', CAST(N'2019-05-01T00:00:00.000' AS DateTime))
126 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (1226, 2, N'yixin_public', N'admin', CAST(N'2019-05-21T11:29:05.307' AS DateTime))
127 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (1227, 2, N'afghfeat', N'admin', CAST(N'2019-05-21T11:29:05.307' AS DateTime))
128 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (1228, 2, N'fa-puzzle-piece', N'admin', CAST(N'2019-05-21T11:29:05.307' AS DateTime))
129 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (1229, 2, N'fa-book', N'admin', CAST(N'2019-05-21T11:29:05.307' AS DateTime))
130 INSERT [dbo].[role_module_relation] ([id], [role_id], [module_code], [creator_name], [creator_date]) VALUES (1230, 2, N'fa-th-list', N'admin', CAST(N'2019-05-21T11:29:05.307' AS DateTime))
131 SET IDENTITY_INSERT [dbo].[role_module_relation] OFF
132 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'使用者名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'user_name'
133 GO
134 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'使用者密碼 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'pass_word'
135 GO
136 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'使用者全名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'user_full_name'
137 GO
138 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'使用者狀態 1:有效  2:無效' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'user_status'
139 GO
140 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最後登入日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'last_lgoin_date'
141 GO
142 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最後登入ip' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'last_login_ip'
143 GO
144 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立人登入名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'creator_name'
145 GO
146 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'creator_date'
147 GO
148 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改人登入名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'modifi_name'
149 GO
150 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user', @level2type=N'COLUMN',@level2name=N'modifi_date'
151 GO
152 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立人登入名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user_role_relation', @level2type=N'COLUMN',@level2name=N'creator_name'
153 GO
154 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立時間' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'admin_user_role_relation', @level2type=N'COLUMN',@level2name=N'creator_date'
155 GO
156 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典key' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'dt_key'
157 GO
158 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典類別key' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'dt_type_key'
159 GO
160 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'dt_name'
161 GO
162 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典狀態 1:有效  2:無效' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'dt_status'
163 GO
164 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'排序欄位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'dt_orderby'
165 GO
166 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立人登陸名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'creator_name'
167 GO
168 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'creator_date'
169 GO
170 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改人登入名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'modifi_name'
171 GO
172 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_table', @level2type=N'COLUMN',@level2name=N'modifi_date'
173 GO
174 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典類別' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'dt_type_key'
175 GO
176 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典類別名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'dt_type_name'
177 GO
178 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'字典類別備註' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'dt_type_remark'
179 GO
180 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'creator_name'
181 GO
182 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立時間' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'creator_date'
183 GO
184 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'modifi_name'
185 GO
186 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改時間' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'dictionary_type_table', @level2type=N'COLUMN',@level2name=N'modifi_date'
187 GO
188 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'模組code' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'module_code'
189 GO
190 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'模組名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'module_name'
191 GO
192 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'父模組code' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'parent_code'
193 GO
194 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'模組級別' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'module_level'
195 GO
196 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否是選單  1:選單   2:不是選單' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'is_menu'
197 GO
198 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否是選單  1:請求   2:不是選單' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'is_action'
199 GO
200 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'請求url' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'action_url'
201 GO
202 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'排序欄位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'order_by'
203 GO
204 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'模組狀態  1:有效  2:無效' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'module_status'
205 GO
206 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立人使用者名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'creator_name'
207 GO
208 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'creator_date'
209 GO
210 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改使用者名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'modifi_name'
211 GO
212 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'module_db', @level2type=N'COLUMN',@level2name=N'modifi_date'
213 GO
214 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'角色id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'role_module_relation', @level2type=N'COLUMN',@level2name=N'role_id'
215 GO
216 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'模組code' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'role_module_relation', @level2type=N'COLUMN',@level2name=N'module_code'
217 GO
218 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立使用者名稱' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'role_module_relation', @level2type=N'COLUMN',@level2name=N'creator_name'
219 GO
220 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'建立時間' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'role_module_relation', @level2type=N'COLUMN',@level2name=N'creator_date'
221 GO
資料庫程式碼

原始碼 : https://github.com/linjierd/Jurisdiction

[僅限於下載學習,不允許用於商業用途]