add login type for auth,add list baseResponse
This commit is contained in:
@@ -4,6 +4,9 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace YYApi.Communications
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础相应
|
||||
/// </summary>
|
||||
public class BaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
@@ -37,6 +40,7 @@ namespace YYApi.Communications
|
||||
SetCode(200);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 返回指定代码的描述
|
||||
/// </summary>
|
||||
@@ -94,4 +98,16 @@ namespace YYApi.Communications
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态内容
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class BaseResponse<T> : BaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态内容
|
||||
/// </summary>
|
||||
public T Data { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace YYApi.Controllers
|
||||
/// <summary>
|
||||
/// 当前登录用户的ID
|
||||
/// </summary>
|
||||
protected int LoginId => HttpContext.Items["LoginId"] == null ? 0 : int.Parse(HttpContext.Items["LoginId"].ToString());
|
||||
protected LoginInfoItem LoginInfo => (LoginInfoItem)HttpContext.Items["LoginInfo"];
|
||||
|
||||
/// <summary>
|
||||
/// 验证请求参数
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
@@ -28,10 +29,10 @@ namespace YYApi.Helpers
|
||||
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
var id = cache.GetString(token);
|
||||
if (id != null)
|
||||
var login = cache.GetString(token);
|
||||
if (login != null)
|
||||
{
|
||||
httpContext.Items.Add("LoginId", id);
|
||||
httpContext.Items.Add("LoginInfo", JsonSerializer.Deserialize<LoginInfoItem>(login));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +40,17 @@ namespace YYApi.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录信息中间件
|
||||
/// </summary>
|
||||
public class LoginInfoItem
|
||||
{
|
||||
//登录用户的ID
|
||||
public int Id { get; set; }
|
||||
//登录用户来源
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测登录中间件
|
||||
/// </summary>
|
||||
@@ -70,10 +82,15 @@ namespace YYApi.Helpers
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public string SetId(int id)
|
||||
public string SetId(int id, string type = "user")
|
||||
{
|
||||
var uuid = GetUUID();
|
||||
Cache.SetString(uuid, id.ToString());
|
||||
var loginItem = new LoginInfoItem
|
||||
{
|
||||
Id = id,
|
||||
Type = type
|
||||
};
|
||||
Cache.SetString(uuid, JsonSerializer.Serialize(loginItem));
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -4,14 +4,13 @@
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<PackOnBuild>true</PackOnBuild>
|
||||
<Version>0.1.0</Version>
|
||||
<Version>0.1.3</Version>
|
||||
<Authors>xRain@YYTech</Authors>
|
||||
<Description>AspNetCore一个方便的API文档,捕获异常,统一输入输出的API类库</Description>
|
||||
<PackageId>YY-Tech.YYApi</PackageId>
|
||||
<IsPackable>true</IsPackable>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<PackageVersion>0.1.2</PackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user