diff --git a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs index ec7734a..1d33ee3 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs @@ -10,10 +10,9 @@ using SqlSugar; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; -using ZR.Model.Dto; using ZR.Model.System; using ZR.Model.System.Dto; -using ZR.Service.System; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers { diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index bfda972..c68be2d 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -93,9 +93,8 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "修改密码", BusinessType = BusinessType.UPDATE)] public IActionResult UpdatePwd(string oldPassword, string newPassword) { - LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext); - - SysUser user = UserService.SelectUserById(loginUser.UserId); + long userId = HttpContext.GetUId(); + SysUser user = UserService.SelectUserById(userId); string oldMd5 = NETCore.Encrypt.EncryptProvider.Md5(oldPassword); string newMd5 = NETCore.Encrypt.EncryptProvider.Md5(newPassword); @@ -107,7 +106,7 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ApiResult.Error("新密码不能和旧密码相同")); } - if (UserService.ResetPwd(loginUser.UserId, newMd5.ToLower()) > 0) + if (UserService.ResetPwd(userId, newMd5) > 0) { //TODO 更新缓存 @@ -127,12 +126,12 @@ namespace ZR.Admin.WebApi.Controllers.System [Log(Title = "修改头像", BusinessType = BusinessType.UPDATE, IsSaveRequestData = false)] public async Task Avatar([FromForm(Name = "picture")] IFormFile formFile) { - LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext); + long userId = HttpContext.GetUId(); if (formFile == null) throw new CustomException("请选择文件"); SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "avatar", HttpContext.GetName(), formFile); - UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = loginUser.UserId }); + UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = userId }); return SUCCESS(new { imgUrl = file.AccessUrl }); } } diff --git a/Infrastructure/Extensions/AppServiceExtensions.cs b/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs similarity index 81% rename from Infrastructure/Extensions/AppServiceExtensions.cs rename to ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs index 4f3f5e5..f888f1f 100644 --- a/Infrastructure/Extensions/AppServiceExtensions.cs +++ b/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs @@ -1,11 +1,13 @@ using Infrastructure.Attribute; using Microsoft.Extensions.DependencyInjection; -using System; using System.Linq; using System.Reflection; -namespace Infrastructure.Extensions +namespace ZR.Admin.WebApi.Extensions { + /// + /// App服务注册 + /// public static class AppServiceExtensions { /// @@ -14,18 +16,16 @@ namespace Infrastructure.Extensions /// public static void AddAppService(this IServiceCollection services) { - //var assemblies = AppDomain.CurrentDomain.GetAssemblies(); - - string []cls = new string[] { "ZR.Repository", "ZR.Service", "ZR.Tasks" }; + string[] cls = new string[] { "ZR.Repository", "ZR.Service", "ZR.Tasks" }; foreach (var item in cls) { - Assembly assembly = Assembly.Load(item); - Register(services, assembly); + Register(services, item); } } - private static void Register(IServiceCollection services, Assembly assembly) + private static void Register(IServiceCollection services, string item) { + Assembly assembly = Assembly.Load(item); foreach (var type in assembly.GetTypes()) { var serviceAttribute = type.GetCustomAttribute(); @@ -59,11 +59,7 @@ namespace Infrastructure.Extensions services.AddTransient(serviceType, type); break; } - //Console.WriteLine($"注册:{serviceType}"); - } - else - { - //Console.WriteLine($"注册:{serviceType}"); + //System.Console.WriteLine($"注册:{serviceType}"); } } } diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index 044deb7..3dea7f9 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -11,18 +11,9 @@ namespace ZR.Admin.WebApi.Extensions var types = source?.GetType(); if (types == null) return source; - if (types.GetProperty("CreateTime") != null) - { - types.GetProperty("CreateTime")?.SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("AddTime") != null) - { - types.GetProperty("AddTime")?.SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("UpdateTime") != null) - { - types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); - } + types.GetProperty("CreateTime")?.SetValue(source, DateTime.Now, null); + types.GetProperty("AddTime")?.SetValue(source, DateTime.Now, null); + types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); if (types.GetProperty("Create_by") != null && context != null) { types.GetProperty("Create_by")?.SetValue(source, context.GetName(), null); @@ -47,22 +38,12 @@ namespace ZR.Admin.WebApi.Extensions var types = source?.GetType(); if (types == null) return source; - if (types.GetProperty("UpdateTime") != null) - { - types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("Update_time") != null) - { - types.GetProperty("Update_time")?.SetValue(source, DateTime.Now, null); - } - if (types.GetProperty("UpdateBy") != null) - { - types.GetProperty("UpdateBy")?.SetValue(source, context?.GetName(), null); - } - if (types.GetProperty("Update_by") != null) - { - types.GetProperty("Update_by")?.SetValue(source, context?.GetName(), null); - } + types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); + types.GetProperty("Update_time")?.SetValue(source, DateTime.Now, null); + + types.GetProperty("UpdateBy")?.SetValue(source,context.GetName(), null); + types.GetProperty("Update_by")?.SetValue(source, context.GetName(), null); + return source; } diff --git a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs index a8caab5..a2500d8 100644 --- a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs +++ b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs @@ -1,7 +1,5 @@ using Infrastructure; using Infrastructure.Extensions; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; @@ -10,7 +8,6 @@ using System.Linq; using System.Security.Claims; using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; using UAParser; using ZR.Model.System; @@ -73,7 +70,10 @@ namespace ZR.Admin.WebApi.Extensions public static long GetUId(this HttpContext context) { var uid = context.User.FindFirstValue(ClaimTypes.PrimarySid); - + if (uid.IsEmpty() || uid.IsNullOrZero()) + { + throw new CustomException(ResultCode.DENY, "未登录"); + } return !string.IsNullOrEmpty(uid) ? long.Parse(uid) : 0; } diff --git a/ZR.Admin.WebApi/Hubs/MessageHub.cs b/ZR.Admin.WebApi/Hubs/MessageHub.cs index 3a51212..46fc719 100644 --- a/ZR.Admin.WebApi/Hubs/MessageHub.cs +++ b/ZR.Admin.WebApi/Hubs/MessageHub.cs @@ -2,6 +2,7 @@ using Infrastructure.Constant; using Infrastructure.Model; using IPTools.Core; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Framework; @@ -42,12 +43,12 @@ namespace ZR.Admin.WebApi.Hubs var ip = HttpContextExtension.GetClientUserIp(App.HttpContext); var ip_info = IpTool.Search(ip); - LoginUser loginUser = JwtUtil.GetLoginUser(App.HttpContext); + var userid = HttpContextExtension.GetUId(App.HttpContext); var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId); //判断用户是否存在,否则添加集合 if (!user && Context.User.Identity.IsAuthenticated) { - OnlineUsers users = new(Context.ConnectionId, name, loginUser?.UserId, ip) + OnlineUsers users = new(Context.ConnectionId, name, userid, ip) { Location = ip_info.City }; diff --git a/ZR.Service/System/IService/ISysConfigService.cs b/ZR.Service/System/IService/ISysConfigService.cs index 4ed2f69..94ac407 100644 --- a/ZR.Service/System/IService/ISysConfigService.cs +++ b/ZR.Service/System/IService/ISysConfigService.cs @@ -1,7 +1,7 @@ using System; using ZR.Model.System; -namespace ZR.Service.System +namespace ZR.Service.System.IService { /// /// 参数配置service接口 diff --git a/ZR.Service/System/SysConfigService.cs b/ZR.Service/System/SysConfigService.cs index bf59c29..308674d 100644 --- a/ZR.Service/System/SysConfigService.cs +++ b/ZR.Service/System/SysConfigService.cs @@ -1,5 +1,6 @@ using Infrastructure.Attribute; using ZR.Model.System; +using ZR.Service.System.IService; namespace ZR.Service.System {