From 9b38ee9b39145e24d07cbe7e2d61206ab0195ce8 Mon Sep 17 00:00:00 2001 From: xRain Date: Tue, 18 Feb 2020 08:07:51 +0800 Subject: [PATCH] add mutil role --- Attributes/YYAuthAttribute.cs | 2 +- Communications/YYLoginItem.cs | 2 +- Helpers/YYAuth.cs | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Attributes/YYAuthAttribute.cs b/Attributes/YYAuthAttribute.cs index 08752b2..7307aa3 100644 --- a/Attributes/YYAuthAttribute.cs +++ b/Attributes/YYAuthAttribute.cs @@ -41,7 +41,7 @@ namespace YYApi.Attributes throw new YYApiException(401); } //检测用户类型 - if (!Types.Contains(loginInfo.Type)) + if (Types.Intersect(loginInfo.Type).Count() == 0) { throw new YYApiException(403); } diff --git a/Communications/YYLoginItem.cs b/Communications/YYLoginItem.cs index 44a7883..0923526 100644 --- a/Communications/YYLoginItem.cs +++ b/Communications/YYLoginItem.cs @@ -9,6 +9,6 @@ namespace YYApi.Communications //登录用户的ID public int Id { get; set; } //登录用户来源 - public string Type { get; set; } + public string[] Type { get; set; } } } diff --git a/Helpers/YYAuth.cs b/Helpers/YYAuth.cs index efd9a9e..b8b1bad 100644 --- a/Helpers/YYAuth.cs +++ b/Helpers/YYAuth.cs @@ -24,6 +24,17 @@ namespace YYApi.Helpers /// /// public string Set(int id, string type = "user") + { + return Set(id, new[] { type }); + } + + /// + /// 产生一个TOken并记录用户ID角色[多角色] + /// + /// + /// + /// + public string Set(int id, string[] type) { var uuid = Guid.NewGuid().ToString(); var loginItem = new YYLoginItem