Browse Source

Merge pull request #384 from colinin/4.4.1

feat(identity): profile interface added setting user claim
pull/396/head
yx lin 4 years ago
committed by GitHub
parent
commit
938d78870a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimCreateDto.cs
  2. 16
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimCreateOrUpdateDto.cs
  3. 6
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimSetDto.cs
  4. 24
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimUpdateDto.cs
  5. 66
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs
  6. 24
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs
  7. 96
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs

23
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimCreateDto.cs

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

16
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimCreateOrUpdateDto.cs

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

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

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

24
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimUpdateDto.cs

@ -1,13 +1,11 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity
{
public class IdentityUserClaimUpdateDto : IdentityUserClaimCreateDto
{
[Required]
[DynamicMaxLength(typeof(IdentityUserClaimConsts), nameof(IdentityUserClaimConsts.MaxClaimValueLength))]
public string NewClaimValue { get; set; }
}
}
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity
{
public class IdentityUserClaimUpdateDto : IdentityUserClaimCreateOrUpdateDto
{
[DynamicMaxLength(typeof(IdentityUserClaimConsts), nameof(IdentityUserClaimConsts.MaxClaimValueLength))]
public string NewClaimValue { get; set; }
}
}

66
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs

@ -1,30 +1,36 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.Identity
{
public interface IMyProfileAppService : IApplicationService
{
/// <summary>
/// 改变二次认证
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input);
/// <summary>
/// 发送改变手机号验证码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input);
/// <summary>
/// 改变手机绑定
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <remarks>
/// 需二次认证,主要是为了无法用到重定向页面修改相关信息的地方(点名微信小程序)
/// </remarks>
Task ChangePhoneNumberAsync(ChangePhoneNumberDto input);
}
}
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.Identity
{
public interface IMyProfileAppService : IApplicationService
{
/// <summary>
/// 设置声明
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SetClaimAsync(IdentityUserClaimSetDto input);
/// <summary>
/// 改变二次认证
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input);
/// <summary>
/// 发送改变手机号验证码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input);
/// <summary>
/// 改变手机绑定
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <remarks>
/// 需二次认证,主要是为了无法用到重定向页面修改相关信息的地方(点名微信小程序)
/// </remarks>
Task ChangePhoneNumberAsync(ChangePhoneNumberDto input);
}
}

24
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/MyProfileAppService.cs

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Caching;
@ -35,6 +36,29 @@ namespace LINGYUN.Abp.Identity
SecurityTokenCache = securityTokenCache;
}
public virtual async Task SetClaimAsync(IdentityUserClaimSetDto input)
{
await IdentityOptions.SetAsync();
var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
var newClaim = new Claim(input.ClaimType, input.ClaimValue);
var currentClaim = user.FindClaim(newClaim);
if (currentClaim != null)
{
// Replace With Claim Value Empty?
// (await UserManager.ReplaceClaimAsync(user, currentClaim.ToClaim(), newClaim)).CheckErrors();
user.ReplaceClaim(currentClaim.ToClaim(), newClaim);
}
else
{
// (await UserManager.AddClaimAsync(user, newClaim)).CheckErrors();
user.AddClaim(GuidGenerator, newClaim);
}
(await UserManager.UpdateAsync(user)).CheckErrors();
await CurrentUnitOfWork.CompleteAsync();
}
public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
{
// Removed See: https://github.com/abpframework/abp/pull/7719

96
aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs

@ -1,44 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity;
namespace LINGYUN.Abp.Identity
{
[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
[Area("identity")]
[ControllerName("Profile")]
[Route("/api/identity/my-profile")]
public class MyProfileController : AbpController, IMyProfileAppService
{
protected IMyProfileAppService MyProfileAppService { get; }
public MyProfileController(
IMyProfileAppService myProfileAppService)
{
MyProfileAppService = myProfileAppService;
}
[HttpPut]
[Route("change-two-factor")]
public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
{
await MyProfileAppService.ChangeTwoFactorEnabledAsync(input);
}
[HttpPut]
[Route("send-phone-number-change-code")]
public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input)
{
await MyProfileAppService.SendChangePhoneNumberCodeAsync(input);
}
[HttpPut]
[Route("change-phone-number")]
public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberDto input)
{
await MyProfileAppService.ChangePhoneNumberAsync(input);
}
}
}
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity;
namespace LINGYUN.Abp.Identity
{
[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
[Area("identity")]
[ControllerName("Profile")]
[Route("/api/identity/my-profile")]
public class MyProfileController : AbpController, IMyProfileAppService
{
protected IMyProfileAppService MyProfileAppService { get; }
public MyProfileController(
IMyProfileAppService myProfileAppService)
{
MyProfileAppService = myProfileAppService;
}
[HttpPut]
[Route("/claims")]
public virtual async Task SetClaimAsync(IdentityUserClaimSetDto input)
{
await MyProfileAppService.SetClaimAsync(input);
}
[HttpPut]
[Route("change-two-factor")]
public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
{
await MyProfileAppService.ChangeTwoFactorEnabledAsync(input);
}
[HttpPut]
[Route("send-phone-number-change-code")]
public virtual async Task SendChangePhoneNumberCodeAsync(SendChangePhoneNumberCodeDto input)
{
await MyProfileAppService.SendChangePhoneNumberCodeAsync(input);
}
[HttpPut]
[Route("change-phone-number")]
public virtual async Task ChangePhoneNumberAsync(ChangePhoneNumberDto input)
{
await MyProfileAppService.ChangePhoneNumberAsync(input);
}
}
}

Loading…
Cancel
Save