add mutil role

This commit is contained in:
2020-02-18 08:07:51 +08:00
parent 116dd1a808
commit 9b38ee9b39
3 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ namespace YYApi.Attributes
throw new YYApiException(401); throw new YYApiException(401);
} }
//检测用户类型 //检测用户类型
if (!Types.Contains(loginInfo.Type)) if (Types.Intersect(loginInfo.Type).Count() == 0)
{ {
throw new YYApiException(403); throw new YYApiException(403);
} }
+1 -1
View File
@@ -9,6 +9,6 @@ namespace YYApi.Communications
//登录用户的ID //登录用户的ID
public int Id { get; set; } public int Id { get; set; }
//登录用户来源 //登录用户来源
public string Type { get; set; } public string[] Type { get; set; }
} }
} }
+11
View File
@@ -24,6 +24,17 @@ namespace YYApi.Helpers
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
public string Set(int id, string type = "user") public string Set(int id, string type = "user")
{
return Set(id, new[] { type });
}
/// <summary>
/// 产生一个TOken并记录用户ID角色[多角色]
/// </summary>
/// <param name="id"></param>
/// <param name="type"></param>
/// <returns></returns>
public string Set(int id, string[] type)
{ {
var uuid = Guid.NewGuid().ToString(); var uuid = Guid.NewGuid().ToString();
var loginItem = new YYLoginItem var loginItem = new YYLoginItem