using CZFW.Framework.Model.ViewModel; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace CZFW.Framework.Auth { public class CZAuth : IMiddleware { public Task InvokeAsync(HttpContext context, RequestDelegate next) { var path = context.Request.Path; if (path.StartsWithSegments("/assets") || path.StartsWithSegments("/userinfo/login") || path.StartsWithSegments("/userinfo/login2") || path.StartsWithSegments("/userinfo/login3") || path.StartsWithSegments("/userinfo/GetCurrentUser") || path.StartsWithSegments("/home/index") || path.StartsWithSegments("/") || path.StartsWithSegments("/home") || path.StartsWithSegments("/index") || path.StartsWithSegments("/login") || path.StartsWithSegments("/org") || path.StartsWithSegments("/worldManage") || path.StartsWithSegments("/userManage") || path.StartsWithSegments("/uploadedimages") || path.StartsWithSegments("/sync")) return next.Invoke(context); var op = Model.OperatorProvider.Provider.GetCurrent(); if (op != null) { if (!(path.StartsWithSegments("/portal") || path.StartsWithSegments("/portalManage") || path.StartsWithSegments("/uploadedImage") || path.StartsWithSegments("/Attachment/UploadImage")) && (op.IsSystem && !op.HasAccess(context.Request.Path))) { var result = new ResultModel { Success = false, Code = "401", Message = "Not Authorized Access!" }; return context.Response.WriteAsync(Core.Json.Json.ToJson(result)); } return next.Invoke(context); } else { var result = new ResultModel { Success = false, Code = "403", Message = "Not Login!" }; return context.Response.WriteAsync(CZFW.Core.Json.Json.ToJson(result)); } } } public static class CZAuthExtensions { public static IApplicationBuilder UseCZAuth(this IApplicationBuilder builder) { return builder.UseMiddleware(); } } }