From 0b4398a60adf3c7c1ee2eeede64a7c4cb65c47a0 Mon Sep 17 00:00:00 2001 From: wangyue Date: Wed, 17 Apr 2024 15:25:35 +0800 Subject: [PATCH 01/14] feat:revoke account --- .../CAAccount/Dtos/CancelCheckResultDto.cs | 5 +- .../CAAccount/Dtos/RevokeDto.cs | 4 +- .../CAAccount/ICAAccountAppService.cs | 2 + .../CAAccount/RevokeAccountInput.cs | 18 ++ .../Commons/ResponseMessage.cs | 2 + .../Contacts/Dtos/ContactLabelDto.cs | 6 + .../Dtos/InvitationPermissionsEnum.cs | 8 + .../Contacts/IContactAppService.cs | 1 + .../Google/IGoogleAppService.cs | 3 +- .../Verifier/IVerifierAppService.cs | 1 + .../Verifier/OperationType.cs | 3 +- .../Verifier/SendRevokeCodeInput.cs | 14 ++ .../Verifier/SendRevokeCodeResponse.cs | 10 + .../Verifier/VerifyRevokeCodeInput.cs | 19 ++ .../Verifier/VerifyRevokeCodeRequest.cs | 12 + .../Verifier/VerifyRevokeCodeResponse.cs | 6 + .../VerifyToken/IVerifyTokenStrategy.cs | 13 + .../CAAccount/CAAccountAppService.cs | 237 ++++++++++++++++-- .../Contacts/ContactAppService.cs | 5 + .../Google/GoogleAppService.cs | 27 ++ .../Verifier/IVerifierServerClient.cs | 2 + .../Verifier/VerifierAppService.cs | 13 +- .../Verifier/VerifierServerClient.cs | 30 ++- .../appsettings.json | 168 +++++++++---- .../Controllers/CAAccountController.cs | 16 +- .../Controllers/CAVerifierController.cs | 2 +- .../Controllers/ContactController.cs | 12 + 27 files changed, 565 insertions(+), 74 deletions(-) create mode 100644 src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs create mode 100644 src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs create mode 100644 src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs create mode 100644 src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs create mode 100644 src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs create mode 100644 src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeInput.cs create mode 100644 src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs create mode 100644 src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeResponse.cs create mode 100644 src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/CancelCheckResultDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/CancelCheckResultDto.cs index aa4c7f36a..83cbc9d1d 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/CancelCheckResultDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/CancelCheckResultDto.cs @@ -2,11 +2,12 @@ namespace CAServer.CAAccount.Dtos; public class CancelCheckResultDto { - + public bool ValidatedAssets { get; set; } - public bool ValidatedGuardian { get; set; } + public bool ValidatedGuardian { get; set; } public bool ValidatedDevice { get; set; } + } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs index c12257a09..282ada71e 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs @@ -4,5 +4,7 @@ namespace CAServer.CAAccount.Dtos; public class RevokeDto { - [Required] public string AppleToken { get; set; } + public string AppleToken { get; set; } + + } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAAccount/ICAAccountAppService.cs b/src/CAServer.Application.Contracts/CAAccount/ICAAccountAppService.cs index f5a71fc28..ac29f1807 100644 --- a/src/CAServer.Application.Contracts/CAAccount/ICAAccountAppService.cs +++ b/src/CAServer.Application.Contracts/CAAccount/ICAAccountAppService.cs @@ -14,4 +14,6 @@ public interface ICAAccountAppService Task RevokeAsync(RevokeDto input); Task CheckManagerCountAsync(string caHash); Task AuthorizeDelegateAsync(AssignProjectDelegateeRequestDto input); + Task RevokeAccountAsync(RevokeAccountInput input); + Task RevokeValidateAsync(Guid userId, string type); } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs b/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs new file mode 100644 index 000000000..235ca239f --- /dev/null +++ b/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs @@ -0,0 +1,18 @@ +using System; +using CAServer.Verifier; + +namespace CAServer.CAAccount; + +public class RevokeAccountInput +{ + public string Token { get; set; } + public string Identifier { get; set; } + + public Guid VerifierSessionId { get; set; } + + public string VerifierId { get; set; } + + public string ChainId { get; set; } + public string Type { get; set; } + +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Commons/ResponseMessage.cs b/src/CAServer.Application.Contracts/Commons/ResponseMessage.cs index 6435ccff6..132a207db 100644 --- a/src/CAServer.Application.Contracts/Commons/ResponseMessage.cs +++ b/src/CAServer.Application.Contracts/Commons/ResponseMessage.cs @@ -4,6 +4,8 @@ public static class ResponseMessage { public const string AlreadyDeleted = "User already deleted"; public const string AppleLoginGuardiansExceed = "Login guardian exceed"; + public const string LoginGuardianNotExists = "Login guardian not exists"; public const string ValidFail = "Revoke valid fail"; public const string AppleIdVerifyFail = "Apple id verify fail"; + } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs new file mode 100644 index 000000000..af3f362e4 --- /dev/null +++ b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs @@ -0,0 +1,6 @@ +namespace CAServer.Contacts; + +public class ContactLabelDto +{ + public InvitationPermissionsEnum InvitationPermissionsEnum { get; set; } = InvitationPermissionsEnum.NoBody; +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs b/src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs new file mode 100644 index 000000000..1b07d2fe8 --- /dev/null +++ b/src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs @@ -0,0 +1,8 @@ +namespace CAServer.Contacts; + +public enum InvitationPermissionsEnum +{ + NoBody = 0, + Friends = 1, + AnyBody = 2 +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs b/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs index efa734ec3..36c97dd60 100644 --- a/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs +++ b/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs @@ -20,4 +20,5 @@ public interface IContactAppService Task> GetNameAsync(List input); Task> GetContactListAsync(ContactListRequestDto input); Task> GetContactsByUserIdAsync(Guid userId); + Task> InvitationPermission(Guid? userId, ContactLabelDto contactLabelDto); } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs b/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs index 600529d43..b99388e28 100644 --- a/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs +++ b/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs @@ -10,5 +10,6 @@ public interface IGoogleAppService Task IsGoogleRecaptchaTokenValidAsync(string recaptchatoken, PlatformType platformType = PlatformType.WEB); Task ValidateTokenAsync(string rcToken, string acToken, PlatformType platformType = PlatformType.WEB); - + Task VerifyGoogleTokenAsync(string token); + } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/IVerifierAppService.cs b/src/CAServer.Application.Contracts/Verifier/IVerifierAppService.cs index 90fac4f50..c5e2102d0 100644 --- a/src/CAServer.Application.Contracts/Verifier/IVerifierAppService.cs +++ b/src/CAServer.Application.Contracts/Verifier/IVerifierAppService.cs @@ -17,4 +17,5 @@ public interface IVerifierAppService public Task VerifyTelegramTokenAsync(VerifyTokenRequestDto requestDto); public Task VerifyFacebookTokenAsync(VerifyTokenRequestDto requestDto); Task VerifyTwitterTokenAsync(VerifyTokenRequestDto requestDto); + } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/OperationType.cs b/src/CAServer.Application.Contracts/Verifier/OperationType.cs index 0f0cd428f..82d4b9ce5 100644 --- a/src/CAServer.Application.Contracts/Verifier/OperationType.cs +++ b/src/CAServer.Application.Contracts/Verifier/OperationType.cs @@ -13,5 +13,6 @@ public enum OperationType Approve = 8, ModifyTransferLimit = 9, GuardianApproveTransfer = 10, - UnSetLoginAccount = 11 + UnSetLoginAccount = 11, + RevokeAccount = 12 } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs b/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs new file mode 100644 index 000000000..eb4bb3a0b --- /dev/null +++ b/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs @@ -0,0 +1,14 @@ +namespace CAServer.Verifier; + +public class SendRevokeCodeInput +{ + public string GuardianIdentifier { get; set; } + + public string ChainId{ get; set; } + + public string Type { get; set; } + + public string VerifierId { get; set; } + + +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs b/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs new file mode 100644 index 000000000..3b29c6be4 --- /dev/null +++ b/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs @@ -0,0 +1,10 @@ +using System; + +namespace CAServer.Verifier; + +public class SendRevokeCodeResponse +{ + public Guid VerifierSessionId { get; set; } + + public string VerifierId { get; set; } +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeInput.cs b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeInput.cs new file mode 100644 index 000000000..72750bc2b --- /dev/null +++ b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeInput.cs @@ -0,0 +1,19 @@ +using System; + +namespace CAServer.Verifier; + +public class VerifyRevokeCodeInput +{ + public Guid VerifierSessionId { get; set; } + + public string VerifierId { get; set; } + + public string ChainId { get; set; } + + public string VerifyCode { get; set; } + + public string GuardianIdentifier { get; set; } + + public string Type { get; set; } + +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs new file mode 100644 index 000000000..e24c9c055 --- /dev/null +++ b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs @@ -0,0 +1,12 @@ +using System; + +namespace CAServer.Verifier; + +public class VerifyRevokeCodeRequest +{ + + public Guid VerifierSessionId { get; set; } + public string VerifyCode { get; set; } + + public string ChainId { get; set; } +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeResponse.cs b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeResponse.cs new file mode 100644 index 000000000..4b1b63420 --- /dev/null +++ b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeResponse.cs @@ -0,0 +1,6 @@ +namespace CAServer.Verifier; + +public class VerifyRevokeCodeResponse +{ + public bool Success { get; set; } +} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs b/src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs new file mode 100644 index 000000000..6ab8fad3f --- /dev/null +++ b/src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; +using CAServer.CAAccount; + +namespace CAServer.VerifyToken; + +public interface IVerifyTokenStrategy +{ + string Type { get; } + + Task VerifyRevokeToken(RevokeAccountInput input); + +} \ No newline at end of file diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index f91a5a74e..52d3855e5 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using AElf; using AElf.Types; using CAServer.AppleAuth.Provider; using CAServer.CAAccount.Dtos; @@ -19,11 +20,12 @@ using CAServer.Options; using CAServer.UserAssets; using CAServer.UserAssets.Provider; -using Microsoft.AspNetCore.Http; +using CAServer.Verifier; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Orleans; +using Portkey.Contracts.CA; using Volo.Abp; using Volo.Abp.Auditing; using Volo.Abp.EventBus.Distributed; @@ -51,19 +53,21 @@ public class CAAccountAppService : CAServerAppService, ICAAccountAppService private const int MaxResultCount = 10; public const string DefaultSymbol = "ELF"; public const double MinBanlance = 0.05 * 100000000; + private readonly IVerifierServerClient _verifierServerClient; public CAAccountAppService(IClusterClient clusterClient, IDistributedEventBus distributedEventBus, - ILogger logger, - IDeviceAppService deviceAppService, + ILogger logger, + IDeviceAppService deviceAppService, IOptions chainOptions, IGuardianProvider guardianProvider, - IContractProvider contractProvider, + IContractProvider contractProvider, IUserAssetsProvider userAssetsProvider, ICAAccountProvider accountProvider, INickNameAppService caHolderAppService, - IAppleAuthProvider appleAuthProvider, - IOptionsSnapshot managerCountLimitOptions) + IAppleAuthProvider appleAuthProvider, + IOptionsSnapshot managerCountLimitOptions, + IVerifierServerClient verifierServerClient) { _distributedEventBus = distributedEventBus; _clusterClient = clusterClient; @@ -75,6 +79,7 @@ public CAAccountAppService(IClusterClient clusterClient, _caHolderAppService = caHolderAppService; _accountProvider = accountProvider; _appleAuthProvider = appleAuthProvider; + _verifierServerClient = verifierServerClient; _managerCountLimitOptions = managerCountLimitOptions.Value; _chainOptions = chainOptions.Value; } @@ -188,16 +193,13 @@ public async Task RevokeEntranceAsync() } var loginGuardians = guardianInfo.GuardianList.Guardians.Where(g => g.IsLoginGuardian).ToList(); - var appleLoginGuardians = loginGuardians - .Where(g => g.Type.Equals(((int)GuardianIdentifierType.Apple).ToString())).ToList(); - resultDto.EntranceDisplay = appleLoginGuardians.Count == 1 && loginGuardians.Count == 1; - + resultDto.EntranceDisplay = loginGuardians.Count == 1; return resultDto; } public async Task RevokeCheckAsync(Guid uid) { - var caHolderIndex = await _userAssetsProvider.GetCaHolderIndexAsync(uid); + var caHolderIndex = await _userAssetsProvider.GetCaHolderIndexAsync(uid); var caHash = caHolderIndex.CaHash; var caAddressInfos = new List(); foreach (var chainId in _chainOptions.ChainInfos.Select(key => _chainOptions.ChainInfos[key.Key]) @@ -339,8 +341,9 @@ public async Task RevokeAsync(RevokeDto input) public async Task AuthorizeDelegateAsync(AssignProjectDelegateeRequestDto input) { - Logger.LogInformation("Authorize Delegate : param is {input}",JsonConvert.SerializeObject(input)); - var assignProjectDelegateeDto = ObjectMapper.Map(input); + Logger.LogInformation("Authorize Delegate : param is {input}", JsonConvert.SerializeObject(input)); + var assignProjectDelegateeDto = + ObjectMapper.Map(input); var transactionResult = await _contractProvider.AuthorizeDelegateAsync(assignProjectDelegateeDto); return new AuthorizeDelegateResultDto { @@ -348,6 +351,148 @@ public async Task AuthorizeDelegateAsync(AssignProje }; } + public async Task RevokeAccountAsync(RevokeAccountInput input) + { + var validateResult = await RevokeValidateAsync(CurrentUser.GetId(), input.Type); + if (!validateResult.ValidatedDevice || !validateResult.ValidatedAssets || !validateResult.ValidatedGuardian) + { + Logger.LogInformation( + "{message}, validateDevice:{validateDevice},validatedAssets:{validatedAssets},validateGuardian{validateGuardian}", + ResponseMessage.ValidFail, validateResult.ValidatedDevice, validateResult.ValidatedAssets, + validateResult.ValidatedGuardian); + + throw new UserFriendlyException(ResponseMessage.ValidFail); + } + + var revokeCodeInput = new VerifyRevokeCodeInput + { + VerifierId = input.VerifierId, + VerifierSessionId = input.VerifierSessionId, + Type = input.Type, + GuardianIdentifier = input.Identifier, + VerifyCode = input.Token, + ChainId = input.ChainId + }; + try + { + var verifyRevokeToken = await _verifierServerClient.VerifyRevokeCodeAsync(revokeCodeInput); + if (verifyRevokeToken) + { + await DeleteGuardianAsync(input.Identifier); + await _caHolderAppService.DeleteAsync(); + } + + return new RevokeResultDto + { + Success = verifyRevokeToken + }; + } + catch (Exception e) + { + _logger.LogError(e, "Revoke token failed:{error}", e.Message); + return new RevokeResultDto + { + Success = false + }; + } + } + + public async Task RevokeValidateAsync(Guid userId, string type) + { + var caHolderIndex = await _userAssetsProvider.GetCaHolderIndexAsync(userId); + if (caHolderIndex.IsDeleted) + { + throw new UserFriendlyException(ResponseMessage.AlreadyDeleted); + } + + var caHash = caHolderIndex.CaHash; + var caAddressInfos = new List(); + var caHolderDic = new Dictionary(); + var originChainId = 0; + foreach (var chainId in _chainOptions.ChainInfos.Select(key => _chainOptions.ChainInfos[key.Key]) + .Select(chainOptionsChainInfo => chainOptionsChainInfo.ChainId)) + { + try + { + var result = await _contractProvider.GetHolderInfoAsync(Hash.LoadFromHex(caHash), null, chainId); + if (result == null) + { + continue; + } + + caHolderDic.Add(chainId, result); + if (result.CreateChainId > 0) + { + originChainId = result.CreateChainId; + } + + caAddressInfos.Add(new CAAddressInfo + { + CaAddress = result.CaAddress.ToBase58(), + ChainId = chainId + }); + } + catch (Exception e) + { + Logger.LogError(e, "get holder from chain error, userId:{userId}, caHash:{caHash}", userId.ToString(), + caHash); + } + } + + + + var validateAssets = await ValidateAssertsAsync(caAddressInfos); + + + var validateDevice = false; + var chainIdBase58 = ChainHelper.ConvertChainIdToBase58(originChainId); + caHolderDic.TryGetValue(chainIdBase58, out var holderInfo); + if (holderInfo != null && holderInfo.ManagerInfos.Count > 1) + { + validateDevice = true; + } + + + var validateGuardian = false; + if (holderInfo != null) + { + var guardians = holderInfo.GuardianList.Guardians.Where(t => t.IsLoginGuardian).ToList(); + if (guardians.Count > 1) + { + validateGuardian = true; + } + + + + var guardian = guardians.FirstOrDefault(t => (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType),type)); + if (guardian == null) + { + throw new Exception(ResponseMessage.LoginGuardianNotExists); + } + } + + + var currentGuardian = + holderInfo?.GuardianList.Guardians.FirstOrDefault(t => t.IsLoginGuardian && (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType),type)); + if (currentGuardian != null) + { + var caHolderDto = + await _accountProvider.GetGuardianAddedCAHolderAsync(currentGuardian.IdentifierHash.ToHex(), 0, + MaxResultCount); + if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count > 1) + { + validateGuardian = true; + } + } + + return new CancelCheckResultDto + { + ValidatedDevice = validateDevice, + ValidatedAssets = validateAssets, + ValidatedGuardian = validateGuardian, + }; + } + public async Task CheckManagerCountAsync(string caHash) { var guardiansDto = await _guardianProvider.GetGuardiansAsync(null, caHash); @@ -355,8 +500,10 @@ public async Task CheckManagerCountAsync(string caHa { throw new UserFriendlyException("CAHolder is not exist."); } + var guardianDto = guardiansDto.CaHolderInfo.FirstOrDefault(); - _logger.LogInformation("Current manager count: {count},Limit count is {Limitcount}", guardianDto?.ManagerInfos.Count,_managerCountLimitOptions.Limit); + _logger.LogInformation("Current manager count: {count},Limit count is {Limitcount}", + guardianDto?.ManagerInfos.Count, _managerCountLimitOptions.Limit); var checkManagerCount = guardianDto?.ManagerInfos.Count >= _managerCountLimitOptions.Limit; return new CheckManagerCountResultDto { @@ -364,6 +511,68 @@ public async Task CheckManagerCountAsync(string caHa }; } + private async Task ValidateAssertsAsync(List caAddressInfos) + { + var validateAssets = false; + var tokenRes = await _userAssetsProvider.GetUserTokenInfoAsync(caAddressInfos, DefaultSymbol, + 0, MaxResultCount); + + if (tokenRes.CaHolderTokenBalanceInfo.Data.Count > 0) + { + var tokenInfos = tokenRes.CaHolderTokenBalanceInfo.Data + .Where(o => o.Balance >= MinBanlance).ToList(); + if (tokenInfos.Count > 0) + { + validateAssets = true; + } + } + + var res = await _userAssetsProvider.GetUserNftInfoAsync(caAddressInfos, + null, 0, MaxResultCount); + if (res.CaHolderNFTBalanceInfo.Data.Count > 0) + { + validateAssets = true; + } + + return validateAssets; + } + + private async Task ValidateGuardianAsync(GetHolderInfoOutput holderInfo, string type) + { + var validateGuardian = true; + if (holderInfo != null) + { + var guardians = holderInfo.GuardianList.Guardians.Where(t => t.IsLoginGuardian).ToList(); + if (guardians.Count > 1) + { + validateGuardian = false; + } + + var guardian = guardians.FirstOrDefault(t => Enum.GetName(t.Type) == type); + if (guardian == null) + { + throw new Exception(ResponseMessage.LoginGuardianNotExists); + } + } + + + var currentGuardian = + holderInfo?.GuardianList.Guardians.FirstOrDefault(t => t.IsLoginGuardian && Enum.GetName(t.Type) == type); + if (currentGuardian != null) + { + var caHolderDto = + await _accountProvider.GetGuardianAddedCAHolderAsync(currentGuardian.IdentifierHash.ToHex(), 0, + MaxResultCount); + if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count < 2) + { + validateGuardian = false; + } + } + + return validateGuardian; + } + + private async Task> GetGuardianAsync(string caHash) { var holderInfo = await _guardianProvider.GetGuardiansAsync(null, caHash); diff --git a/src/CAServer.Application/Contacts/ContactAppService.cs b/src/CAServer.Application/Contacts/ContactAppService.cs index a200a9542..43c069772 100644 --- a/src/CAServer.Application/Contacts/ContactAppService.cs +++ b/src/CAServer.Application/Contacts/ContactAppService.cs @@ -697,6 +697,11 @@ public async Task> GetContactsByUserIdAsync(Guid userId) return ObjectMapper.Map, List>(contacts); } + public Task> InvitationPermission(Guid? userId, ContactLabelDto contactLabelDto) + { + throw new NotImplementedException(); + } + private async Task CheckContactAsync(ContactDto contact) { if (contact.ImInfo != null && contact.CaHolderInfo == null) diff --git a/src/CAServer.Application/Google/GoogleAppService.cs b/src/CAServer.Application/Google/GoogleAppService.cs index 8e4f7ab19..ebc10c1cd 100644 --- a/src/CAServer.Application/Google/GoogleAppService.cs +++ b/src/CAServer.Application/Google/GoogleAppService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Linq; +using System.Net; using System.Net.Http; using System.Threading.Tasks; using CAServer.Cache; @@ -10,6 +11,7 @@ using CAServer.Signature.Options; using CAServer.Signature.Provider; using CAServer.Verifier; +using CAServer.Verifier.Dtos; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; @@ -150,6 +152,31 @@ public async Task ValidateTokenAsync(string rcToken, stri } } + public async Task VerifyGoogleTokenAsync(string accessToken) + { + var requestUrl = $"https://www.googleapis.com/oauth2/v2/userinfo?access_token={accessToken}"; + + var client = _httpClientFactory.CreateClient(); + var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUrl)); + + var result = await response.Content.ReadAsStringAsync(); + if (response.StatusCode == HttpStatusCode.Unauthorized || !response.IsSuccessStatusCode) + { + _logger.LogError("{Message}", response.ToString()); + return false; + } + + _logger.LogInformation("GetUserInfo from google: {userInfo}", result); + var googleUserInfo = JsonConvert.DeserializeObject(result); + if (googleUserInfo != null) + { + return true; + } + + _logger.LogError("Get userInfo from google fail."); + return false; + } + public async Task VerifyAppCheckTokenAsync(string token) { if (string.IsNullOrEmpty(token)) diff --git a/src/CAServer.Application/Verifier/IVerifierServerClient.cs b/src/CAServer.Application/Verifier/IVerifierServerClient.cs index 983375177..f41f6be6e 100644 --- a/src/CAServer.Application/Verifier/IVerifierServerClient.cs +++ b/src/CAServer.Application/Verifier/IVerifierServerClient.cs @@ -23,4 +23,6 @@ Task>> VerifyTelegramTok Task> VerifyTwitterTokenAsync(VerifyTokenRequestDto input, string identifierHash, string salt); + + Task VerifyRevokeCodeAsync(VerifyRevokeCodeInput input); } \ No newline at end of file diff --git a/src/CAServer.Application/Verifier/VerifierAppService.cs b/src/CAServer.Application/Verifier/VerifierAppService.cs index cdc8d7b14..b2e89ad59 100644 --- a/src/CAServer.Application/Verifier/VerifierAppService.cs +++ b/src/CAServer.Application/Verifier/VerifierAppService.cs @@ -289,6 +289,13 @@ await AddUserInfoAsync( } } + + public async Task VerifyRevokeCodeAsync(VerifyRevokeCodeInput input) + { + return await _verifierServerClient.VerifyRevokeCodeAsync(input); + + } + private async Task GetTwitterUserIdAsync(string accessToken) { var header = new Dictionary @@ -678,9 +685,3 @@ private string GetTelegramUserId(string identityToken) } } } - -public class GenerateSignatureOutput -{ - public string Data { get; set; } - public string Signature { get; set; } -} \ No newline at end of file diff --git a/src/CAServer.Application/Verifier/VerifierServerClient.cs b/src/CAServer.Application/Verifier/VerifierServerClient.cs index 54e52151b..cd822e204 100644 --- a/src/CAServer.Application/Verifier/VerifierServerClient.cs +++ b/src/CAServer.Application/Verifier/VerifierServerClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Net.Mime; using System.Text; @@ -25,18 +26,20 @@ public class VerifierServerClient : IDisposable, IVerifierServerClient, ISinglet private readonly ILogger _logger; private readonly IHttpClientFactory _httpClientFactory; private readonly IAccelerateManagerProvider _accelerateManagerProvider; + private readonly IContractProvider _contractProvider; public VerifierServerClient(IOptionsSnapshot adaptableVariableOptions, IGetVerifierServerProvider getVerifierServerProvider, ILogger logger, - IHttpClientFactory httpClientFactory, IAccelerateManagerProvider accelerateManagerProvider) + IHttpClientFactory httpClientFactory, IAccelerateManagerProvider accelerateManagerProvider, IContractProvider contractProvider) { _getVerifierServerProvider = getVerifierServerProvider; _logger = logger; _httpService = new HttpService(adaptableVariableOptions.Value.HttpConnectTimeOut, httpClientFactory, true); _httpClientFactory = httpClientFactory; _accelerateManagerProvider = accelerateManagerProvider; + _contractProvider = contractProvider; } private bool _disposed; @@ -174,6 +177,31 @@ public async Task> VerifyTwitterTokenAs return await GetResultAsync(input, requestUri, identifierHash, salt); } + + public async Task VerifyRevokeCodeAsync(VerifyRevokeCodeInput input) + { + //var endPoint = await _getVerifierServerProvider.GetVerifierServerEndPointsAsync(input.VerifierId, input.ChainId); + var endPoint = "http://127.0.0.1:5002"; + _logger.LogInformation("EndPiont is {endPiont} :", endPoint); + if (null == endPoint) + { + _logger.LogInformation("No Available Service Tips.{verifierId}", input.VerifierId); + return false; + } + + var url = endPoint + "/api/app/account/verifyRevokeCode"; + var parameters = new Dictionary + { + { "guardianIdentifier", input.GuardianIdentifier }, + { "verifyCode", input.VerifyCode }, + { "verifierSessionId", input.VerifierSessionId.ToString()}, + { "type", input.Type}, + }; + var response = await _httpService.PostResponseAsync(url, parameters); + return response.Success; + + } + private async Task> GetResultAsync(VerifyTokenRequestDto input, string requestUri, string identifierHash, string salt) { diff --git a/src/CAServer.ContractEventHandler/appsettings.json b/src/CAServer.ContractEventHandler/appsettings.json index 403c5f067..0968921d5 100644 --- a/src/CAServer.ContractEventHandler/appsettings.json +++ b/src/CAServer.ContractEventHandler/appsettings.json @@ -2,34 +2,83 @@ "RabbitMQ": { "Connections": { "Default": { - "HostName": "127.0.0.1", - "Port": "5672" + "HostName": "192.168.66.53", + "Port": "5672", + "UserName": "admin", + "Password": "admin123456" } }, "EventBus": { - "ClientName": "ContractEventHandler", - "ExchangeName": "Exchange" + "ClientName": "ContractService", + "ExchangeName": "CAAccount" } }, "ConnectionStrings": { - "Default": "mongodb://admin:admin123@127.0.0.1:27017/CAServer" - }, - "Serilog": { - "MinimumLevel": { - "Default": "Debug", - "Override": { - "Default": "Warning", - "System": "Warning", - "Microsoft": "Warning", + "Default": "mongodb://localhost:27017/CAServer" + }, + "Redis": { + "Configuration": "192.168.66.53" + }, + "Serilog":{ + "Using":[ + "Serilog.Expressions" + ], + "MinimumLevel":{ + "Default":"Debug", + "Override":{ + "Default":"Warning", + "System":"Warning", + "Microsoft":"Warning", "Quartz": "Warning" } }, - "WriteTo": [ + "WriteTo":[ { - "Name": "RollingFile", - "Args": { - "pathFormat": "Logs/log-{Date}.log", - "retainedFileCountLimit": 15 + "Name":"Logger", + "Args":{ + "ConfigureLogger":{ + "WriteTo":[ + { + "Name":"RollingFile", + "Args":{ + "pathFormat":"Logs/log-{Date}.log", + "retainedFileCountLimit":10 + } + } + ], + "Filter":[ + { + "Name":"ByExcluding", + "Args":{ + "expression":"StartsWith(SourceContext, 'CAServer.Monitor.Logger.MonitorLogger')" + } + } + ] + } + } + }, + { + "Name":"Logger", + "Args":{ + "ConfigureLogger":{ + "WriteTo":[ + { + "Name":"RollingFile", + "Args":{ + "pathFormat":"Logs/monitor-{Date}.log", + "retainedFileCountLimit":10 + } + } + ], + "Filter":[ + { + "Name":"ByIncludingOnly", + "Args":{ + "expression":"StartsWith(SourceContext, 'CAServer.Monitor.Logger.MonitorLogger')" + } + } + ] + } } } ] @@ -38,22 +87,24 @@ "ChainInfos": { "AELF": { "ChainId": "AELF", - "BaseUrl": "http://127.0.0.1:8000", - "ContractAddress": "***", - "TokenContractAddress": "***", - "CrossChainContractAddress": "***", - "RedPackageContractAddress": "***", - "PrivateKey": "***", + "BaseUrl": "http://192.168.66.123:8000", + "ContractAddress": "SzX8Drm7719hZ4bSqM7jQ5va37BKepqiusfyPjkVdZEA4gvcs", + "TokenContractAddress": "JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE", + "CrossChainContractAddress": "2SQ9LeGZYSWmfJcYuQkDQxgd3HzwjamAaaL4Tge2eFSXw2cseq", + "RedPackageContractAddress": "2UM9eusxdRyCztbmMZadGXzwgwKfFdk8pF4ckw58D769ehaPSR", + "PublicKey": "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e", + "PrivateKey": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2", "IsMainChain": true }, "tDVV": { "ChainId": "tDVV", - "BaseUrl": "http://127.0.0.1:8000", - "ContractAddress": "***", - "TokenContractAddress": "***", - "CrossChainContractAddress": "***", - "RedPackageContractAddress": "***", - "PrivateKey": "***", + "BaseUrl": "http://192.168.66.60:8000", + "ContractAddress": "SzX8Drm7719hZ4bSqM7jQ5va37BKepqiusfyPjkVdZEA4gvcs", + "TokenContractAddress": "7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX", + "CrossChainContractAddress": "2snHc8AMh9QMbCAa7XXmdZZVM5EBZUUPDdLjemwUJkBnL6k8z9", + "RedPackageContractAddress": "jvhrvLGJ29ZzoLSQyUmKGL51NNvYjaHDqcuCpF481139mdxd2", + "PublicKey": "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e", + "PrivateKey": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2", "IsMainChain": false } } @@ -68,57 +119,66 @@ "IndexBefore": 200, "indexAfter": 400, "AutoSyncStartHeight": { - "AELF": 5743, - "tDVV": 3295 + "AELF": 5586826, + "tDVV": 5584084 } }, "GraphQL": { - "GraphQLConnection": "http://127.0.0.1:8083/Indexer_DApp/PortKeyIndexerCASchema/graphql" + "Configuration": "http://192.168.67.214:8084/AElfIndexer_DApp_V2/PortKeyIndexerCASchema/graphql" }, - "Sync": { + "Sync" : { "Sync": 30, "AutoReceive": 60 }, "Orleans": { "ClusterId": "CAServerSiloCluster", "ServiceId": "CAServerOrleansBasicService", - "MongoDBClient": "mongodb://127.0.0.1:27017/?maxPoolSize=555", + "MongoDBClient": "mongodb://localhost:27017/CAServer", "DataBase": "CAServerOrleansDB", "ResponseTimeout":60 }, "CrossChain": { "AutoReceiveStartHeight": { - "AELF": 5743, - "tDVV": 3295 + "AELF": 15231922, + "tDVV": 15203857 } }, - "Redis": { - "Configuration": "127.0.0.1" + "SignatureServer_bak": { + "BaseUrl": "http://192.168.66.117:18080/api/app/signature" }, "SignatureServer": { - "BaseUrl": "http://127.0.0.1:18080/api/app/signature" + "BaseUrl": "http://192.168.66.122:18080", + "AppId": "caserver", + "AppSecret": "12345678" }, "ContractOptions": { "CommonPrivateKeyForCallTx": "aee9944b684505b51c2eefc54b6735453160a74f27c158df65d2783fafa81e57" }, "ElasticUris": { "Uris": [ - "http://127.0.0.1:9200" + "http://192.168.66.201:9200" ] }, + "IndexSetting": { + "NumberOfShards": 5, + "NumberOfReplicas": 1, + "IndexPrefix": "CAServer" + }, "Indicator":{ "IsEnabled":true, "Application":"PortKey", "Module":"CAServer.ContractEventHandler" }, "Hangfire" : { + "ConnectionString": "mongodb://admin:admin123456@192.168.66.216:27017/CAServerContractHangfire?authSource=admin", "Redis": { - "ConnectionString": "127.0.0.1:6379" + "ConnectionString": "192.168.66.53:6379" }, - "redpackage":8 + "redpackage":1 }, "RedPackage":{ "maxCount":1000, + "ExpireTimeMs": 300000, "tokenInfo":[ { "chainId":"AELF", @@ -167,17 +227,29 @@ "symbol":"DISK", "decimal":8, "minAmount":"1" + }, + { + "chainId":"AELF", + "symbol":"USDT", + "decimal":6, + "minAmount":"1" + }, + { + "chainId":"tDVV", + "symbol":"USDT", + "decimal":6, + "minAmount":"1" } ], "RedPackageContractAddress":[ { "chainId": "AELF", - "contractAddress": "***" + "contractAddress": "2UM9eusxdRyCztbmMZadGXzwgwKfFdk8pF4ckw58D769ehaPSR" }, { "chainId": "tDVV", - "contractAddress": "***" + "contractAddress":"jvhrvLGJ29ZzoLSQyUmKGL51NNvYjaHDqcuCpF481139mdxd2" } ] }, @@ -185,7 +257,11 @@ { "RedPackagePayAccounts": [ - "***" + "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e", + "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e" ] + }, + "ImServer": { + "BaseUrl": "http://192.168.66.117:5007/" } } \ No newline at end of file diff --git a/src/CAServer.HttpApi/Controllers/CAAccountController.cs b/src/CAServer.HttpApi/Controllers/CAAccountController.cs index fb2cfe665..6c2b8d81b 100644 --- a/src/CAServer.HttpApi/Controllers/CAAccountController.cs +++ b/src/CAServer.HttpApi/Controllers/CAAccountController.cs @@ -86,7 +86,7 @@ public async Task RevokeAsync(RevokeDto input) { return await _caAccountService.RevokeAsync(input); } - + [HttpGet("checkManagerCount")] public async Task CheckManagerCountAsync(string caHash) { @@ -99,5 +99,19 @@ public async Task GetRedirectUrlAsync(string shortLinkCode) var url = await _growthAppService.GetRedirectUrlAsync(shortLinkCode); return Redirect(url); } + + [HttpPost("revoke/account"), Authorize, IgnoreAntiforgeryToken] + public async Task RevokeAccountAsync(RevokeAccountInput input) + { + return await _caAccountService.RevokeAccountAsync(input); + } + + [HttpGet("revoke/validate")] + [Authorize] + public async Task RevokeValidateAsync(string type) + { + var userId = _currentUser.Id ?? throw new UserFriendlyException("User not found"); + return await _caAccountService.RevokeValidateAsync(userId, type); + } } \ No newline at end of file diff --git a/src/CAServer.HttpApi/Controllers/CAVerifierController.cs b/src/CAServer.HttpApi/Controllers/CAVerifierController.cs index 714f791d5..364a71807 100644 --- a/src/CAServer.HttpApi/Controllers/CAVerifierController.cs +++ b/src/CAServer.HttpApi/Controllers/CAVerifierController.cs @@ -50,7 +50,6 @@ public CAVerifierController(IVerifierAppService verifierAppService, IObjectMappe [HttpPost("sendVerificationRequest")] public async Task SendVerificationRequest([FromHeader] string recaptchatoken, - [FromHeader] string version, [FromHeader] string acToken, VerifierServerInput verifierServerInput) { @@ -272,6 +271,7 @@ public async Task GetVerifierServerAsync(GetVerifierS { return await _verifierAppService.GetVerifierServerAsync(input.ChainId); } + private string UserIpAddress(HttpContext context) diff --git a/src/CAServer.HttpApi/Controllers/ContactController.cs b/src/CAServer.HttpApi/Controllers/ContactController.cs index d301acb0b..700d263c1 100644 --- a/src/CAServer.HttpApi/Controllers/ContactController.cs +++ b/src/CAServer.HttpApi/Controllers/ContactController.cs @@ -89,4 +89,16 @@ public async Task> GetContactsByUserIdAsync(Guid userId) { return await _contactAppService.GetContactsByUserIdAsync(userId); } + + [HttpPost("invitationPermission")] + public async Task> ContactsInvitationPermission(ContactLabelDto contactLabelDto) + { + var userId = CurrentUser.Id; + if (null == userId) + { + throw new UserFriendlyException("Invalidate User"); + } + + return await _contactAppService.InvitationPermission(userId,contactLabelDto); + } } \ No newline at end of file From 83b96c16b4e670b459f79fbe8f7cdee7da764ef9 Mon Sep 17 00:00:00 2001 From: wangyue Date: Thu, 18 Apr 2024 11:02:56 +0800 Subject: [PATCH 02/14] feat:update field name --- .../CAAccount/RevokeAccountInput.cs | 2 +- .../CAAccount/CAAccountAppService.cs | 21 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs b/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs index 235ca239f..35c567721 100644 --- a/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs +++ b/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs @@ -6,7 +6,7 @@ namespace CAServer.CAAccount; public class RevokeAccountInput { public string Token { get; set; } - public string Identifier { get; set; } + public string GuardianIdentifier { get; set; } public Guid VerifierSessionId { get; set; } diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index 52d3855e5..f41959d7a 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -199,7 +199,7 @@ public async Task RevokeEntranceAsync() public async Task RevokeCheckAsync(Guid uid) { - var caHolderIndex = await _userAssetsProvider.GetCaHolderIndexAsync(uid); + var caHolderIndex = await _userAssetsProvider.GetCaHolderIndexAsync(uid); var caHash = caHolderIndex.CaHash; var caAddressInfos = new List(); foreach (var chainId in _chainOptions.ChainInfos.Select(key => _chainOptions.ChainInfos[key.Key]) @@ -354,7 +354,7 @@ public async Task AuthorizeDelegateAsync(AssignProje public async Task RevokeAccountAsync(RevokeAccountInput input) { var validateResult = await RevokeValidateAsync(CurrentUser.GetId(), input.Type); - if (!validateResult.ValidatedDevice || !validateResult.ValidatedAssets || !validateResult.ValidatedGuardian) + if (validateResult.ValidatedDevice || validateResult.ValidatedAssets || validateResult.ValidatedGuardian) { Logger.LogInformation( "{message}, validateDevice:{validateDevice},validatedAssets:{validatedAssets},validateGuardian{validateGuardian}", @@ -369,7 +369,7 @@ public async Task RevokeAccountAsync(RevokeAccountInput input) VerifierId = input.VerifierId, VerifierSessionId = input.VerifierSessionId, Type = input.Type, - GuardianIdentifier = input.Identifier, + GuardianIdentifier = input.GuardianIdentifier, VerifyCode = input.Token, ChainId = input.ChainId }; @@ -378,7 +378,7 @@ public async Task RevokeAccountAsync(RevokeAccountInput input) var verifyRevokeToken = await _verifierServerClient.VerifyRevokeCodeAsync(revokeCodeInput); if (verifyRevokeToken) { - await DeleteGuardianAsync(input.Identifier); + await DeleteGuardianAsync(input.GuardianIdentifier); await _caHolderAppService.DeleteAsync(); } @@ -439,10 +439,7 @@ public async Task RevokeValidateAsync(Guid userId, string } } - - var validateAssets = await ValidateAssertsAsync(caAddressInfos); - var validateDevice = false; var chainIdBase58 = ChainHelper.ConvertChainIdToBase58(originChainId); @@ -452,7 +449,6 @@ public async Task RevokeValidateAsync(Guid userId, string validateDevice = true; } - var validateGuardian = false; if (holderInfo != null) { @@ -461,19 +457,18 @@ public async Task RevokeValidateAsync(Guid userId, string { validateGuardian = true; } - - - var guardian = guardians.FirstOrDefault(t => (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType),type)); + var guardian = + guardians.FirstOrDefault(t => (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType), type)); if (guardian == null) { throw new Exception(ResponseMessage.LoginGuardianNotExists); } } - var currentGuardian = - holderInfo?.GuardianList.Guardians.FirstOrDefault(t => t.IsLoginGuardian && (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType),type)); + holderInfo?.GuardianList.Guardians.FirstOrDefault(t => + t.IsLoginGuardian && (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType), type)); if (currentGuardian != null) { var caHolderDto = From d04365ee3270dd5ca320b9d529c7565b4eb5e9f5 Mon Sep 17 00:00:00 2001 From: wangyue Date: Fri, 19 Apr 2024 17:40:42 +0800 Subject: [PATCH 03/14] feat:user invitation permission --- .../CAAccount/Dtos/CAHolderResultDto.cs | 1 + .../CAAccount/Dtos/HolderInfoDto.cs | 20 +++++++++++-- .../Contacts/Dtos/ContactResultDto.cs | 1 + .../Contacts/Etos/UpdateCAHolderEto.cs | 3 ++ .../Contacts/IContactAppService.cs | 1 - .../Contacts/ContactAppService.cs | 28 +++++++++++++------ .../Entities/Es/CAHolderIndex.cs | 2 ++ .../Grain/Contacts/CAHolderGrain.cs | 7 +++++ .../Grain/Contacts/CAHolderGrainDto.cs | 4 ++- .../State/Account/CAHolderState.cs | 3 ++ .../Controllers/ContactController.cs | 11 -------- 11 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs index 8d9e4a213..09556ebce 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs @@ -2,4 +2,5 @@ namespace CAServer.Dtos; public class CAHolderResultDto : CAHolderDto { + public int InvitationPermission { get; set; } = 0; } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs index b34450090..2e77f3f6b 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs @@ -1,6 +1,10 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Linq.Dynamic.Core; +using CAServer.Contacts; +using Volo.Abp; namespace CAServer.CAAccount.Dtos; @@ -8,15 +12,25 @@ public class HolderInfoDto : IValidatableObject { [MaxLength(16)] public string NickName { get; set; } public string Avatar { get; set; } - + public InvitationPermissionsEnum InvitationPermission { get; set; } public IEnumerable Validate(ValidationContext validationContext) { - if (NickName.IsNullOrWhiteSpace() && Avatar.IsNullOrWhiteSpace()) + var values = Enum.GetValues(typeof(InvitationPermissionsEnum)).ToDynamicList(); + if (!values.Contains(InvitationPermission)) + { + yield return new ValidationResult( + "Invalid input.", + new[] { "InvitationPermission" } + ); + } + + if (NickName.IsNullOrWhiteSpace() && Avatar.IsNullOrWhiteSpace() && + InvitationPermission.ToString().IsNullOrWhiteSpace()) { yield return new ValidationResult( "Invalid input.", - new[] { "NickName", "Avatar" } + new[] { "NickName", "Avatar", "InvitationPermission" } ); } } diff --git a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs index be845f8f6..68279ca8b 100644 --- a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs +++ b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs @@ -2,4 +2,5 @@ namespace CAServer.Contacts; public class ContactResultDto : ContactDto { + public int InvitationPermission { get; set; } } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs b/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs index f57092707..ce7d16e36 100644 --- a/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs +++ b/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs @@ -14,4 +14,7 @@ public class UpdateCAHolderEto public string Avatar { get; set; } public bool IsDeleted { get; set; } public DateTime CreateTime { get; set; } + + public int InvitationPermission { get; set; } + } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs b/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs index 36c97dd60..efa734ec3 100644 --- a/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs +++ b/src/CAServer.Application.Contracts/Contacts/IContactAppService.cs @@ -20,5 +20,4 @@ public interface IContactAppService Task> GetNameAsync(List input); Task> GetContactListAsync(ContactListRequestDto input); Task> GetContactsByUserIdAsync(Guid userId); - Task> InvitationPermission(Guid? userId, ContactLabelDto contactLabelDto); } \ No newline at end of file diff --git a/src/CAServer.Application/Contacts/ContactAppService.cs b/src/CAServer.Application/Contacts/ContactAppService.cs index 43c069772..96815c078 100644 --- a/src/CAServer.Application/Contacts/ContactAppService.cs +++ b/src/CAServer.Application/Contacts/ContactAppService.cs @@ -3,9 +3,11 @@ using System.Linq; using System.Threading.Tasks; using AElf.Types; +using CAServer.CAAccount.Dtos; using CAServer.Common; using CAServer.Commons; using CAServer.Contacts.Provider; +using CAServer.Dtos; using CAServer.Entities.Es; using CAServer.Etos; using CAServer.Grains; @@ -75,7 +77,7 @@ public async Task CreateAsync(CreateUpdateContactDto input) { throw new UserFriendlyException(ContactMessage.ExistedMessage); } - + await CheckAddressAsync(userId, input.Addresses, input.RelationId); var contactDto = await GetContactDtoAsync(input); await CheckContactAsync(contactDto); @@ -389,7 +391,7 @@ await _contactProvider.GetCaHolderInfoAsync(new List { address.Address } { var chainIds = contact.Addresses.Select(t => t.ChainId); var needAddChainIds = _chainOptions.ChainInfos.Keys.Except(chainIds).ToList(); - + foreach (var chainId in needAddChainIds) { contact.Addresses.Add(new ContactAddressDto() @@ -693,15 +695,25 @@ public async Task> GetContactListAsync(ContactListRequest public async Task> GetContactsByUserIdAsync(Guid userId) { - var contacts= await _contactProvider.GetContactsAsync(userId); - return ObjectMapper.Map, List>(contacts); - } + var contacts = await _contactProvider.GetContactsAsync(userId); + var contractList = ObjectMapper.Map, List>(contacts); + if (contacts == null) + { + return contractList; + } - public Task> InvitationPermission(Guid? userId, ContactLabelDto contactLabelDto) - { - throw new NotImplementedException(); + var uIdList = contacts.Select(t => new Guid(t.ImInfo.PortkeyId)).ToList(); + var caHolders = await _contactProvider.GetCaHoldersAsync(uIdList); + var dictionary = caHolders.ToDictionary(t => t.UserId, t => t); + foreach (var dto in contractList) + { + dto.InvitationPermission = dictionary[dto.ImInfo.PortkeyId].InvitationPermission; + } + + return contractList; } + private async Task CheckContactAsync(ContactDto contact) { if (contact.ImInfo != null && contact.CaHolderInfo == null) diff --git a/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs b/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs index dfee16f1c..f817f230b 100644 --- a/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs +++ b/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs @@ -12,4 +12,6 @@ public class CAHolderIndex : CAServerEsEntity, IIndexBuild public string Avatar { get; set; } public bool IsDeleted { get; set; } public DateTime CreateTime { get; set; } + + public int InvitationPermission { get; set; } = 0; } \ No newline at end of file diff --git a/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs b/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs index 4cb0f86b0..563e0fd36 100644 --- a/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs +++ b/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs @@ -1,4 +1,5 @@ using CAServer.CAAccount.Dtos; +using CAServer.Contacts; using CAServer.Grains.State; using Orleans; using Volo.Abp.ObjectMapping; @@ -119,6 +120,12 @@ public async Task> UpdateHolderInfo(HolderInfoD { State.Avatar = holderInfo.Avatar; } + + if (!holderInfo.InvitationPermission.ToString().IsNullOrWhiteSpace()) + { + State.InvitationPermission = (int)holderInfo.InvitationPermission; + } + await WriteStateAsync(); result.Success = true; diff --git a/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs b/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs index d3286004e..94a5f1acd 100644 --- a/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs +++ b/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs @@ -4,4 +4,6 @@ namespace CAServer.Grains.Grain.Contacts; public class CAHolderGrainDto : CAHolderDto { -} \ No newline at end of file + public int InvitationPermission { get; set; } + +} diff --git a/src/CAServer.Grains/State/Account/CAHolderState.cs b/src/CAServer.Grains/State/Account/CAHolderState.cs index 939ad21a4..98453627d 100644 --- a/src/CAServer.Grains/State/Account/CAHolderState.cs +++ b/src/CAServer.Grains/State/Account/CAHolderState.cs @@ -9,4 +9,7 @@ public class CAHolderState public string Avatar { get; set; } public bool IsDeleted { get; set; } public DateTime CreateTime { get; set; } + + public int InvitationPermission { get; set; } + } \ No newline at end of file diff --git a/src/CAServer.HttpApi/Controllers/ContactController.cs b/src/CAServer.HttpApi/Controllers/ContactController.cs index 700d263c1..8e5fa7e31 100644 --- a/src/CAServer.HttpApi/Controllers/ContactController.cs +++ b/src/CAServer.HttpApi/Controllers/ContactController.cs @@ -90,15 +90,4 @@ public async Task> GetContactsByUserIdAsync(Guid userId) return await _contactAppService.GetContactsByUserIdAsync(userId); } - [HttpPost("invitationPermission")] - public async Task> ContactsInvitationPermission(ContactLabelDto contactLabelDto) - { - var userId = CurrentUser.Id; - if (null == userId) - { - throw new UserFriendlyException("Invalidate User"); - } - - return await _contactAppService.InvitationPermission(userId,contactLabelDto); - } } \ No newline at end of file From 1fe86486d902eb08bfaf4f64023495340cca16c9 Mon Sep 17 00:00:00 2001 From: wangyue Date: Mon, 22 Apr 2024 14:55:08 +0800 Subject: [PATCH 04/14] feat:fix validate return value --- .../CAAccount/Dtos/CAHolderResultDto.cs | 1 - .../CAAccount/Dtos/HolderInfoDto.cs | 16 +++--------- .../Contacts/Dtos/ContactLabelDto.cs | 6 ----- .../Contacts/Dtos/ContactResultDto.cs | 1 - .../Dtos/InvitationPermissionsEnum.cs | 8 ------ .../Contacts/Etos/UpdateCAHolderEto.cs | 2 -- .../CAAccount/CAAccountAppService.cs | 16 ++++++------ .../Contacts/ContactAppService.cs | 25 +++---------------- .../Entities/Es/CAHolderIndex.cs | 1 - .../Grain/Contacts/CAHolderGrain.cs | 7 ------ .../Grain/Contacts/CAHolderGrainDto.cs | 1 - .../State/Account/CAHolderState.cs | 2 -- 12 files changed, 15 insertions(+), 71 deletions(-) delete mode 100644 src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs delete mode 100644 src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs index 09556ebce..8d9e4a213 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/CAHolderResultDto.cs @@ -2,5 +2,4 @@ namespace CAServer.Dtos; public class CAHolderResultDto : CAHolderDto { - public int InvitationPermission { get; set; } = 0; } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs index 2e77f3f6b..feac6c636 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs @@ -12,25 +12,15 @@ public class HolderInfoDto : IValidatableObject { [MaxLength(16)] public string NickName { get; set; } public string Avatar { get; set; } - public InvitationPermissionsEnum InvitationPermission { get; set; } public IEnumerable Validate(ValidationContext validationContext) { - var values = Enum.GetValues(typeof(InvitationPermissionsEnum)).ToDynamicList(); - if (!values.Contains(InvitationPermission)) + + if (NickName.IsNullOrWhiteSpace() && Avatar.IsNullOrWhiteSpace()) { yield return new ValidationResult( "Invalid input.", - new[] { "InvitationPermission" } - ); - } - - if (NickName.IsNullOrWhiteSpace() && Avatar.IsNullOrWhiteSpace() && - InvitationPermission.ToString().IsNullOrWhiteSpace()) - { - yield return new ValidationResult( - "Invalid input.", - new[] { "NickName", "Avatar", "InvitationPermission" } + new[] { "NickName", "Avatar"} ); } } diff --git a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs deleted file mode 100644 index af3f362e4..000000000 --- a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactLabelDto.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CAServer.Contacts; - -public class ContactLabelDto -{ - public InvitationPermissionsEnum InvitationPermissionsEnum { get; set; } = InvitationPermissionsEnum.NoBody; -} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs index 68279ca8b..be845f8f6 100644 --- a/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs +++ b/src/CAServer.Application.Contracts/Contacts/Dtos/ContactResultDto.cs @@ -2,5 +2,4 @@ namespace CAServer.Contacts; public class ContactResultDto : ContactDto { - public int InvitationPermission { get; set; } } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs b/src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs deleted file mode 100644 index 1b07d2fe8..000000000 --- a/src/CAServer.Application.Contracts/Contacts/Dtos/InvitationPermissionsEnum.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CAServer.Contacts; - -public enum InvitationPermissionsEnum -{ - NoBody = 0, - Friends = 1, - AnyBody = 2 -} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs b/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs index ce7d16e36..7d8a12fce 100644 --- a/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs +++ b/src/CAServer.Application.Contracts/Contacts/Etos/UpdateCAHolderEto.cs @@ -15,6 +15,4 @@ public class UpdateCAHolderEto public bool IsDeleted { get; set; } public DateTime CreateTime { get; set; } - public int InvitationPermission { get; set; } - } \ No newline at end of file diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index f41959d7a..5c3e2c1a6 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -441,21 +441,21 @@ public async Task RevokeValidateAsync(Guid userId, string var validateAssets = await ValidateAssertsAsync(caAddressInfos); - var validateDevice = false; + var validateDevice = true; var chainIdBase58 = ChainHelper.ConvertChainIdToBase58(originChainId); caHolderDic.TryGetValue(chainIdBase58, out var holderInfo); if (holderInfo != null && holderInfo.ManagerInfos.Count > 1) { - validateDevice = true; + validateDevice = false; } - var validateGuardian = false; + var validateGuardian = true; if (holderInfo != null) { var guardians = holderInfo.GuardianList.Guardians.Where(t => t.IsLoginGuardian).ToList(); if (guardians.Count > 1) { - validateGuardian = true; + validateGuardian = false; } var guardian = @@ -476,7 +476,7 @@ await _accountProvider.GetGuardianAddedCAHolderAsync(currentGuardian.IdentifierH MaxResultCount); if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count > 1) { - validateGuardian = true; + validateGuardian = false; } } @@ -508,7 +508,7 @@ public async Task CheckManagerCountAsync(string caHa private async Task ValidateAssertsAsync(List caAddressInfos) { - var validateAssets = false; + var validateAssets = true; var tokenRes = await _userAssetsProvider.GetUserTokenInfoAsync(caAddressInfos, DefaultSymbol, 0, MaxResultCount); @@ -518,7 +518,7 @@ private async Task ValidateAssertsAsync(List caAddressInfos .Where(o => o.Balance >= MinBanlance).ToList(); if (tokenInfos.Count > 0) { - validateAssets = true; + validateAssets = false; } } @@ -526,7 +526,7 @@ private async Task ValidateAssertsAsync(List caAddressInfos null, 0, MaxResultCount); if (res.CaHolderNFTBalanceInfo.Data.Count > 0) { - validateAssets = true; + validateAssets = false; } return validateAssets; diff --git a/src/CAServer.Application/Contacts/ContactAppService.cs b/src/CAServer.Application/Contacts/ContactAppService.cs index 96815c078..a200a9542 100644 --- a/src/CAServer.Application/Contacts/ContactAppService.cs +++ b/src/CAServer.Application/Contacts/ContactAppService.cs @@ -3,11 +3,9 @@ using System.Linq; using System.Threading.Tasks; using AElf.Types; -using CAServer.CAAccount.Dtos; using CAServer.Common; using CAServer.Commons; using CAServer.Contacts.Provider; -using CAServer.Dtos; using CAServer.Entities.Es; using CAServer.Etos; using CAServer.Grains; @@ -77,7 +75,7 @@ public async Task CreateAsync(CreateUpdateContactDto input) { throw new UserFriendlyException(ContactMessage.ExistedMessage); } - + await CheckAddressAsync(userId, input.Addresses, input.RelationId); var contactDto = await GetContactDtoAsync(input); await CheckContactAsync(contactDto); @@ -391,7 +389,7 @@ await _contactProvider.GetCaHolderInfoAsync(new List { address.Address } { var chainIds = contact.Addresses.Select(t => t.ChainId); var needAddChainIds = _chainOptions.ChainInfos.Keys.Except(chainIds).ToList(); - + foreach (var chainId in needAddChainIds) { contact.Addresses.Add(new ContactAddressDto() @@ -695,25 +693,10 @@ public async Task> GetContactListAsync(ContactListRequest public async Task> GetContactsByUserIdAsync(Guid userId) { - var contacts = await _contactProvider.GetContactsAsync(userId); - var contractList = ObjectMapper.Map, List>(contacts); - if (contacts == null) - { - return contractList; - } - - var uIdList = contacts.Select(t => new Guid(t.ImInfo.PortkeyId)).ToList(); - var caHolders = await _contactProvider.GetCaHoldersAsync(uIdList); - var dictionary = caHolders.ToDictionary(t => t.UserId, t => t); - foreach (var dto in contractList) - { - dto.InvitationPermission = dictionary[dto.ImInfo.PortkeyId].InvitationPermission; - } - - return contractList; + var contacts= await _contactProvider.GetContactsAsync(userId); + return ObjectMapper.Map, List>(contacts); } - private async Task CheckContactAsync(ContactDto contact) { if (contact.ImInfo != null && contact.CaHolderInfo == null) diff --git a/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs b/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs index f817f230b..0dc36e65c 100644 --- a/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs +++ b/src/CAServer.Domain/Entities/Es/CAHolderIndex.cs @@ -13,5 +13,4 @@ public class CAHolderIndex : CAServerEsEntity, IIndexBuild public bool IsDeleted { get; set; } public DateTime CreateTime { get; set; } - public int InvitationPermission { get; set; } = 0; } \ No newline at end of file diff --git a/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs b/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs index 563e0fd36..4cb0f86b0 100644 --- a/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs +++ b/src/CAServer.Grains/Grain/Contacts/CAHolderGrain.cs @@ -1,5 +1,4 @@ using CAServer.CAAccount.Dtos; -using CAServer.Contacts; using CAServer.Grains.State; using Orleans; using Volo.Abp.ObjectMapping; @@ -120,12 +119,6 @@ public async Task> UpdateHolderInfo(HolderInfoD { State.Avatar = holderInfo.Avatar; } - - if (!holderInfo.InvitationPermission.ToString().IsNullOrWhiteSpace()) - { - State.InvitationPermission = (int)holderInfo.InvitationPermission; - } - await WriteStateAsync(); result.Success = true; diff --git a/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs b/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs index 94a5f1acd..25bea5f14 100644 --- a/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs +++ b/src/CAServer.Grains/Grain/Contacts/CAHolderGrainDto.cs @@ -4,6 +4,5 @@ namespace CAServer.Grains.Grain.Contacts; public class CAHolderGrainDto : CAHolderDto { - public int InvitationPermission { get; set; } } diff --git a/src/CAServer.Grains/State/Account/CAHolderState.cs b/src/CAServer.Grains/State/Account/CAHolderState.cs index 98453627d..58099a963 100644 --- a/src/CAServer.Grains/State/Account/CAHolderState.cs +++ b/src/CAServer.Grains/State/Account/CAHolderState.cs @@ -9,7 +9,5 @@ public class CAHolderState public string Avatar { get; set; } public bool IsDeleted { get; set; } public DateTime CreateTime { get; set; } - - public int InvitationPermission { get; set; } } \ No newline at end of file From 0ccff64cb92ee1b4ca44351666f2f10cb68cc6ff Mon Sep 17 00:00:00 2001 From: wangyue Date: Mon, 22 Apr 2024 15:49:33 +0800 Subject: [PATCH 05/14] feat:fix validate result --- src/CAServer.Application/CAAccount/CAAccountAppService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index 5c3e2c1a6..98c3589b7 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -354,7 +354,7 @@ public async Task AuthorizeDelegateAsync(AssignProje public async Task RevokeAccountAsync(RevokeAccountInput input) { var validateResult = await RevokeValidateAsync(CurrentUser.GetId(), input.Type); - if (validateResult.ValidatedDevice || validateResult.ValidatedAssets || validateResult.ValidatedGuardian) + if (!validateResult.ValidatedDevice || !validateResult.ValidatedAssets || !validateResult.ValidatedGuardian) { Logger.LogInformation( "{message}, validateDevice:{validateDevice},validatedAssets:{validatedAssets},validateGuardian{validateGuardian}", From 0ba703ba93b59557679146760e9f1f5b0758a2ad Mon Sep 17 00:00:00 2001 From: wangyue Date: Wed, 24 Apr 2024 11:35:21 +0800 Subject: [PATCH 06/14] feat:remove unused code --- .../CAAccount/Dtos/HolderInfoDto.cs | 3 +- .../CAAccount/Dtos/RevokeDto.cs | 4 +- .../CAAccount/RevokeAccountInput.cs | 4 - .../CAServer.Application.Contracts.csproj | 5 + .../Google/IGoogleAppService.cs | 2 - .../Verifier/SendRevokeCodeInput.cs | 14 -- .../Verifier/SendRevokeCodeResponse.cs | 10 -- .../Verifier/VerifierServerInput.cs | 2 - .../Verifier/VerifyRevokeCodeRequest.cs | 12 -- .../VerifyToken/IVerifyTokenStrategy.cs | 13 -- .../Google/GoogleAppService.cs | 25 --- .../Verifier/VerifierServerClient.cs | 3 +- .../appsettings.json | 168 +++++------------- 13 files changed, 54 insertions(+), 211 deletions(-) delete mode 100644 src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs delete mode 100644 src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs delete mode 100644 src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs delete mode 100644 src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs index feac6c636..c6cc186ec 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/HolderInfoDto.cs @@ -15,12 +15,11 @@ public class HolderInfoDto : IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { - if (NickName.IsNullOrWhiteSpace() && Avatar.IsNullOrWhiteSpace()) { yield return new ValidationResult( "Invalid input.", - new[] { "NickName", "Avatar"} + new[] { "NickName", "Avatar" } ); } } diff --git a/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs b/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs index 282ada71e..c12257a09 100644 --- a/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs +++ b/src/CAServer.Application.Contracts/CAAccount/Dtos/RevokeDto.cs @@ -4,7 +4,5 @@ namespace CAServer.CAAccount.Dtos; public class RevokeDto { - public string AppleToken { get; set; } - - + [Required] public string AppleToken { get; set; } } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs b/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs index 35c567721..113213a86 100644 --- a/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs +++ b/src/CAServer.Application.Contracts/CAAccount/RevokeAccountInput.cs @@ -7,12 +7,8 @@ public class RevokeAccountInput { public string Token { get; set; } public string GuardianIdentifier { get; set; } - public Guid VerifierSessionId { get; set; } - public string VerifierId { get; set; } - public string ChainId { get; set; } public string Type { get; set; } - } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj b/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj index 4236e4cd7..055eed419 100644 --- a/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj +++ b/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj @@ -62,6 +62,11 @@ + + + + + diff --git a/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs b/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs index b99388e28..63d070e9b 100644 --- a/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs +++ b/src/CAServer.Application.Contracts/Google/IGoogleAppService.cs @@ -8,8 +8,6 @@ public interface IGoogleAppService { Task IsGoogleRecaptchaOpenAsync(string userIpAddress, OperationType type); Task IsGoogleRecaptchaTokenValidAsync(string recaptchatoken, PlatformType platformType = PlatformType.WEB); - Task ValidateTokenAsync(string rcToken, string acToken, PlatformType platformType = PlatformType.WEB); - Task VerifyGoogleTokenAsync(string token); } \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs b/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs deleted file mode 100644 index eb4bb3a0b..000000000 --- a/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeInput.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace CAServer.Verifier; - -public class SendRevokeCodeInput -{ - public string GuardianIdentifier { get; set; } - - public string ChainId{ get; set; } - - public string Type { get; set; } - - public string VerifierId { get; set; } - - -} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs b/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs deleted file mode 100644 index 3b29c6be4..000000000 --- a/src/CAServer.Application.Contracts/Verifier/SendRevokeCodeResponse.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace CAServer.Verifier; - -public class SendRevokeCodeResponse -{ - public Guid VerifierSessionId { get; set; } - - public string VerifierId { get; set; } -} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/Verifier/VerifierServerInput.cs b/src/CAServer.Application.Contracts/Verifier/VerifierServerInput.cs index 47fec0685..2bc133133 100644 --- a/src/CAServer.Application.Contracts/Verifier/VerifierServerInput.cs +++ b/src/CAServer.Application.Contracts/Verifier/VerifierServerInput.cs @@ -1,7 +1,5 @@ -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq.Dynamic.Core; using CAServer.Commons; namespace CAServer.Verifier; diff --git a/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs b/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs deleted file mode 100644 index e24c9c055..000000000 --- a/src/CAServer.Application.Contracts/Verifier/VerifyRevokeCodeRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace CAServer.Verifier; - -public class VerifyRevokeCodeRequest -{ - - public Guid VerifierSessionId { get; set; } - public string VerifyCode { get; set; } - - public string ChainId { get; set; } -} \ No newline at end of file diff --git a/src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs b/src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs deleted file mode 100644 index 6ab8fad3f..000000000 --- a/src/CAServer.Application.Contracts/VerifyToken/IVerifyTokenStrategy.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Threading.Tasks; -using CAServer.CAAccount; - -namespace CAServer.VerifyToken; - -public interface IVerifyTokenStrategy -{ - string Type { get; } - - Task VerifyRevokeToken(RevokeAccountInput input); - -} \ No newline at end of file diff --git a/src/CAServer.Application/Google/GoogleAppService.cs b/src/CAServer.Application/Google/GoogleAppService.cs index ebc10c1cd..06086e65b 100644 --- a/src/CAServer.Application/Google/GoogleAppService.cs +++ b/src/CAServer.Application/Google/GoogleAppService.cs @@ -152,31 +152,6 @@ public async Task ValidateTokenAsync(string rcToken, stri } } - public async Task VerifyGoogleTokenAsync(string accessToken) - { - var requestUrl = $"https://www.googleapis.com/oauth2/v2/userinfo?access_token={accessToken}"; - - var client = _httpClientFactory.CreateClient(); - var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUrl)); - - var result = await response.Content.ReadAsStringAsync(); - if (response.StatusCode == HttpStatusCode.Unauthorized || !response.IsSuccessStatusCode) - { - _logger.LogError("{Message}", response.ToString()); - return false; - } - - _logger.LogInformation("GetUserInfo from google: {userInfo}", result); - var googleUserInfo = JsonConvert.DeserializeObject(result); - if (googleUserInfo != null) - { - return true; - } - - _logger.LogError("Get userInfo from google fail."); - return false; - } - public async Task VerifyAppCheckTokenAsync(string token) { if (string.IsNullOrEmpty(token)) diff --git a/src/CAServer.Application/Verifier/VerifierServerClient.cs b/src/CAServer.Application/Verifier/VerifierServerClient.cs index cd822e204..31b5f47ce 100644 --- a/src/CAServer.Application/Verifier/VerifierServerClient.cs +++ b/src/CAServer.Application/Verifier/VerifierServerClient.cs @@ -180,8 +180,7 @@ public async Task> VerifyTwitterTokenAs public async Task VerifyRevokeCodeAsync(VerifyRevokeCodeInput input) { - //var endPoint = await _getVerifierServerProvider.GetVerifierServerEndPointsAsync(input.VerifierId, input.ChainId); - var endPoint = "http://127.0.0.1:5002"; + var endPoint = await _getVerifierServerProvider.GetVerifierServerEndPointsAsync(input.VerifierId, input.ChainId); _logger.LogInformation("EndPiont is {endPiont} :", endPoint); if (null == endPoint) { diff --git a/src/CAServer.ContractEventHandler/appsettings.json b/src/CAServer.ContractEventHandler/appsettings.json index 0968921d5..403c5f067 100644 --- a/src/CAServer.ContractEventHandler/appsettings.json +++ b/src/CAServer.ContractEventHandler/appsettings.json @@ -2,83 +2,34 @@ "RabbitMQ": { "Connections": { "Default": { - "HostName": "192.168.66.53", - "Port": "5672", - "UserName": "admin", - "Password": "admin123456" + "HostName": "127.0.0.1", + "Port": "5672" } }, "EventBus": { - "ClientName": "ContractService", - "ExchangeName": "CAAccount" + "ClientName": "ContractEventHandler", + "ExchangeName": "Exchange" } }, "ConnectionStrings": { - "Default": "mongodb://localhost:27017/CAServer" - }, - "Redis": { - "Configuration": "192.168.66.53" - }, - "Serilog":{ - "Using":[ - "Serilog.Expressions" - ], - "MinimumLevel":{ - "Default":"Debug", - "Override":{ - "Default":"Warning", - "System":"Warning", - "Microsoft":"Warning", + "Default": "mongodb://admin:admin123@127.0.0.1:27017/CAServer" + }, + "Serilog": { + "MinimumLevel": { + "Default": "Debug", + "Override": { + "Default": "Warning", + "System": "Warning", + "Microsoft": "Warning", "Quartz": "Warning" } }, - "WriteTo":[ + "WriteTo": [ { - "Name":"Logger", - "Args":{ - "ConfigureLogger":{ - "WriteTo":[ - { - "Name":"RollingFile", - "Args":{ - "pathFormat":"Logs/log-{Date}.log", - "retainedFileCountLimit":10 - } - } - ], - "Filter":[ - { - "Name":"ByExcluding", - "Args":{ - "expression":"StartsWith(SourceContext, 'CAServer.Monitor.Logger.MonitorLogger')" - } - } - ] - } - } - }, - { - "Name":"Logger", - "Args":{ - "ConfigureLogger":{ - "WriteTo":[ - { - "Name":"RollingFile", - "Args":{ - "pathFormat":"Logs/monitor-{Date}.log", - "retainedFileCountLimit":10 - } - } - ], - "Filter":[ - { - "Name":"ByIncludingOnly", - "Args":{ - "expression":"StartsWith(SourceContext, 'CAServer.Monitor.Logger.MonitorLogger')" - } - } - ] - } + "Name": "RollingFile", + "Args": { + "pathFormat": "Logs/log-{Date}.log", + "retainedFileCountLimit": 15 } } ] @@ -87,24 +38,22 @@ "ChainInfos": { "AELF": { "ChainId": "AELF", - "BaseUrl": "http://192.168.66.123:8000", - "ContractAddress": "SzX8Drm7719hZ4bSqM7jQ5va37BKepqiusfyPjkVdZEA4gvcs", - "TokenContractAddress": "JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE", - "CrossChainContractAddress": "2SQ9LeGZYSWmfJcYuQkDQxgd3HzwjamAaaL4Tge2eFSXw2cseq", - "RedPackageContractAddress": "2UM9eusxdRyCztbmMZadGXzwgwKfFdk8pF4ckw58D769ehaPSR", - "PublicKey": "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e", - "PrivateKey": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2", + "BaseUrl": "http://127.0.0.1:8000", + "ContractAddress": "***", + "TokenContractAddress": "***", + "CrossChainContractAddress": "***", + "RedPackageContractAddress": "***", + "PrivateKey": "***", "IsMainChain": true }, "tDVV": { "ChainId": "tDVV", - "BaseUrl": "http://192.168.66.60:8000", - "ContractAddress": "SzX8Drm7719hZ4bSqM7jQ5va37BKepqiusfyPjkVdZEA4gvcs", - "TokenContractAddress": "7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX", - "CrossChainContractAddress": "2snHc8AMh9QMbCAa7XXmdZZVM5EBZUUPDdLjemwUJkBnL6k8z9", - "RedPackageContractAddress": "jvhrvLGJ29ZzoLSQyUmKGL51NNvYjaHDqcuCpF481139mdxd2", - "PublicKey": "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e", - "PrivateKey": "36bc3f264aa340d44aada5759a5a86aac6d734f19932397e551d9e69edffe0d2", + "BaseUrl": "http://127.0.0.1:8000", + "ContractAddress": "***", + "TokenContractAddress": "***", + "CrossChainContractAddress": "***", + "RedPackageContractAddress": "***", + "PrivateKey": "***", "IsMainChain": false } } @@ -119,66 +68,57 @@ "IndexBefore": 200, "indexAfter": 400, "AutoSyncStartHeight": { - "AELF": 5586826, - "tDVV": 5584084 + "AELF": 5743, + "tDVV": 3295 } }, "GraphQL": { - "Configuration": "http://192.168.67.214:8084/AElfIndexer_DApp_V2/PortKeyIndexerCASchema/graphql" + "GraphQLConnection": "http://127.0.0.1:8083/Indexer_DApp/PortKeyIndexerCASchema/graphql" }, - "Sync" : { + "Sync": { "Sync": 30, "AutoReceive": 60 }, "Orleans": { "ClusterId": "CAServerSiloCluster", "ServiceId": "CAServerOrleansBasicService", - "MongoDBClient": "mongodb://localhost:27017/CAServer", + "MongoDBClient": "mongodb://127.0.0.1:27017/?maxPoolSize=555", "DataBase": "CAServerOrleansDB", "ResponseTimeout":60 }, "CrossChain": { "AutoReceiveStartHeight": { - "AELF": 15231922, - "tDVV": 15203857 + "AELF": 5743, + "tDVV": 3295 } }, - "SignatureServer_bak": { - "BaseUrl": "http://192.168.66.117:18080/api/app/signature" + "Redis": { + "Configuration": "127.0.0.1" }, "SignatureServer": { - "BaseUrl": "http://192.168.66.122:18080", - "AppId": "caserver", - "AppSecret": "12345678" + "BaseUrl": "http://127.0.0.1:18080/api/app/signature" }, "ContractOptions": { "CommonPrivateKeyForCallTx": "aee9944b684505b51c2eefc54b6735453160a74f27c158df65d2783fafa81e57" }, "ElasticUris": { "Uris": [ - "http://192.168.66.201:9200" + "http://127.0.0.1:9200" ] }, - "IndexSetting": { - "NumberOfShards": 5, - "NumberOfReplicas": 1, - "IndexPrefix": "CAServer" - }, "Indicator":{ "IsEnabled":true, "Application":"PortKey", "Module":"CAServer.ContractEventHandler" }, "Hangfire" : { - "ConnectionString": "mongodb://admin:admin123456@192.168.66.216:27017/CAServerContractHangfire?authSource=admin", "Redis": { - "ConnectionString": "192.168.66.53:6379" + "ConnectionString": "127.0.0.1:6379" }, - "redpackage":1 + "redpackage":8 }, "RedPackage":{ "maxCount":1000, - "ExpireTimeMs": 300000, "tokenInfo":[ { "chainId":"AELF", @@ -227,29 +167,17 @@ "symbol":"DISK", "decimal":8, "minAmount":"1" - }, - { - "chainId":"AELF", - "symbol":"USDT", - "decimal":6, - "minAmount":"1" - }, - { - "chainId":"tDVV", - "symbol":"USDT", - "decimal":6, - "minAmount":"1" } ], "RedPackageContractAddress":[ { "chainId": "AELF", - "contractAddress": "2UM9eusxdRyCztbmMZadGXzwgwKfFdk8pF4ckw58D769ehaPSR" + "contractAddress": "***" }, { "chainId": "tDVV", - "contractAddress":"jvhrvLGJ29ZzoLSQyUmKGL51NNvYjaHDqcuCpF481139mdxd2" + "contractAddress": "***" } ] }, @@ -257,11 +185,7 @@ { "RedPackagePayAccounts": [ - "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e", - "0438ad713d76220ddfdac35e2b978f645cf254946d310b0e891201a7d8d36ef3341077d8a40b2fd79b1cfa91b3f3d675933d2ef761af9fa693cf2e36903404a32e" + "***" ] - }, - "ImServer": { - "BaseUrl": "http://192.168.66.117:5007/" } } \ No newline at end of file From 3faceff057fab794f5b3c10ff006d2c506748231 Mon Sep 17 00:00:00 2001 From: wangyue Date: Wed, 24 Apr 2024 11:48:15 +0800 Subject: [PATCH 07/14] feat:format code --- .../CAAccount/CAAccountAppService.cs | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index 98c3589b7..cf29ad4d0 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -448,38 +448,7 @@ public async Task RevokeValidateAsync(Guid userId, string { validateDevice = false; } - - var validateGuardian = true; - if (holderInfo != null) - { - var guardians = holderInfo.GuardianList.Guardians.Where(t => t.IsLoginGuardian).ToList(); - if (guardians.Count > 1) - { - validateGuardian = false; - } - - var guardian = - guardians.FirstOrDefault(t => (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType), type)); - if (guardian == null) - { - throw new Exception(ResponseMessage.LoginGuardianNotExists); - } - } - - var currentGuardian = - holderInfo?.GuardianList.Guardians.FirstOrDefault(t => - t.IsLoginGuardian && (int)t.Type == (int)Enum.Parse(typeof(GuardianIdentifierType), type)); - if (currentGuardian != null) - { - var caHolderDto = - await _accountProvider.GetGuardianAddedCAHolderAsync(currentGuardian.IdentifierHash.ToHex(), 0, - MaxResultCount); - if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count > 1) - { - validateGuardian = false; - } - } - + var validateGuardian = await ValidateGuardianAsync(holderInfo,type); return new CancelCheckResultDto { ValidatedDevice = validateDevice, From 8f321bc4e3749c1ea70bfad314e196d5c7e9ca5b Mon Sep 17 00:00:00 2001 From: wangyue Date: Wed, 24 Apr 2024 16:03:22 +0800 Subject: [PATCH 08/14] feat:remove unused code --- .../CAServer.Application.Contracts.csproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj b/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj index 055eed419..4236e4cd7 100644 --- a/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj +++ b/src/CAServer.Application.Contracts/CAServer.Application.Contracts.csproj @@ -62,11 +62,6 @@ - - - - - From 90482d46375fab37a110e6712e9f219026dd6cbd Mon Sep 17 00:00:00 2001 From: wangyue Date: Thu, 25 Apr 2024 13:51:13 +0800 Subject: [PATCH 09/14] feat:add UT --- .../CAAccount/RevokeAccountMockTests.cs | 42 +++++++++++++++++++ .../CAAccount/RevokeAccountTests.cs | 37 ++++++++++++++++ .../CAServerApplicationTestModule.cs | 10 ++++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs b/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs index 8f2434fd5..7c6a09992 100644 --- a/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs +++ b/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs @@ -1,13 +1,20 @@ using System; using System.Collections.Generic; +using AElf; +using AElf.Types; using CAServer.AppleAuth.Provider; using CAServer.CAAccount.Provider; +using CAServer.Common; using CAServer.Entities.Es; using CAServer.Guardian; using CAServer.Guardian.Provider; +using CAServer.Options; using CAServer.UserAssets; using CAServer.UserAssets.Provider; +using Microsoft.Extensions.Options; using Moq; +using Nethereum.Hex.HexConvertors.Extensions; +using Portkey.Contracts.CA; using GuardianDto = CAServer.Guardian.Provider.GuardianDto; namespace CAServer.CAAccount; @@ -142,4 +149,39 @@ private IAppleAuthProvider GetMockAppleAuthProvider() return mockCaAccountProvider.Object; } + + private IContractProvider GetMockContractProvider() + { + var mockContractProvider = new Mock(); + mockContractProvider.Setup(m => m.GetHolderInfoAsync(It.IsAny(), It.IsAny(), "AELF")) + .ReturnsAsync( + new GetHolderInfoOutput + { + CreateChainId = 123456, + CaHash = Hash.LoadFromHex("df6d6e308c15f8d3a4e78853425985bb3cac08a2230e1df859eb3567fc38c03e"), + GuardianList = new GuardianList() + { + Guardians = + { + new Portkey.Contracts.CA.Guardian + { + IsLoginGuardian = true, + IdentifierHash = Hash.LoadFromHex("0d12a5264e650c245c647738c27f30a75efc5b74e87c85e46fc29dd5d2bc9fe4"), + Salt = "MockSalt", + VerifierId = Hash.LoadFromHex("dbf9d0dedaec2474f89c096ff75c01dc5cdbce0e21567252e99a7f4a88428ae8"), + Type = GuardianType.OfEmail + } + + } + } + + } + + ); + + return mockContractProvider.Object; + } + + + } \ No newline at end of file diff --git a/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs b/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs index 1280eec09..8ee7385f5 100644 --- a/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs +++ b/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs @@ -45,6 +45,8 @@ protected override void AfterAddApplication(IServiceCollection services) services.AddSingleton(GetMockGuardianProvider()); services.AddSingleton(GetMockCaAccountProvider()); services.AddSingleton(GetMockAppleAuthProvider()); + services.AddSingleton(GetMockContractProvider()); + } @@ -108,4 +110,39 @@ private IAppleUserProvider GetMockAppleUserProvider() return provider.Object; } + + [Fact] + public async Task Revoke_Validate_Test() + { + var userId = Guid.NewGuid(); + var result = await _caAccountAppService.RevokeValidateAsync(userId,"Email"); + result.ValidatedAssets.ShouldBeTrue(); + result.ValidatedDevice.ShouldBeTrue(); + result.ValidatedGuardian.ShouldBeTrue(); + } + + [Fact] + public async Task Revoke_Account_Test() + { + + var input = new RevokeAccountInput + { + Token = "MockToken", + ChainId = "AELF", + GuardianIdentifier = "MockGuardianIdentifier", + VerifierId = "", + Type = "Google", + VerifierSessionId = Guid.NewGuid() + }; + var resultDto = await _caAccountAppService.RevokeAccountAsync(input); + resultDto.Success.ShouldBe(false); + + + + + + } + + + } \ No newline at end of file diff --git a/test/CAServer.Application.Tests/CAServerApplicationTestModule.cs b/test/CAServer.Application.Tests/CAServerApplicationTestModule.cs index 09dbf6d9a..433349b8e 100755 --- a/test/CAServer.Application.Tests/CAServerApplicationTestModule.cs +++ b/test/CAServer.Application.Tests/CAServerApplicationTestModule.cs @@ -155,8 +155,14 @@ public override void ConfigureServices(ServiceConfigurationContext context) { option.ChainInfos = new Dictionary { - { "TEST", new Grains.Grain.ApplicationHandler.ChainInfo() }, - { "AELF", new Grains.Grain.ApplicationHandler.ChainInfo() } + { "TEST", new Grains.Grain.ApplicationHandler.ChainInfo() + { + ChainId = "TEST" + } }, + { "AELF", new Grains.Grain.ApplicationHandler.ChainInfo() + { + ChainId = "AELF" + } } }; }); From 616be1507bf087a973ee43ec36440e98367bcbb1 Mon Sep 17 00:00:00 2001 From: wangyue Date: Thu, 25 Apr 2024 14:01:45 +0800 Subject: [PATCH 10/14] feat:add UT --- .../VerifierCode/VerifierServerClientTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/CAServer.Application.Tests/VerifierCode/VerifierServerClientTests.cs b/test/CAServer.Application.Tests/VerifierCode/VerifierServerClientTests.cs index c37d85a50..79789458d 100644 --- a/test/CAServer.Application.Tests/VerifierCode/VerifierServerClientTests.cs +++ b/test/CAServer.Application.Tests/VerifierCode/VerifierServerClientTests.cs @@ -136,4 +136,18 @@ public async Task VerifyAppleToken_Test() await _verifierServerClient.VerifyAppleTokenAsync(input, identifierHash, salt); } + + [Fact] + public async Task VerifyRevokeToken_Test() + { + var input = new VerifyRevokeCodeInput() + { + VerifierId = DefaultVerifierId, + ChainId = DefaultChainId, + VerifyCode = + "eyJraWQiOiJXNldjT0tCIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLnBvcnRrZXkuZGlkIiwiZXhwIjoxNjc5NDcyMjg1LCJpYXQiOjE2NzkzODU4ODUsInN1YiI6IjAwMDMwMy5jZDgxN2I2OTgzMDc0ZDhjOGZiNzkyNDk2ZjI3N2ViYy4wMjU3IiwiY19oYXNoIjoicFBSeFFTSWNWY19BTEExSE9vdmJ5QSIsImVtYWlsIjoicHQ2eXhtOXptbUBwcml2YXRlcmVsYXkuYXBwbGVpZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJpc19wcml2YXRlX2VtYWlsIjoidHJ1ZSIsImF1dGhfdGltZSI6MTY3OTM4NTg4NSwibm9uY2Vfc3VwcG9ydGVkIjp0cnVlfQ.wXHXNbQVqvRxK_a6dq3WjBbJe_KaGsRVgSz_i3E01JyKW8rxGRRgDqjYNiTxB6iOqBMfvXfjtjgPl1N-de_Q4OflzG7gKK_17c-sY2uXUbOWVtAFI9WEXksYhZdV66eJDiUKJ8KE94S6NCT8UdkRqtxHtCnjuq82taYPbqcb-NO3Xcu23hfKsYQM_73yHJfnFd7jUYCoLHcxlVUeRGR7D7L3Yo9FdbocHZwei_x_jwb_7gYjTqGKg6rYt4MRT5ElSTj4xajXrRLZZzCFTVPjytvUsGvU038SEj4sIK6eoDAQy90ne2_XritzViMfKcWid6cdgh-Zz3PzfRx9LEyIPg" + }; + var result = await _verifierServerClient.VerifyRevokeCodeAsync(input); + result.ShouldBe(false); + } } \ No newline at end of file From 95c0ed37dcc0e14f7e6ff51c694b96516b79c8bb Mon Sep 17 00:00:00 2001 From: wangyue Date: Thu, 25 Apr 2024 16:41:34 +0800 Subject: [PATCH 11/14] faet:fix Enum compare --- src/CAServer.Application/CAAccount/CAAccountAppService.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index cf29ad4d0..62c57f4cd 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -512,22 +512,24 @@ private async Task ValidateGuardianAsync(GetHolderInfoOutput holderInfo, s validateGuardian = false; } - var guardian = guardians.FirstOrDefault(t => Enum.GetName(t.Type) == type); + var value = (int)(GuardianIdentifierType)Enum.Parse(typeof(GuardianIdentifierType), type); + var guardian = guardians.FirstOrDefault(t=>(int)t.Type == value); if (guardian == null) { throw new Exception(ResponseMessage.LoginGuardianNotExists); } } + var currentGuardian = - holderInfo?.GuardianList.Guardians.FirstOrDefault(t => t.IsLoginGuardian && Enum.GetName(t.Type) == type); + holderInfo?.GuardianList.Guardians.FirstOrDefault(t => t.IsLoginGuardian && (int)t.Type == (int)(GuardianIdentifierType)Enum.Parse(typeof(GuardianIdentifierType), type)); if (currentGuardian != null) { var caHolderDto = await _accountProvider.GetGuardianAddedCAHolderAsync(currentGuardian.IdentifierHash.ToHex(), 0, MaxResultCount); - if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count < 2) + if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count > 1) { validateGuardian = false; } From f8022bfa06353a3fc5a0e294b52193b647f20967 Mon Sep 17 00:00:00 2001 From: wangyue Date: Sun, 28 Apr 2024 14:35:40 +0800 Subject: [PATCH 12/14] feat:add UT --- .../CAAccount/CAAccountAppService.cs | 2 +- .../CAAccount/RevokeAccountMockTests.cs | 29 +++++++++- .../CAAccount/RevokeAccountTests.cs | 56 +++++++++++++------ 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index 62c57f4cd..2f52035aa 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -529,7 +529,7 @@ private async Task ValidateGuardianAsync(GetHolderInfoOutput holderInfo, s var caHolderDto = await _accountProvider.GetGuardianAddedCAHolderAsync(currentGuardian.IdentifierHash.ToHex(), 0, MaxResultCount); - if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count > 1) + if (caHolderDto?.GuardianAddedCAHolderInfo.Data.Count > 1) { validateGuardian = false; } diff --git a/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs b/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs index 7c6a09992..f601da492 100644 --- a/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs +++ b/test/CAServer.Application.Tests/CAAccount/RevokeAccountMockTests.cs @@ -70,7 +70,8 @@ private IGuardianProvider GetMockGuardianProvider() { var mockGuardianProvider = new Mock(); mockGuardianProvider.Setup(m => m.GetGuardiansAsync(It.IsAny(), It.IsAny())).ReturnsAsync( - new GuardiansDto() + + new GuardiansDto { CaHolderInfo = new List() { @@ -78,6 +79,14 @@ private IGuardianProvider GetMockGuardianProvider() { OriginChainId = "AELF", ChainId = "AELF", + ManagerInfos = new List + { + new ManagerInfoDBase() + { + Address = "123", + ExtraData = "234" + } + }, GuardianList = new GuardianBaseListDto { Guardians = new List @@ -157,7 +166,7 @@ private IContractProvider GetMockContractProvider() .ReturnsAsync( new GetHolderInfoOutput { - CreateChainId = 123456, + CreateChainId = 9992731, CaHash = Hash.LoadFromHex("df6d6e308c15f8d3a4e78853425985bb3cac08a2230e1df859eb3567fc38c03e"), GuardianList = new GuardianList() { @@ -182,6 +191,22 @@ private IContractProvider GetMockContractProvider() return mockContractProvider.Object; } + private IOptionsSnapshot GetMockManagerCountLimitOptions() + { + var mockOptions = new Mock>(); + + mockOptions.Setup(o => o.Value).Returns( + new ManagerCountLimitOptions() + { + Limit = 1 + }); + + return mockOptions.Object; + } + + + + } \ No newline at end of file diff --git a/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs b/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs index 8ee7385f5..960d73fac 100644 --- a/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs +++ b/test/CAServer.Application.Tests/CAAccount/RevokeAccountTests.cs @@ -27,8 +27,8 @@ public partial class RevokeAccountTests : CAServerApplicationTestBase private readonly AppleCacheOptions _appleCacheOptions; private readonly TestCluster _cluster; private ICurrentUser _currentUser; - - + + public RevokeAccountTests() { _caAccountAppService = GetRequiredService(); @@ -36,7 +36,7 @@ public RevokeAccountTests() _cluster = GetRequiredService().Cluster; _currentUser = new CurrentUser(new FakeCurrentPrincipalAccessor()); } - + protected override void AfterAddApplication(IServiceCollection services) { base.AfterAddApplication(services); @@ -46,7 +46,7 @@ protected override void AfterAddApplication(IServiceCollection services) services.AddSingleton(GetMockCaAccountProvider()); services.AddSingleton(GetMockAppleAuthProvider()); services.AddSingleton(GetMockContractProvider()); - + services.AddSingleton(GetMockManagerCountLimitOptions()); } @@ -56,9 +56,9 @@ public async Task Revoke_Test() try { await MockGuardianData(); - + await MockCAHolderData(); - + await _caAccountAppService.RevokeAsync(new RevokeDto { AppleToken = "aaaa" @@ -75,7 +75,7 @@ private async Task MockGuardianData() var contactGrain = _cluster.Client.GetGrain("Guardian-MockIdentifier"); await contactGrain.AddGuardianAsync("aaa", "sss", "xxx", "aaas"); } - + private async Task MockCAHolderData() { var contactGrain = _cluster.Client.GetGrain(_currentUser.GetId()); @@ -94,7 +94,7 @@ private IOptionsSnapshot MockAppleCacheOptions() }); return mockOptionsSnapshot.Object; } - + private IAppleUserProvider GetMockAppleUserProvider() { var provider = new Mock(); @@ -115,34 +115,58 @@ private IAppleUserProvider GetMockAppleUserProvider() public async Task Revoke_Validate_Test() { var userId = Guid.NewGuid(); - var result = await _caAccountAppService.RevokeValidateAsync(userId,"Email"); + var result = await _caAccountAppService.RevokeValidateAsync(userId, "Email"); result.ValidatedAssets.ShouldBeTrue(); result.ValidatedDevice.ShouldBeTrue(); result.ValidatedGuardian.ShouldBeTrue(); } - + [Fact] public async Task Revoke_Account_Test() { - var input = new RevokeAccountInput { Token = "MockToken", ChainId = "AELF", GuardianIdentifier = "MockGuardianIdentifier", VerifierId = "", - Type = "Google", + Type = "Email", VerifierSessionId = Guid.NewGuid() }; var resultDto = await _caAccountAppService.RevokeAccountAsync(input); resultDto.Success.ShouldBe(false); - - + } + [Fact] + public async Task Revoke_Account_GuardianNotExsits_Test() + { + var input = new RevokeAccountInput + { + Token = "MockToken", + ChainId = "AELF", + GuardianIdentifier = "MockGuardianIdentifier", + VerifierId = "", + Type = "Google", + VerifierSessionId = Guid.NewGuid() + }; + try + { + await _caAccountAppService.RevokeAccountAsync(input); + } + catch (Exception e) + { + e.Message.ShouldContain("Login guardian not exists"); + } } - - + + [Fact] + public async Task CheckManagerCountAsync_Test() + { + var caHash = "MockCaHash"; + var resultDto = await _caAccountAppService.CheckManagerCountAsync(caHash); + resultDto.ManagersTooMany.ShouldBeTrue(); + } } \ No newline at end of file From 4832bd06effe7ab4919f66cfd28335ec944b0043 Mon Sep 17 00:00:00 2001 From: wangyue Date: Sun, 28 Apr 2024 15:43:43 +0800 Subject: [PATCH 13/14] feat:fix npe --- .../CAAccount/CAAccountAppService.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CAServer.Application/CAAccount/CAAccountAppService.cs b/src/CAServer.Application/CAAccount/CAAccountAppService.cs index 2f52035aa..87ecc6397 100644 --- a/src/CAServer.Application/CAAccount/CAAccountAppService.cs +++ b/src/CAServer.Application/CAAccount/CAAccountAppService.cs @@ -229,7 +229,7 @@ public async Task RevokeCheckAsync(Guid uid) var tokenRes = await _userAssetsProvider.GetUserTokenInfoAsync(caAddressInfos, "", 0, MaxResultCount); - if (tokenRes.CaHolderTokenBalanceInfo.Data.Count > 0) + if (tokenRes.CaHolderTokenBalanceInfo?.Data.Count > 0) { var tokenInfos = tokenRes.CaHolderTokenBalanceInfo.Data .Where(o => o.TokenInfo.Symbol == DefaultSymbol && o.Balance >= MinBanlance).ToList(); @@ -241,7 +241,7 @@ public async Task RevokeCheckAsync(Guid uid) var res = await _userAssetsProvider.GetUserNftInfoAsync(caAddressInfos, null, 0, MaxResultCount); - if (res.CaHolderNFTBalanceInfo.Data.Count > 0) + if (res.CaHolderNFTBalanceInfo?.Data.Count > 0) { validateAssets = false; } @@ -249,9 +249,9 @@ public async Task RevokeCheckAsync(Guid uid) var validateDevice = true; var caAddresses = caAddressInfos.Select(t => t.CaAddress).ToList(); var caHolderManagerInfo = await _userAssetsProvider.GetCaHolderManagerInfoAsync(caAddresses); - if (caHolderManagerInfo != null && caHolderManagerInfo.CaHolderManagerInfo.Count > 0) + if (caHolderManagerInfo != null && caHolderManagerInfo.CaHolderManagerInfo?.Count > 0) { - var originChainId = caHolderManagerInfo.CaHolderManagerInfo.First().OriginChainId; + var originChainId = caHolderManagerInfo.CaHolderManagerInfo.FirstOrDefault()?.OriginChainId; foreach (var caHolderManager in caHolderManagerInfo.CaHolderManagerInfo .Where(caHolderManager => caHolderManager.OriginChainId == originChainId) .Where(caHolderManager => caHolderManager.ManagerInfos.Count > 1)) @@ -262,7 +262,7 @@ public async Task RevokeCheckAsync(Guid uid) var validateGuardian = true; var appleLoginGuardians = await GetGuardianAsync(caHash); - if (appleLoginGuardians == null && appleLoginGuardians.Count != 1) + if (appleLoginGuardians is not { Count: 1 }) { throw new Exception(ResponseMessage.AppleLoginGuardiansExceed); } @@ -271,7 +271,7 @@ public async Task RevokeCheckAsync(Guid uid) var caHolderDto = await _accountProvider.GetGuardianAddedCAHolderAsync(guardian.IdentifierHash, 0, MaxResultCount); - if (caHolderDto.GuardianAddedCAHolderInfo.Data.Count > 1) + if (caHolderDto.GuardianAddedCAHolderInfo?.Data.Count > 1) { validateGuardian = false; } From 3a1a71d1c29663bfe018b7e210d62fd78349f8d4 Mon Sep 17 00:00:00 2001 From: chaoxkang Date: Mon, 29 Apr 2024 16:54:42 +0800 Subject: [PATCH 14/14] feat: fix sdk TokenList balanceInUsd display fail --- src/CAServer.Application/UserAssets/UserAssetsAppService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CAServer.Application/UserAssets/UserAssetsAppService.cs b/src/CAServer.Application/UserAssets/UserAssetsAppService.cs index 2e72d4771..21af0e949 100644 --- a/src/CAServer.Application/UserAssets/UserAssetsAppService.cs +++ b/src/CAServer.Application/UserAssets/UserAssetsAppService.cs @@ -246,7 +246,7 @@ await _userAssetsProvider.GetUserChainIdsAsync(requestDto.CaAddressInfos.Select( var balanceInUsd = CalculationHelper.GetBalanceInUsd(priceDict[token.Symbol], long.Parse(token.Balance), token.Decimals); token.Price = priceDict[token.Symbol]; - token.BalanceInUsd = token.Price == 0 ? string.Empty : balanceInUsd.ToString(); + token.BalanceInUsd = balanceInUsd.ToString(); } dto.TotalBalanceInUsd = CalculateTotalBalanceInUsd(dto.Data);