Browse Source

feat(identity): profile interface added setting user claim

pull/384/head
cKey 4 years ago
parent
commit
b93ce73039
  1. 15
      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. 6
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserClaimUpdateDto.cs
  5. 6
      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. 8
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs

15
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
namespace LINGYUN.Abp.Identity
{
public class IdentityUserClaimCreateDto
public class IdentityUserClaimCreateDto: IdentityUserClaimCreateOrUpdateDto
{
[Required]
[DynamicMaxLength(typeof(IdentityUserClaimConsts), nameof(IdentityUserClaimConsts.MaxClaimTypeLength))]
public string ClaimType { get; set; }
[Required]
[DynamicMaxLength(typeof(IdentityUserClaimConsts), nameof(IdentityUserClaimConsts.MaxClaimValueLength))]
public string ClaimValue { get; set; }
}
}

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
{
}
}

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

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

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

@ -5,6 +5,12 @@ namespace LINGYUN.Abp.Identity
{
public interface IMyProfileAppService : IApplicationService
{
/// <summary>
/// 设置声明
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task SetClaimAsync(IdentityUserClaimSetDto input);
/// <summary>
/// 改变二次认证
/// </summary>

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

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

@ -20,6 +20,14 @@ namespace LINGYUN.Abp.Identity
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)

Loading…
Cancel
Save