Browse Source

refactor: move user profile api to account service

pull/431/head
cKey 4 years ago
parent
commit
5c356282ec
  1. 6
      RELEASE.md
  2. 4
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/ChangePhoneNumberInput.cs
  3. 16
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/ChangeUserClaimInput.cs
  4. 4
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SendChangePhoneNumberCodeInput.cs
  5. 7
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/TwoFactorEnabledDto.cs
  6. 8
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyProfileAppService.cs
  7. 29
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyProfileAppService.cs
  8. 12
      aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyProfileController.cs
  9. 27
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/ChangeEmailAddressDto.cs
  10. 6
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimSetDto.cs
  11. 18
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/SendChangeEmailAddressCodeDto.cs

6
RELEASE.md

@ -12,9 +12,13 @@
4、移除网关管理模块, 使用本地文件作为路由配置;
5、移除动态网关数据库脚本文件;
6、将 Profile 相关api从Identity模块移动到Account模块;
5、加入Fody统一配置ConfigureAwait;
6、使用Directory.Build.props统一管理导入版本。
6、使用Directory.Build.props统一管理导入版本;
# [2021-03-29]
1、增加动态本地化组件支持,用于在运行时替换本地化文本,需要实现 ILocalizationStore;

4
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/ChangePhoneNumberDto.cs → aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/ChangePhoneNumberInput.cs

@ -3,9 +3,9 @@ using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity
namespace LINGYUN.Abp.Account
{
public class ChangePhoneNumberDto
public class ChangePhoneNumberInput
{
/// <summary>
/// 新手机号

16
aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/ChangeUserClaimInput.cs

@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Account
{
public class ChangeUserClaimInput
{
[Required]
[DynamicMaxLength(typeof(IdentityUserClaimConsts), nameof(IdentityUserClaimConsts.MaxClaimTypeLength))]
public string ClaimType { get; set; }
[DynamicMaxLength(typeof(IdentityUserClaimConsts), nameof(IdentityUserClaimConsts.MaxClaimValueLength))]
public string ClaimValue { get; set; }
}
}

4
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/SendChangePhoneNumberCodeDto.cs → aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/SendChangePhoneNumberCodeInput.cs

@ -2,9 +2,9 @@
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity
namespace LINGYUN.Abp.Account
{
public class SendChangePhoneNumberCodeDto
public class SendChangePhoneNumberCodeInput
{
/// <summary>
/// 新手机号

7
aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Dto/TwoFactorEnabledDto.cs

@ -0,0 +1,7 @@
namespace LINGYUN.Abp.Account
{
public class TwoFactorEnabledDto
{
public bool Enabled { get; set; }
}
}

8
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs → aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/IMyProfileAppService.cs

@ -1,7 +1,7 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.Identity
namespace LINGYUN.Abp.Account
{
public interface IMyProfileAppService : IApplicationService
{
@ -10,7 +10,7 @@ namespace LINGYUN.Abp.Identity
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SetClaimAsync(IdentityUserClaimSetDto input);
Task SetClaimAsync(ChangeUserClaimInput input);
/// <summary>
/// 获取二次认证状态
/// </summary>
@ -27,7 +27,7 @@ namespace LINGYUN.Abp.Identity
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input);
Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeInput input);
/// <summary>
/// 改变手机绑定
/// </summary>
@ -36,6 +36,6 @@ namespace LINGYUN.Abp.Identity
/// <remarks>
/// 需二次认证,主要是为了无法用到重定向页面修改相关信息的地方(点名微信小程序)
/// </remarks>
Task ChangePhoneNumberAsync(ChangePhoneNumberDto input);
Task ChangePhoneNumberAsync(ChangePhoneNumberInput input);
}
}

29
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs → aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/MyProfileAppService.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using LINGYUN.Abp.Identity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
@ -6,25 +7,27 @@ using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Account.Localization;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Volo.Abp.Identity;
using Volo.Abp.Settings;
using Volo.Abp.Users;
namespace LINGYUN.Abp.Identity
namespace LINGYUN.Abp.Account
{
[Authorize]
public class MyProfileAppService : IdentityAppServiceBase, IMyProfileAppService
public class MyProfileAppService : ApplicationService, IMyProfileAppService
{
protected IDistributedCache<SmsSecurityTokenCacheItem> SecurityTokenCache { get; }
protected IUserSecurityCodeSender SecurityCodeSender { get; }
protected IdentityUserManager UserManager { get; }
protected IIdentityUserRepository UserRepository { get; }
protected Identity.IIdentityUserRepository UserRepository { get; }
protected IOptions<IdentityOptions> IdentityOptions { get; }
public MyProfileAppService(
IdentityUserManager userManager,
IIdentityUserRepository userRepository,
Identity.IIdentityUserRepository userRepository,
IUserSecurityCodeSender securityCodeSender,
IOptions<IdentityOptions> identityOptions,
IDistributedCache<SmsSecurityTokenCacheItem> securityTokenCache)
@ -34,9 +37,11 @@ namespace LINGYUN.Abp.Identity
IdentityOptions = identityOptions;
SecurityCodeSender = securityCodeSender;
SecurityTokenCache = securityTokenCache;
LocalizationResource = typeof(AccountResource);
}
public virtual async Task SetClaimAsync(IdentityUserClaimSetDto input)
public virtual async Task SetClaimAsync(ChangeUserClaimInput input)
{
await IdentityOptions.SetAsync();
var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
@ -86,11 +91,11 @@ namespace LINGYUN.Abp.Identity
await CurrentUnitOfWork.SaveChangesAsync();
}
public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input)
public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeInput input)
{
var securityTokenCacheKey = SmsSecurityTokenCacheItem.CalculateCacheKey(input.NewPhoneNumber, "SmsChangePhoneNumber");
var securityTokenCacheItem = await SecurityTokenCache.GetAsync(securityTokenCacheKey);
var interval = await SettingProvider.GetAsync(Settings.IdentitySettingNames.User.SmsRepetInterval, 1);
var interval = await SettingProvider.GetAsync(Identity.Settings.IdentitySettingNames.User.SmsRepetInterval, 1);
if (securityTokenCacheItem != null)
{
throw new UserFriendlyException(L["SendRepeatPhoneVerifyCode", interval]);
@ -99,10 +104,10 @@ namespace LINGYUN.Abp.Identity
// 是否已有用户使用手机号绑定
if (await UserRepository.IsPhoneNumberConfirmedAsync(input.NewPhoneNumber))
{
throw new BusinessException(IdentityErrorCodes.DuplicatePhoneNumber);
throw new BusinessException(Identity.IdentityErrorCodes.DuplicatePhoneNumber);
}
var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
var template = await SettingProvider.GetOrNullAsync(Settings.IdentitySettingNames.User.SmsPhoneNumberConfirmed);
var template = await SettingProvider.GetOrNullAsync(Identity.Settings.IdentitySettingNames.User.SmsPhoneNumberConfirmed);
var token = await UserManager.GenerateChangePhoneNumberTokenAsync(user, input.NewPhoneNumber);
// 发送验证码
await SecurityCodeSender.SendPhoneConfirmedCodeAsync(input.NewPhoneNumber, token, template);
@ -116,12 +121,12 @@ namespace LINGYUN.Abp.Identity
});
}
public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberDto input)
public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberInput input)
{
// 是否已有用户使用手机号绑定
if (await UserRepository.IsPhoneNumberConfirmedAsync(input.NewPhoneNumber))
{
throw new BusinessException(IdentityErrorCodes.DuplicatePhoneNumber);
throw new BusinessException(Identity.IdentityErrorCodes.DuplicatePhoneNumber);
}
await IdentityOptions.SetAsync();
//TODO: 可以查询缓存用 securityTokenCacheItem.SecurityToken 与 user.SecurityStamp 作对比

12
aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs → aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/MyProfileController.cs

@ -4,12 +4,12 @@ using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity;
namespace LINGYUN.Abp.Identity
namespace LINGYUN.Abp.Account
{
[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
[Area("identity")]
[Area("account")]
[ControllerName("Profile")]
[Route("/api/identity/my-profile")]
[Route("/api/account/my-profile")]
public class MyProfileController : AbpController, IMyProfileAppService
{
protected IMyProfileAppService MyProfileAppService { get; }
@ -22,7 +22,7 @@ namespace LINGYUN.Abp.Identity
[HttpPut]
[Route("claims")]
public virtual async Task SetClaimAsync(IdentityUserClaimSetDto input)
public virtual async Task SetClaimAsync(ChangeUserClaimInput input)
{
await MyProfileAppService.SetClaimAsync(input);
}
@ -43,14 +43,14 @@ namespace LINGYUN.Abp.Identity
[HttpPut]
[Route("send-phone-number-change-code")]
public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input)
public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeInput input)
{
await MyProfileAppService.SendChangePhoneNumberCodeAsync(input);
}
[HttpPut]
[Route("change-phone-number")]
public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberDto input)
public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberInput input)
{
await MyProfileAppService.ChangePhoneNumberAsync(input);
}

27
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/ChangeEmailAddressDto.cs

@ -1,27 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity
{
public class ChangeEmailAddressDto
{
/// <summary>
/// 新邮件地址
/// </summary>
[Required]
[EmailAddress]
[Display(Name = "EmailAddress")]
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxEmailLength))]
public string NewEmailAddress { get; set; }
/// <summary>
/// 安全验证码
/// </summary>
[Required]
[DisableAuditing]
[StringLength(6, MinimumLength = 6)]
[Display(Name = "EmailVerifyCode")]
public string Code { get; set; }
}
}

6
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimSetDto.cs

@ -1,6 +0,0 @@
namespace LINGYUN.Abp.Identity
{
public class IdentityUserClaimSetDto : IdentityUserClaimCreateDto
{
}
}

18
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/SendChangeEmailAddressCodeDto.cs

@ -1,18 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity
{
public class SendChangeEmailAddressCodeDto
{
/// <summary>
/// 新邮件地址
/// </summary>
[Required]
[EmailAddress]
[Display(Name = "EmailAddress")]
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxEmailLength))]
public string NewEmailAddress { get; set; }
}
}
Loading…
Cancel
Save