From 989036d67c723003f67c4aa4ef6a1fed42b0e882 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 3 Mar 2025 20:45:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(account):=20=E5=A2=9E=E5=8A=A0=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=94=A8=E6=88=B7=E5=AE=89=E5=85=A8=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Abp/Account/Dto/GetUserClaimStateDto.cs | 7 ++ .../LINGYUN/Abp/Account/Dto/SecurityLogDto.cs | 29 +++++++++ .../Account/Dto/SecurityLogGetListInput.cs | 15 +++++ .../LINGYUN/Abp/Account/IMyClaimAppService.cs | 17 +++++ .../Abp/Account/IMyProfileAppService.cs | 6 +- .../Abp/Account/IMySecurityLogAppService.cs | 14 ++++ .../Account/Localization/Resources/en.json | 8 ++- .../Localization/Resources/zh-Hans.json | 8 ++- .../LINGYUN.Abp.Account.Application.csproj | 3 +- .../Account/AbpAccountApplicationModule.cs | 51 ++++++++++----- .../Abp/Account/AbpAccountMapperProfile.cs | 12 ++++ .../LINGYUN/Abp/Account/AccountAppService.cs | 2 - .../Account/AccountApplicationServiceBase.cs | 1 + .../LINGYUN/Abp/Account/MyClaimAppService.cs | 64 +++++++++++++------ .../Abp/Account/MyProfileAppService.cs | 16 ++--- .../Abp/Account/MySecurityLogAppService.cs | 51 +++++++++++++++ .../LINGYUN/Abp/Account/MyClaimController.cs | 24 +++++-- .../Abp/Account/MyProfileController.cs | 18 +++--- .../Abp/Account/MySecurityLogController.cs | 45 +++++++++++++ 19 files changed, 327 insertions(+), 64 deletions(-) create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/GetUserClaimStateDto.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogDto.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogGetListInput.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMySecurityLogAppService.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountMapperProfile.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MySecurityLogAppService.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MySecurityLogController.cs diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/GetUserClaimStateDto.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/GetUserClaimStateDto.cs new file mode 100644 index 000000000..5c3d661c8 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/GetUserClaimStateDto.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.Account; + +public class GetUserClaimStateDto +{ + public bool IsBound { get; set; } + public string Value { get; set; } +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogDto.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogDto.cs new file mode 100644 index 000000000..eb5f5ddad --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogDto.cs @@ -0,0 +1,29 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.Account; + +public class SecurityLogDto : ExtensibleEntityDto +{ + public string ApplicationName { get; set; } + + public string Identity { get; set; } + + public string Action { get; set; } + + public Guid? UserId { get; set; } + + public string UserName { get; set; } + + public string TenantName { get; set; } + + public string ClientId { get; set; } + + public string CorrelationId { get; set; } + + public string ClientIpAddress { get; set; } + + public string BrowserInfo { get; set; } + + public DateTime CreationTime { get; set; } +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogGetListInput.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogGetListInput.cs new file mode 100644 index 000000000..afde4703a --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SecurityLogGetListInput.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.Account; + +public class SecurityLogGetListInput : PagedAndSortedResultRequestDto +{ + public DateTime? StartTime { get; set; } + public DateTime? EndTime { get; set; } + public string ApplicationName { get; set; } + public string Identity { get; set; } + public string ActionName { get; set; } + public string ClientId { get; set; } + public string CorrelationId { get; set; } +} \ No newline at end of file diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyClaimAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyClaimAppService.cs index 3141e954c..5706195b3 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyClaimAppService.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyClaimAppService.cs @@ -5,5 +5,22 @@ namespace LINGYUN.Abp.Account; public interface IMyClaimAppService : IApplicationService { + /// + /// 变更头像 + /// + /// + /// Task ChangeAvatarAsync(ChangeAvatarInput input); + /// + /// 查询绑定状态 + /// + /// + /// + Task GetStateAsync(string claimType); + /// + /// 重置绑定状态 + /// + /// + /// + Task ResetAsync(string claimType); } diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyProfileAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyProfileAppService.cs index 84905cae0..430090099 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyProfileAppService.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyProfileAppService.cs @@ -11,13 +11,13 @@ public interface IMyProfileAppService : IApplicationService /// 获取验证器信息 /// /// - Task GetAuthenticator(); + Task GetAuthenticatorAsync(); /// /// 验证验证器代码 /// /// /// - Task VerifyAuthenticatorCode(VerifyAuthenticatorCodeInput input); + Task VerifyAuthenticatorCodeAsync(VerifyAuthenticatorCodeInput input); /// /// 获取会话列表 /// @@ -34,7 +34,7 @@ public interface IMyProfileAppService : IApplicationService /// 重置验证器 /// /// - Task ResetAuthenticator(); + Task ResetAuthenticatorAsync(); /// /// 获取二次认证状态 /// diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMySecurityLogAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMySecurityLogAppService.cs new file mode 100644 index 000000000..9cd577543 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMySecurityLogAppService.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.Account; + +public interface IMySecurityLogAppService +{ + Task> GetListAsync(SecurityLogGetListInput input); + + Task GetAsync(Guid id); + + Task DeleteAsync(Guid id); +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json index f450b36bd..3fac4ec96 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json @@ -16,6 +16,7 @@ "DisplayName:WeChatCode": "Wechat login code", "DisplayName:AuthenticatorCode": "Authenticator Code", "TwoFactor": "Two factor authentication", + "TwoFactor:Enabled": "TwoFactor Enabled", "TwoFactor:Email": "Email", "TwoFactor:Phone": "Phone", "TwoFactor:Authenticator": "Authenticator", @@ -43,6 +44,11 @@ "YourAuthenticatorIsSuccessfullyReset": "Your authenticator reset was successful.", "Steps:PreStep": "Pre Step", "Steps:NextStep": "Next Step", - "Steps:Done": "Done" + "Steps:Done": "Done", + "PersonalSessions": "Personal sessions", + "ProfileTab:Session": "Sessions", + "ProfileTab:TwoFactor": "TwoFactor", + "ProfileTab:Authenticator": "Authenticator", + "ProfileTab:SecurityLog": "Security Log" } } \ No newline at end of file diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json index d216764e0..a550172c7 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json @@ -16,6 +16,7 @@ "DisplayName:WeChatCode": "微信登录凭证", "DisplayName:AuthenticatorCode": "验证代码", "TwoFactor": "双因素身份验证", + "TwoFactor:Enabled": "启用双因素认证", "TwoFactor:Email": "邮箱验证", "TwoFactor:Phone": "手机验证", "TwoFactor:Authenticator": "验证码验证", @@ -43,6 +44,11 @@ "YourAuthenticatorIsSuccessfullyReset": "您的验证器重置成功.", "Steps:PreStep": "上一步", "Steps:NextStep": "下一步", - "Steps:Done": "完成" + "Steps:Done": "完成", + "PersonalSessions": "我的会话", + "ProfileTab:Session": "会话管理", + "ProfileTab:TwoFactor": "双因素身份验证", + "ProfileTab:Authenticator": "身份验证程序", + "ProfileTab:SecurityLog": "安全日志" } } \ No newline at end of file diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN.Abp.Account.Application.csproj b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN.Abp.Account.Application.csproj index 131ab2367..1ada339df 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN.Abp.Account.Application.csproj +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN.Abp.Account.Application.csproj @@ -19,11 +19,12 @@ + - + diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountApplicationModule.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountApplicationModule.cs index 30425c87a..5544d58be 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountApplicationModule.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountApplicationModule.cs @@ -1,22 +1,34 @@ -using LINGYUN.Abp.Account.Templates; -using LINGYUN.Abp.Identity; -using LINGYUN.Abp.WeChat.MiniProgram; -using Volo.Abp.Modularity; +using LINGYUN.Abp.Account.Emailing; +using LINGYUN.Abp.Account.Emailing.Localization; +using LINGYUN.Abp.Identity; +using LINGYUN.Abp.WeChat.MiniProgram; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Account.Localization; +using Volo.Abp.AutoMapper; +using Volo.Abp.Localization; +using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.VirtualFileSystem; -namespace LINGYUN.Abp.Account; - -[DependsOn( - typeof(Volo.Abp.Account.AbpAccountApplicationModule), - typeof(AbpAccountApplicationContractsModule), - typeof(AbpAccountTemplatesModule), - typeof(AbpIdentityDomainModule), - typeof(AbpWeChatMiniProgramModule))] -public class AbpAccountApplicationModule : AbpModule -{ +namespace LINGYUN.Abp.Account; + +[DependsOn( + typeof(Volo.Abp.Account.AbpAccountApplicationModule), + typeof(AbpAccountApplicationContractsModule), + typeof(AbpAccountEmailingModule), + typeof(AbpIdentityDomainModule), + typeof(AbpWeChatMiniProgramModule))] +public class AbpAccountApplicationModule : AbpModule +{ public override void ConfigureServices(ServiceConfigurationContext context) { + context.Services.AddAutoMapperObjectMapper(); + + Configure(options => + { + options.AddMaps(validate: true); + }); + Configure(options => { options.FileSets.AddEmbedded(); @@ -26,5 +38,12 @@ public class AbpAccountApplicationModule : AbpModule { options.Applications["MVC"].Urls[AccountUrlNames.EmailConfirm] = "Account/EmailConfirm"; }); - } -} + + Configure(options => + { + options.Resources + .Get() + .AddBaseTypes(typeof(AccountEmailingResource)); + }); + } +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountMapperProfile.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountMapperProfile.cs new file mode 100644 index 000000000..ee907f377 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AbpAccountMapperProfile.cs @@ -0,0 +1,12 @@ +using AutoMapper; +using LINGYUN.Abp.AuditLogging; + +namespace LINGYUN.Abp.Account; + +public class AbpAccountMapperProfile : Profile +{ + public AbpAccountMapperProfile() + { + CreateMap(MemberList.Destination); + } +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs index a22c0e07a..e27278844 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs @@ -7,7 +7,6 @@ using LINGYUN.Abp.WeChat.MiniProgram; using LINGYUN.Abp.WeChat.OpenId; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System; using System.ComponentModel.DataAnnotations; @@ -15,7 +14,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp; -using Volo.Abp.Account; using Volo.Abp.Application.Dtos; using Volo.Abp.Caching; using Volo.Abp.Clients; diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountApplicationServiceBase.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountApplicationServiceBase.cs index 73b94a953..52e61ce0b 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountApplicationServiceBase.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountApplicationServiceBase.cs @@ -17,6 +17,7 @@ public abstract class AccountApplicationServiceBase : ApplicationService protected AccountApplicationServiceBase() { LocalizationResource = typeof(AccountResource); + ObjectMapperContext = typeof(AbpAccountApplicationModule); } protected async virtual Task GetCurrentUserAsync() diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyClaimAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyClaimAppService.cs index 1c47aeb37..3b040a4d4 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyClaimAppService.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyClaimAppService.cs @@ -22,25 +22,25 @@ public class MyClaimAppService : AccountApplicationServiceBase, IMyClaimAppServi var user = await GetCurrentUserAsync(); // TODO: Use AbpClaimTypes.Picture - user.Claims.RemoveAll(x => x.ClaimType.Equals(IdentityConsts.ClaimType.Avatar.Name)); - user.AddClaim(GuidGenerator, new Claim(IdentityConsts.ClaimType.Avatar.Name, input.AvatarUrl)); - - var avatarClaims = user.Claims.Where(x => x.ClaimType.StartsWith(AbpClaimTypes.Picture)) - .Select(x => x.ToClaim()) - .Skip(0) - .Take(3) - .ToList(); - if (avatarClaims.Any()) - { + user.Claims.RemoveAll(x => x.ClaimType.Equals(IdentityConsts.ClaimType.Avatar.Name)); + user.AddClaim(GuidGenerator, new Claim(IdentityConsts.ClaimType.Avatar.Name, input.AvatarUrl)); + + var avatarClaims = user.Claims.Where(x => x.ClaimType.StartsWith(AbpClaimTypes.Picture)) + .Select(x => x.ToClaim()) + .Skip(0) + .Take(3) + .ToList(); + if (avatarClaims.Any()) + { // 保留最多3个头像 if (avatarClaims.Count >= 3) { user.RemoveClaim(avatarClaims.First()); avatarClaims.RemoveAt(0); - } - - // 历史头像加数字标识 - for (var index = 1; index <= avatarClaims.Count; index++) + } + + // 历史头像加数字标识 + for (var index = 1; index <= avatarClaims.Count; index++) { var avatarClaim = avatarClaims[index - 1]; var findClaim = user.FindClaim(avatarClaim); @@ -49,14 +49,38 @@ public class MyClaimAppService : AccountApplicationServiceBase, IMyClaimAppServi findClaim.SetClaim(new Claim( AbpClaimTypes.Picture + index.ToString(), findClaim.ClaimValue)); - } - } - } - - user.AddClaim(GuidGenerator, new Claim(AbpClaimTypes.Picture, input.AvatarUrl)); - + } + } + } + + user.AddClaim(GuidGenerator, new Claim(AbpClaimTypes.Picture, input.AvatarUrl)); + (await UserManager.UpdateAsync(user)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); } + + public async virtual Task GetStateAsync(string claimType) + { + var user = await GetCurrentUserAsync(); + + var userClaim = user.Claims.FirstOrDefault(x => x.ClaimType == claimType); + + return new GetUserClaimStateDto + { + IsBound = userClaim != null, + Value = userClaim?.ClaimValue, + }; + } + + public async virtual Task ResetAsync(string claimType) + { + var user = await GetCurrentUserAsync(); + + var seeyonLoginClaim = user.Claims.FirstOrDefault(x => x.ClaimType == claimType); + if (seeyonLoginClaim != null) + { + (await UserManager.RemoveClaimAsync(user, seeyonLoginClaim.ToClaim())).CheckErrors(); + } + } } diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyProfileAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyProfileAppService.cs index 0b77eb666..42790e5b0 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyProfileAppService.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyProfileAppService.cs @@ -7,11 +7,9 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; -using System.Text.Encodings.Web; using System.Threading.Tasks; using System.Web; using Volo.Abp; @@ -172,11 +170,13 @@ public class MyProfileAppService : AccountApplicationServiceBase, IMyProfileAppS var sender = LazyServiceProvider.LazyGetRequiredService(); await sender.SendEmailConfirmLinkAsync( - user, + user.Id, + user.Email, confirmToken, input.AppName, input.ReturnUrl, - input.ReturnUrlHash); + input.ReturnUrlHash, + user.TenantId); } public async virtual Task ConfirmEmailAsync(ConfirmEmailInput input) @@ -186,7 +186,7 @@ public class MyProfileAppService : AccountApplicationServiceBase, IMyProfileAppS var user = await UserManager.GetByIdAsync(CurrentUser.GetId()); // 字符编码错误 - var confirmToken = WebUtility.UrlDecode(input.ConfirmToken.Replace("%20", "%2B")); + var confirmToken = HttpUtility.UrlDecode(input.ConfirmToken); ; (await UserManager.ConfirmEmailAsync(user, confirmToken)).CheckErrors(); await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext @@ -196,7 +196,7 @@ public class MyProfileAppService : AccountApplicationServiceBase, IMyProfileAppS }); } - public async virtual Task GetAuthenticator() + public async virtual Task GetAuthenticatorAsync() { await IdentityOptions.SetAsync(); @@ -228,7 +228,7 @@ public class MyProfileAppService : AccountApplicationServiceBase, IMyProfileAppS }; } - public async virtual Task VerifyAuthenticatorCode(VerifyAuthenticatorCodeInput input) + public async virtual Task VerifyAuthenticatorCodeAsync(VerifyAuthenticatorCodeInput input) { await IdentityOptions.SetAsync(); @@ -257,7 +257,7 @@ public class MyProfileAppService : AccountApplicationServiceBase, IMyProfileAppS }; } - public async virtual Task ResetAuthenticator() + public async virtual Task ResetAuthenticatorAsync() { await IdentityOptions.SetAsync(); diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MySecurityLogAppService.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MySecurityLogAppService.cs new file mode 100644 index 000000000..86478f180 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MySecurityLogAppService.cs @@ -0,0 +1,51 @@ +using LINGYUN.Abp.AuditLogging; +using Microsoft.AspNetCore.Authorization; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.Account; + +[Authorize] +public class MySecurityLogAppService : AccountApplicationServiceBase, IMySecurityLogAppService +{ + protected ISecurityLogManager SecurityLogManager { get; } + public MySecurityLogAppService(ISecurityLogManager securityLogManager) + { + SecurityLogManager = securityLogManager; + } + public async virtual Task GetAsync(Guid id) + { + var securityLog = await SecurityLogManager.GetAsync(id, includeDetails: true); + + return ObjectMapper.Map(securityLog); + } + + public async virtual Task> GetListAsync(SecurityLogGetListInput input) + { + var userId = CurrentUser.GetId(); + var securityLogCount = await SecurityLogManager + .GetCountAsync(input.StartTime, input.EndTime, + input.ApplicationName, input.Identity, input.ActionName, + userId, null, input.ClientId, input.CorrelationId + ); + + var securityLogs = await SecurityLogManager + .GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, + input.StartTime, input.EndTime, + input.ApplicationName, input.Identity, input.ActionName, + userId, null, input.ClientId, input.CorrelationId, + includeDetails: false + ); + + return new PagedResultDto(securityLogCount, + ObjectMapper.Map, List>(securityLogs)); + } + + public async virtual Task DeleteAsync(Guid id) + { + await SecurityLogManager.DeleteAsync(id); + } +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyClaimController.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyClaimController.cs index dde75b6d1..8eedfcaec 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyClaimController.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyClaimController.cs @@ -1,4 +1,5 @@ using Asp.Versioning; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; using Volo.Abp; @@ -7,10 +8,11 @@ using Volo.Abp.AspNetCore.Mvc; namespace LINGYUN.Abp.Account; -[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] +[Authorize] [Area("account")] [ControllerName("Claim")] -[Route("/api/account/my-claim")] +[Route($"/api/{AccountRemoteServiceConsts.ModuleName}/my-claim")] +[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] public class MyClaimController : AbpControllerBase, IMyClaimAppService { private readonly IMyClaimAppService _service; @@ -23,8 +25,22 @@ public class MyClaimController : AbpControllerBase, IMyClaimAppService [HttpPost] [Route("change-avatar")] - public async virtual Task ChangeAvatarAsync(ChangeAvatarInput input) + public virtual Task ChangeAvatarAsync(ChangeAvatarInput input) + { + return _service.ChangeAvatarAsync(input); + } + + [HttpGet] + [Route("state/{claimType}")] + public virtual Task GetStateAsync(string claimType) + { + return _service.GetStateAsync(claimType); + } + + [HttpDelete] + [Route("reset/{claimType}")] + public virtual Task ResetAsync(string claimType) { - await _service.ChangeAvatarAsync(input); + return _service.ResetAsync(claimType); } } diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyProfileController.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyProfileController.cs index aa444c402..90da8191f 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyProfileController.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyProfileController.cs @@ -1,5 +1,6 @@ using Asp.Versioning; using LINGYUN.Abp.Identity; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; using Volo.Abp; @@ -9,10 +10,11 @@ using Volo.Abp.AspNetCore.Mvc; namespace LINGYUN.Abp.Account; -[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] +[Authorize] [Area("account")] [ControllerName("Profile")] -[Route("/api/account/my-profile")] +[Route($"/api/{AccountRemoteServiceConsts.ModuleName}/my-profile")] +[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] public class MyProfileController : AbpControllerBase, IMyProfileAppService { protected IMyProfileAppService MyProfileAppService { get; } @@ -81,22 +83,22 @@ public class MyProfileController : AbpControllerBase, IMyProfileAppService [HttpGet] [Route("authenticator")] - public virtual Task GetAuthenticator() + public virtual Task GetAuthenticatorAsync() { - return MyProfileAppService.GetAuthenticator(); + return MyProfileAppService.GetAuthenticatorAsync(); } [HttpPost] [Route("verify-authenticator-code")] - public virtual Task VerifyAuthenticatorCode(VerifyAuthenticatorCodeInput input) + public virtual Task VerifyAuthenticatorCodeAsync(VerifyAuthenticatorCodeInput input) { - return MyProfileAppService.VerifyAuthenticatorCode(input); + return MyProfileAppService.VerifyAuthenticatorCodeAsync(input); } [HttpPost] [Route("reset-authenticator")] - public virtual Task ResetAuthenticator() + public virtual Task ResetAuthenticatorAsync() { - return MyProfileAppService.ResetAuthenticator(); + return MyProfileAppService.ResetAuthenticatorAsync(); } } diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MySecurityLogController.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MySecurityLogController.cs new file mode 100644 index 000000000..df16a5540 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MySecurityLogController.cs @@ -0,0 +1,45 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Account; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace LINGYUN.Abp.Account; + +[Authorize] +[Area("account")] +[ControllerName("SecurityLog")] +[Route($"/api/{AccountRemoteServiceConsts.ModuleName}/security-logs")] +[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] +public class MySecurityLogController : AbpControllerBase, IMySecurityLogAppService +{ + private readonly IMySecurityLogAppService _service; + public MySecurityLogController(IMySecurityLogAppService service) + { + _service = service; + } + + [HttpDelete] + [Route("{id}")] + public virtual Task DeleteAsync(Guid id) + { + return _service.DeleteAsync(id); + } + + [HttpGet] + [Route("{id}")] + public virtual Task GetAsync(Guid id) + { + return _service.GetAsync(id); + } + + [HttpGet] + public virtual Task> GetListAsync(SecurityLogGetListInput input) + { + return _service.GetListAsync(input); + } +}