diff --git a/Yi.Furion.Rbac/Yi.Framework.Infrastructure/Ddd/Services/ReadOnlyAppService.cs b/Yi.Furion.Rbac/Yi.Framework.Infrastructure/Ddd/Services/ReadOnlyAppService.cs index 33afc5c6..5182cfda 100644 --- a/Yi.Furion.Rbac/Yi.Framework.Infrastructure/Ddd/Services/ReadOnlyAppService.cs +++ b/Yi.Furion.Rbac/Yi.Framework.Infrastructure/Ddd/Services/ReadOnlyAppService.cs @@ -1,4 +1,5 @@ using Furion; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using SqlSugar; using Yi.Framework.Infrastructure.Ddd.Dtos; @@ -76,7 +77,7 @@ where TEntityDto : IEntityDto /// /// /// - public virtual async Task> GetListAsync(TGetListInput input) + public virtual async Task> GetListAsync([FromQuery]TGetListInput input) { var totalCount = -1; diff --git a/Yi.Furion.Rbac/Yi.Framework.Module/Startup.cs b/Yi.Furion.Rbac/Yi.Framework.Module/Startup.cs index a64c966c..96067245 100644 --- a/Yi.Furion.Rbac/Yi.Framework.Module/Startup.cs +++ b/Yi.Furion.Rbac/Yi.Framework.Module/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Yi.Framework.Infrastructure.AspNetCore; using Yi.Framework.Infrastructure.Sqlsugar; +using Yi.Framework.Module.ImageSharp.HeiCaptcha; namespace Yi.Framework.Module; @@ -17,6 +18,8 @@ public class Startup : AppStartup services.Configure(App.Configuration.GetSection("DbConnOptions")); services.AddDbSqlsugarContextServer(); + + services.AddHeiCaptcha(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/Yi.Furion.Rbac/Yi.Framework.Module/Yi.Framework.Module.csproj b/Yi.Furion.Rbac/Yi.Framework.Module/Yi.Framework.Module.csproj index a238c36d..10eb138b 100644 --- a/Yi.Furion.Rbac/Yi.Framework.Module/Yi.Framework.Module.csproj +++ b/Yi.Furion.Rbac/Yi.Framework.Module/Yi.Framework.Module.csproj @@ -5,6 +5,13 @@ enable enable + + + + + + + @@ -15,5 +22,12 @@ + + + + + + + diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Dtos/Dept/DeptGetListInputVo.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Dtos/Dept/DeptGetListInputVo.cs index 54c4213d..237c9781 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Dtos/Dept/DeptGetListInputVo.cs +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Dtos/Dept/DeptGetListInputVo.cs @@ -10,7 +10,5 @@ namespace Yi.Furion.Rbac.Application.System.Dtos.Dept public string DeptCode { get; set; } public string Leader { get; set; } - public DateTime? StartTime { get; set; } - public DateTime? EndTime { get; set; } } } diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Event/LoginEventHandler.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Event/LoginEventHandler.cs index c011019c..65ac38c4 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Event/LoginEventHandler.cs +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Event/LoginEventHandler.cs @@ -9,16 +9,17 @@ using Yi.Furion.Rbac.Core.Etos; namespace Yi.Furion.Rbac.Application.System.Event { - public class LoginEventHandler : IEventSubscriber, ISingleton + public class LoginEventHandler : IEventSubscriber,ISingleton { private readonly IRepository _loginLogRepository; - private readonly HttpContext _httpContext; + private readonly IHttpContextAccessor _httpContextAccessor; + private HttpContext _httpContext=> _httpContextAccessor.HttpContext; public LoginEventHandler(IRepository loginLogRepository, IHttpContextAccessor httpContextAccessor) { _loginLogRepository = loginLogRepository; - _httpContext = httpContextAccessor.HttpContext; + _httpContextAccessor = httpContextAccessor; } - [EventSubscribe(nameof(LoginEventSource))] + //[EventSubscribe(nameof(LoginEventSource))] public Task HandlerAsync(EventHandlerExecutingContext context) { var eventData=(LoginEventArgs)context.Source.Payload; diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/AccountService.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/AccountService.cs index 3782c4ce..014d80c4 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/AccountService.cs +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/AccountService.cs @@ -27,7 +27,6 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl (_userRepository, _currentUser, _accountManager, _menuRepository, _smsAliyunManager, _smsAliyunManagerOptions, _securityCode, _memoryCache, _eventPublisher) = (userRepository, currentUser, accountManager, menuRepository, smsAliyunManager, smsAliyunManagerOptions, securityCode, memoryCache, eventPublisher); - private JwtTokenManager _jwtTokenManager { get; set; } private IUserRepository _userRepository { get; set; } @@ -140,8 +139,8 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl #pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 //创建token - var token = _jwtTokenManager.CreateToken(_accountManager.UserInfoToClaim(userInfo)); - return new { Token = token }; + var accessToken = JWTEncryption.Encrypt(_accountManager.UserInfoToClaim(userInfo)); + return new { Token = accessToken }; } /// diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/RoleService.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/RoleService.cs index 078ddbff..d9ef843f 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/RoleService.cs +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/RoleService.cs @@ -14,13 +14,12 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl public class RoleService : CrudAppService, IRoleService, ITransient, IDynamicApiController { - public RoleService(RoleManager roleManager, IUnitOfWorkManager unitOfWorkManager) => - (_roleManager, _unitOfWorkManager) = - (roleManager, unitOfWorkManager); + public RoleService(RoleManager roleManager) => + (_roleManager) = + (roleManager); private RoleManager _roleManager { get; set; } - - private IUnitOfWorkManager _unitOfWorkManager { get; set; } + public override async Task> GetListAsync(RoleGetListInputVo input) @@ -44,14 +43,14 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl public override async Task CreateAsync(RoleCreateInputVo input) { RoleGetOutputDto outputDto; - using (var uow = _unitOfWorkManager.CreateContext()) - { + //using (var uow = _unitOfWorkManager.CreateContext()) + //{ var entity = await MapToEntityAsync(input); await _repository.InsertAsync(entity); outputDto = await MapToGetOutputDtoAsync(entity); await _roleManager.GiveRoleSetMenuAsync(new List { entity.Id }, input.MenuIds); - uow.Commit(); - } + // uow.Commit(); + //} return outputDto; } @@ -65,8 +64,8 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl public override async Task UpdateAsync(long id, RoleUpdateInputVo input) { var dto = new RoleGetOutputDto(); - using (var uow = _unitOfWorkManager.CreateContext()) - { + //using (var uow = _unitOfWorkManager.CreateContext()) + //{ var entity = await _repository.GetByIdAsync(id); await MapToEntityAsync(input, entity); await _repository.UpdateAsync(entity); @@ -74,8 +73,8 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl await _roleManager.GiveRoleSetMenuAsync(new List { id }, input.MenuIds); dto = await MapToGetOutputDtoAsync(entity); - uow.Commit(); - } + // uow.Commit(); + //} return dto; } diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/UserService.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/UserService.cs index 1431305b..93e335cf 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/UserService.cs +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/System/Services/Impl/UserService.cs @@ -21,15 +21,11 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl { - public UserService(UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IUnitOfWorkManager unitOfWorkManager) => - (_userManager, _userRepository, _currentUser, _unitOfWorkManager) = - (userManager, userRepository, currentUser, unitOfWorkManager); + public UserService(UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser) => + (_userManager, _userRepository, _currentUser) = + (userManager, userRepository, currentUser); private UserManager _userManager { get; set; } - - private IUnitOfWorkManager _unitOfWorkManager { get; set; } - - private IUserRepository _userRepository { get; set; } @@ -91,16 +87,16 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl entities.BuildPassword(); - using (var uow = _unitOfWorkManager.CreateContext()) - { + //using (var uow = _unitOfWorkManager.CreateContext()) + //{ var returnEntity = await _repository.InsertReturnEntityAsync(entities); await _userManager.GiveUserSetRoleAsync(new List { returnEntity.Id }, input.RoleIds); await _userManager.GiveUserSetPostAsync(new List { returnEntity.Id }, input.PostIds); - uow.Commit(); + //uow.Commit(); var result = await MapToGetOutputDtoAsync(returnEntity); return result; - } + //} } /// /// 单查 @@ -136,13 +132,13 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl entity.BuildPassword(); } await MapToEntityAsync(input, entity); - using (var uow = _unitOfWorkManager.CreateContext()) - { + //using (var uow = _unitOfWorkManager.CreateContext()) + //{ var res1 = await _repository.UpdateAsync(entity); await _userManager.GiveUserSetRoleAsync(new List { id }, input.RoleIds); await _userManager.GiveUserSetPostAsync(new List { id }, input.PostIds); - uow.Commit(); - } + // uow.Commit(); + //} return await MapToGetOutputDtoAsync(entity); } diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/Yi.Furion.Rbac.Application.xml b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/Yi.Furion.Rbac.Application.xml index 028ce291..2f3fdfa5 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/Yi.Furion.Rbac.Application.xml +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Application/Yi.Furion.Rbac.Application.xml @@ -4,5 +4,361 @@ Yi.Furion.Rbac.Application + + + 用户领域服务 + + + + + 登录效验 + + + + + + + + + 判断账户合法存在 + + + + + + + + 令牌转换 + + + + + + + 更新密码 + + + + + + + + + + 重置密码 + + + + + + + + 给角色设置菜单 + + + + + + + + 给用户设置角色 + + + + + + + + 给用户设置岗位 + + + + + + + + 账号 + + + + + 密码 + + + + + 唯一标识码 + + + + + 电话 + + + + + 验证码 + + + + + Dept输入创建对象 + + + + + Menu输入创建对象 + + + + + Post输入创建对象 + + + + + Role输入创建对象 + + + + + User输入创建对象 + + + + + 获取客户端信息 + + + + + + + 记录用户登陆信息 + + + + + + + Dept服务抽象 + + + + + Menu服务抽象 + + + + + 效验图片登录验证码,无需和账号绑定 + + + + + 效验电话验证码,需要与电话号码绑定 + + + + + 登录 + + + + + + + 生成验证码 + + + + + + 验证电话号码 + + + + + + 注册 手机验证码 + + + + + + 注册,需要验证码通过 + + + + + + + 查询已登录的账户信息 + + + + + + + 获取当前登录用户的前端路由 + + + + + + 退出登录 + + + + + + 更新密码 + + + + + + + 重置密码 + + + + + + + + 更新头像 + + + + + + + Dept服务实现 + + + + + 通过角色id查询该角色全部部门 + + + + + + 多查 + + + + + + + Menu服务实现 + + + + + 查询当前角色的菜单 + + + + + + + Post服务实现 + + + + + Role服务实现 + + + + + 添加角色 + + + + + + + 修改角色 + + + + + + + + 更新状态 + + + + + + + + User服务实现 + + + + + 查询用户 + + + + + + + 添加用户 + + + + + + + + 单查 + + + + + + + 更新用户 + + + + + + + + 更新个人中心 + + + + + + + 更新状态 + + + + + + + + Post服务抽象 + + + + + Role服务抽象 + + + + + User服务抽象 + + diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/Startup.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/Startup.cs index 24d6ab93..3ff1ae2a 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/Startup.cs +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/Startup.cs @@ -16,8 +16,7 @@ public class Startup : AppStartup services.AddCorsAccessor(); - services.AddControllers() - .AddInjectWithUnifyResult(); + services.AddControllers().AddInject(); services.AddEventBus(); } diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/YiRESTfulResult.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/YiRESTfulResult.cs new file mode 100644 index 00000000..2991c252 --- /dev/null +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/YiRESTfulResult.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Furion.Rbac.Web.Core +{ + public class YiRESTfulResult + { + + public YiRESTfulResult() { } + } +} diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/YiRESTfulResultProvider.cs b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/YiRESTfulResultProvider.cs new file mode 100644 index 00000000..4c890e73 --- /dev/null +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Core/YiRESTfulResultProvider.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Furion; +using Furion.DataValidation; +using Furion.FriendlyException; +using Furion.UnifyResult; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Yi.Furion.Rbac.Web.Core +{ + [UnifyModel(typeof(YiRESTfulResult<>))] + public class YiRESTfulResultProvider : IUnifyResultProvider + { + public IActionResult OnException(ExceptionContext context, ExceptionMetadata metadata) + { + return new JsonResult(new YiRESTfulResult() + , UnifyContext.GetSerializerSettings(context)); // 当前行仅限 Furion 4.6.6+ 使用 + } + + public async Task OnResponseStatusCodes(HttpContext context, int statusCode, UnifyResultSettingsOptions unifyResultSettings = null) + { + UnifyContext.SetResponseStatusCodes(context, statusCode, unifyResultSettings); + + switch (statusCode) + { + // 处理 401 状态码 + case StatusCodes.Status401Unauthorized: + await context.Response.WriteAsJsonAsync(new YiRESTfulResult() + , App.GetOptions()?.JsonSerializerOptions); + break; + // 处理 403 状态码 + case StatusCodes.Status403Forbidden: + await context.Response.WriteAsJsonAsync(new YiRESTfulResult() + , App.GetOptions()?.JsonSerializerOptions); + break; + default: break; + } + } + + public IActionResult OnSucceeded(ActionExecutedContext context, object data) + { + return new JsonResult(new YiRESTfulResult() + , UnifyContext.GetSerializerSettings(context)); // 当前行仅限 Furion 4.6.6+ 使用 + } + + public IActionResult OnValidateFailed(ActionExecutingContext context, ValidationMetadata metadata) + { + return new JsonResult(new YiRESTfulResult() + , UnifyContext.GetSerializerSettings(context)); // 当前行仅限 Furion 4.6.6+ 使用 + } + } +} diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/Yi.Furion.Rbac.Web.Entry.csproj b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/Yi.Furion.Rbac.Web.Entry.csproj index ae7f868f..c3746b18 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/Yi.Furion.Rbac.Web.Entry.csproj +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/Yi.Furion.Rbac.Web.Entry.csproj @@ -23,6 +23,17 @@ + + + + + + Always + + + Always + + diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/appsettings.json b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/appsettings.json index 32de42f7..23430b19 100644 --- a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/appsettings.json +++ b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/appsettings.json @@ -22,5 +22,17 @@ "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql "Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver ] + }, + "JWTSettings": { + "ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true + "IssuerSigningKey": "你的密钥", // 密钥,string 类型,必须是复杂密钥,长度大于16 + "ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true + "ValidIssuer": "签发方", // 签发方,string 类型 + "ValidateAudience": true, // 是否验证签收方,bool 类型,默认true + "ValidAudience": "签收方", // 签收方,string 类型 + "ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true + "ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟 + "ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认 5秒 + "Algorithm": "HS256" // 加密算法,string 类型,默认 HS256 } } \ No newline at end of file diff --git a/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/ip2region.db b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/ip2region.db new file mode 100644 index 00000000..0fc60e6c Binary files /dev/null and b/Yi.Furion.Rbac/Yi.Furion.Rbac.Web.Entry/ip2region.db differ