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