Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5e4d57772 | ||
|
|
239cd8bcbb | ||
|
|
62ddd6698e |
@@ -19,13 +19,16 @@ namespace SimApi.Attributes
|
|||||||
//默认是user登录类型
|
//默认是user登录类型
|
||||||
public SimApiAuthAttribute()
|
public SimApiAuthAttribute()
|
||||||
{
|
{
|
||||||
Types = new[] { "user" };
|
Types = new[]
|
||||||
|
{
|
||||||
|
"user"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//只检测一种用户类型的快捷方式
|
//只检测一种用户类型的快捷方式
|
||||||
public SimApiAuthAttribute(string type)
|
public SimApiAuthAttribute(string type)
|
||||||
{
|
{
|
||||||
Types = new[] { type };
|
Types = type.Split(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
//设定特定类型的检测
|
//设定特定类型的检测
|
||||||
@@ -37,7 +40,10 @@ namespace SimApi.Attributes
|
|||||||
//只检测一种用户类型的快捷方式
|
//只检测一种用户类型的快捷方式
|
||||||
public SimApiAuthAttribute(string type, string url)
|
public SimApiAuthAttribute(string type, string url)
|
||||||
{
|
{
|
||||||
Types = new[] { type };
|
Types = new[]
|
||||||
|
{
|
||||||
|
type
|
||||||
|
};
|
||||||
new HttpPostAttribute(url);
|
new HttpPostAttribute(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +56,7 @@ namespace SimApi.Attributes
|
|||||||
throw new SimApiException(401);
|
throw new SimApiException(401);
|
||||||
}
|
}
|
||||||
//检测用户类型
|
//检测用户类型
|
||||||
if (Types.Intersect(loginInfo.Type).Count() == 0)
|
if (!Types.Intersect(loginInfo.Type).Any())
|
||||||
{
|
{
|
||||||
throw new SimApiException(403);
|
throw new SimApiException(403);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace SimApi.Middlewares
|
|||||||
public class SimApiExceptionMiddleware
|
public class SimApiExceptionMiddleware
|
||||||
{
|
{
|
||||||
private RequestDelegate Next { get; }
|
private RequestDelegate Next { get; }
|
||||||
|
|
||||||
private ILogger<SimApiExceptionMiddleware> Log { get; }
|
private ILogger<SimApiExceptionMiddleware> Log { get; }
|
||||||
|
|
||||||
public SimApiExceptionMiddleware(RequestDelegate next, ILogger<SimApiExceptionMiddleware> log)
|
public SimApiExceptionMiddleware(RequestDelegate next, ILogger<SimApiExceptionMiddleware> log)
|
||||||
@@ -35,7 +36,10 @@ namespace SimApi.Middlewares
|
|||||||
await Next(context);
|
await Next(context);
|
||||||
if (context.Response.StatusCode != 200)
|
if (context.Response.StatusCode != 200)
|
||||||
{
|
{
|
||||||
if (!new[] {301, 302}.Contains(context.Response.StatusCode))
|
if (!new[]
|
||||||
|
{
|
||||||
|
301, 302
|
||||||
|
}.Contains(context.Response.StatusCode))
|
||||||
{
|
{
|
||||||
throw new SimApiException(context.Response.StatusCode);
|
throw new SimApiException(context.Response.StatusCode);
|
||||||
}
|
}
|
||||||
@@ -69,6 +73,8 @@ namespace SimApi.Middlewares
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
/// <param name="response"></param>
|
/// <param name="response"></param>
|
||||||
private void ErrorResponse(HttpContext context, SimApiBaseResponse response)
|
private void ErrorResponse(HttpContext context, SimApiBaseResponse response)
|
||||||
|
{
|
||||||
|
if (!context.Response.HasStarted)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 200;
|
context.Response.StatusCode = 200;
|
||||||
context.Response.Headers.Add("Content-Type", "application/json");
|
context.Response.Headers.Add("Content-Type", "application/json");
|
||||||
@@ -76,3 +82,4 @@ namespace SimApi.Middlewares
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
+4
-4
@@ -14,7 +14,7 @@
|
|||||||
<SynchReleaseVersion>false</SynchReleaseVersion>
|
<SynchReleaseVersion>false</SynchReleaseVersion>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<PackageVersion>5.0.2</PackageVersion>
|
<PackageVersion>5.0.2</PackageVersion>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
<Folder Include="Configurations\" />
|
<Folder Include="Configurations\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Minio" Version="4.0.4" />
|
<PackageReference Include="Minio" Version="4.0.7" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.3.1" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.3.1" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<MonoDevelop>
|
<MonoDevelop>
|
||||||
|
|||||||
Reference in New Issue
Block a user