From 9bd203b0a67f32ad95fae392ca993add8c6d72a3 Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Sun, 29 Aug 2021 15:35:46 +0800
Subject: [PATCH] upgrade dapr.net from 1.1.0 to 1.3.0
---
.../LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj | 2 +-
.../LINGYUN.Abp.Dapr.Actors.csproj | 2 +-
.../LINGYUN.Abp.Dapr.Client.csproj | 4 +-
.../Abp/Identity/MyProfileAppService.cs | 207 +++++++++---------
4 files changed, 107 insertions(+), 108 deletions(-)
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
index 0094684a6..4bea0ff91 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj
index 6b6e6debc..41c9bea57 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
index 36a2e73df..895e14f2d 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
@@ -1,4 +1,4 @@
-
+
net5.0
@@ -6,7 +6,7 @@
-
+
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs
index 96f9e9623..8f09f679e 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs
@@ -1,104 +1,103 @@
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Identity;
-using Microsoft.Extensions.Caching.Distributed;
-using Microsoft.Extensions.Options;
-using System;
-using System.Threading.Tasks;
-using Volo.Abp;
-using Volo.Abp.Caching;
-using Volo.Abp.Identity;
-using Volo.Abp.Identity.Settings;
-using Volo.Abp.Settings;
-using Volo.Abp.Users;
-
-namespace LINGYUN.Abp.Identity
-{
- [Authorize]
- public class MyProfileAppService : IdentityAppServiceBase, IMyProfileAppService
- {
- protected IDistributedCache SecurityTokenCache { get; }
- protected IUserSecurityCodeSender SecurityCodeSender { get; }
- protected IdentityUserManager UserManager { get; }
- protected IIdentityUserRepository UserRepository { get; }
- protected IOptions IdentityOptions { get; }
-
- public MyProfileAppService(
- IdentityUserManager userManager,
- IIdentityUserRepository userRepository,
- IUserSecurityCodeSender securityCodeSender,
- IOptions identityOptions,
- IDistributedCache securityTokenCache)
- {
- UserManager = userManager;
- UserRepository = userRepository;
- IdentityOptions = identityOptions;
- SecurityCodeSender = securityCodeSender;
- SecurityTokenCache = securityTokenCache;
- }
-
- public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
- {
- // Removed See: https://github.com/abpframework/abp/pull/7719
- //if (!await SettingProvider.IsTrueAsync(IdentitySettingNames.TwoFactor.UsersCanChange))
- //{
- // throw new BusinessException(Volo.Abp.Identity.IdentityErrorCodes.CanNotChangeTwoFactor);
- //}
- // TODO: Abp官方移除了双因素的设置,不排除以后会增加,如果在用户接口中启用了双因素认证,可能造成登录失败!
- await IdentityOptions.SetAsync();
- var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
-
- (await UserManager.SetTwoFactorEnabledWithAccountConfirmedAsync(user, input.Enabled)).CheckErrors();
-
- await CurrentUnitOfWork.SaveChangesAsync();
- }
-
- public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input)
- {
- var securityTokenCacheKey = SmsSecurityTokenCacheItem.CalculateCacheKey(input.NewPhoneNumber, "SmsChangePhoneNumber");
- var securityTokenCacheItem = await SecurityTokenCache.GetAsync(securityTokenCacheKey);
- var interval = await SettingProvider.GetAsync(Settings.IdentitySettingNames.User.SmsRepetInterval, 1);
- if (securityTokenCacheItem != null)
- {
- throw new UserFriendlyException(L["SendRepeatPhoneVerifyCode", interval]);
- }
-
- // 是否已有用户使用手机号绑定
- if (await UserRepository.IsPhoneNumberConfirmedAsync(input.NewPhoneNumber))
- {
- throw new BusinessException(IdentityErrorCodes.DuplicatePhoneNumber);
- }
- var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
- var template = await SettingProvider.GetOrNullAsync(Settings.IdentitySettingNames.User.SmsPhoneNumberConfirmed);
- var token = await UserManager.GenerateChangePhoneNumberTokenAsync(user, input.NewPhoneNumber);
- // 发送验证码
- await SecurityCodeSender.SendPhoneConfirmedCodeAsync(input.NewPhoneNumber, token, template);
-
- securityTokenCacheItem = new SmsSecurityTokenCacheItem(token, user.ConcurrencyStamp);
- await SecurityTokenCache
- .SetAsync(securityTokenCacheKey, securityTokenCacheItem,
- new DistributedCacheEntryOptions
- {
- AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(interval)
- });
- }
-
- public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberDto input)
- {
- // 是否已有用户使用手机号绑定
- if (await UserRepository.IsPhoneNumberConfirmedAsync(input.NewPhoneNumber))
- {
- throw new BusinessException(IdentityErrorCodes.DuplicatePhoneNumber);
- }
- await IdentityOptions.SetAsync();
- //TODO: 可以查询缓存用 securityTokenCacheItem.SecurityToken 与 user.SecurityStamp 作对比
- var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
- // 更换手机号
- (await UserManager.ChangePhoneNumberAsync(user, input.NewPhoneNumber, input.Code)).CheckErrors();
-
- await CurrentUnitOfWork.SaveChangesAsync();
-
- var securityTokenCacheKey = SmsSecurityTokenCacheItem.CalculateCacheKey(input.NewPhoneNumber, "SmsChangePhoneNumber");
- await SecurityTokenCache.RemoveAsync(securityTokenCacheKey);
- }
- }
-}
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.Extensions.Caching.Distributed;
+using Microsoft.Extensions.Options;
+using System;
+using System.Threading.Tasks;
+using Volo.Abp;
+using Volo.Abp.Caching;
+using Volo.Abp.Identity;
+using Volo.Abp.Settings;
+using Volo.Abp.Users;
+
+namespace LINGYUN.Abp.Identity
+{
+ [Authorize]
+ public class MyProfileAppService : IdentityAppServiceBase, IMyProfileAppService
+ {
+ protected IDistributedCache SecurityTokenCache { get; }
+ protected IUserSecurityCodeSender SecurityCodeSender { get; }
+ protected IdentityUserManager UserManager { get; }
+ protected IIdentityUserRepository UserRepository { get; }
+ protected IOptions IdentityOptions { get; }
+
+ public MyProfileAppService(
+ IdentityUserManager userManager,
+ IIdentityUserRepository userRepository,
+ IUserSecurityCodeSender securityCodeSender,
+ IOptions identityOptions,
+ IDistributedCache securityTokenCache)
+ {
+ UserManager = userManager;
+ UserRepository = userRepository;
+ IdentityOptions = identityOptions;
+ SecurityCodeSender = securityCodeSender;
+ SecurityTokenCache = securityTokenCache;
+ }
+
+ public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
+ {
+ // Removed See: https://github.com/abpframework/abp/pull/7719
+ //if (!await SettingProvider.IsTrueAsync(IdentitySettingNames.TwoFactor.UsersCanChange))
+ //{
+ // throw new BusinessException(Volo.Abp.Identity.IdentityErrorCodes.CanNotChangeTwoFactor);
+ //}
+ // TODO: Abp官方移除了双因素的设置,不排除以后会增加,如果在用户接口中启用了双因素认证,可能造成登录失败!
+ await IdentityOptions.SetAsync();
+ var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
+
+ (await UserManager.SetTwoFactorEnabledWithAccountConfirmedAsync(user, input.Enabled)).CheckErrors();
+
+ await CurrentUnitOfWork.SaveChangesAsync();
+ }
+
+ public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input)
+ {
+ var securityTokenCacheKey = SmsSecurityTokenCacheItem.CalculateCacheKey(input.NewPhoneNumber, "SmsChangePhoneNumber");
+ var securityTokenCacheItem = await SecurityTokenCache.GetAsync(securityTokenCacheKey);
+ var interval = await SettingProvider.GetAsync(Settings.IdentitySettingNames.User.SmsRepetInterval, 1);
+ if (securityTokenCacheItem != null)
+ {
+ throw new UserFriendlyException(L["SendRepeatPhoneVerifyCode", interval]);
+ }
+
+ // 是否已有用户使用手机号绑定
+ if (await UserRepository.IsPhoneNumberConfirmedAsync(input.NewPhoneNumber))
+ {
+ throw new BusinessException(IdentityErrorCodes.DuplicatePhoneNumber);
+ }
+ var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
+ var template = await SettingProvider.GetOrNullAsync(Settings.IdentitySettingNames.User.SmsPhoneNumberConfirmed);
+ var token = await UserManager.GenerateChangePhoneNumberTokenAsync(user, input.NewPhoneNumber);
+ // 发送验证码
+ await SecurityCodeSender.SendPhoneConfirmedCodeAsync(input.NewPhoneNumber, token, template);
+
+ securityTokenCacheItem = new SmsSecurityTokenCacheItem(token, user.ConcurrencyStamp);
+ await SecurityTokenCache
+ .SetAsync(securityTokenCacheKey, securityTokenCacheItem,
+ new DistributedCacheEntryOptions
+ {
+ AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(interval)
+ });
+ }
+
+ public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberDto input)
+ {
+ // 是否已有用户使用手机号绑定
+ if (await UserRepository.IsPhoneNumberConfirmedAsync(input.NewPhoneNumber))
+ {
+ throw new BusinessException(IdentityErrorCodes.DuplicatePhoneNumber);
+ }
+ await IdentityOptions.SetAsync();
+ //TODO: 可以查询缓存用 securityTokenCacheItem.SecurityToken 与 user.SecurityStamp 作对比
+ var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
+ // 更换手机号
+ (await UserManager.ChangePhoneNumberAsync(user, input.NewPhoneNumber, input.Code)).CheckErrors();
+
+ await CurrentUnitOfWork.SaveChangesAsync();
+
+ var securityTokenCacheKey = SmsSecurityTokenCacheItem.CalculateCacheKey(input.NewPhoneNumber, "SmsChangePhoneNumber");
+ await SecurityTokenCache.RemoveAsync(securityTokenCacheKey);
+ }
+ }
+}