Compare commits

..
2 Commits
Author SHA1 Message Date
xrain e8d5496ef5 add login type for auth,add list baseResponse 2020-01-06 12:48:43 +08:00
xrain 3edb472bfb update base nuget package 2019-12-27 17:28:14 +08:00
5 changed files with 58 additions and 12 deletions
+16 -1
View File
@@ -1,10 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Newtonsoft.Json.Serialization;
namespace YYApi.Communications namespace YYApi.Communications
{ {
/// <summary>
/// 基础相应
/// </summary>
public class BaseResponse public class BaseResponse
{ {
/// <summary> /// <summary>
@@ -38,6 +40,7 @@ namespace YYApi.Communications
SetCode(200); SetCode(200);
} }
/// <summary> /// <summary>
/// 返回指定代码的描述 /// 返回指定代码的描述
/// </summary> /// </summary>
@@ -95,4 +98,16 @@ namespace YYApi.Communications
}); });
} }
} }
/// <summary>
/// 动态内容
/// </summary>
/// <typeparam name="T"></typeparam>
public class BaseResponse<T> : BaseResponse
{
/// <summary>
/// 动态内容
/// </summary>
public T Data { get; set; }
}
} }
+4 -1
View File
@@ -15,7 +15,10 @@ namespace YYApi.Controllers
/// </summary> /// </summary>
public class BaseController : Controller public class BaseController : Controller
{ {
protected int LoginId => int.Parse(HttpContext.Items["LoginId"].ToString()); /// <summary>
/// 当前登录用户的ID
/// </summary>
protected LoginInfoItem LoginInfo => (LoginInfoItem)HttpContext.Items["LoginInfo"];
/// <summary> /// <summary>
/// 验证请求参数 /// 验证请求参数
+22 -5
View File
@@ -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;
} }
+10
View File
@@ -2,5 +2,15 @@
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true "anonymousAuthentication": true
},
"profiles": {
"YYApi": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
} }
} }
+5 -4
View File
@@ -4,12 +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>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -21,8 +22,8 @@
<Content Remove="Properties\launchSettings.json" /> <Content Remove="Properties\launchSettings.json" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc4" /> <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc5" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc4" /> <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc5" />
</ItemGroup> </ItemGroup>
<ProjectExtensions> <ProjectExtensions>
<MonoDevelop> <MonoDevelop>