From ef8a11728b7158b9d5e41b7a102a435129696934 Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Thu, 18 Nov 2021 13:31:39 +0800
Subject: [PATCH] feat(profile): added an interface for two factor
---
...oFactorEnabledDto.cs => TwoFactorEnabledDto.cs} | 14 +++++++-------
.../Abp/Identity/IIdentityUserAppService.cs | 2 +-
.../LINGYUN/Abp/Identity/IMyProfileAppService.cs | 7 ++++++-
.../LINGYUN/Abp/Identity/IdentityUserAppService.cs | 2 +-
.../LINGYUN/Abp/Identity/MyProfileAppService.cs | 13 ++++++++++++-
.../LINGYUN/Abp/Identity/IdentityUserController.cs | 2 +-
.../LINGYUN/Abp/Identity/MyProfileController.cs | 8 +++++++-
7 files changed, 35 insertions(+), 13 deletions(-)
rename aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/{ChangeTwoFactorEnabledDto.cs => TwoFactorEnabledDto.cs} (67%)
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/ChangeTwoFactorEnabledDto.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/TwoFactorEnabledDto.cs
similarity index 67%
rename from aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/ChangeTwoFactorEnabledDto.cs
rename to aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/TwoFactorEnabledDto.cs
index 21091277b..e1dd97dd9 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/ChangeTwoFactorEnabledDto.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/TwoFactorEnabledDto.cs
@@ -1,7 +1,7 @@
-namespace LINGYUN.Abp.Identity
-{
- public class ChangeTwoFactorEnabledDto
- {
- public bool Enabled { get; set; }
- }
-}
+namespace LINGYUN.Abp.Identity
+{
+ public class TwoFactorEnabledDto
+ {
+ public bool Enabled { get; set; }
+ }
+}
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs
index 59d957a39..d8b4f4868 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs
@@ -37,7 +37,7 @@ namespace LINGYUN.Abp.Identity
///
///
///
- Task ChangeTwoFactorEnabledAsync(Guid id, ChangeTwoFactorEnabledDto input);
+ Task ChangeTwoFactorEnabledAsync(Guid id, TwoFactorEnabledDto input);
///
/// 变更用户密码
///
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs
index 35a514e10..de9e8fbab 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IMyProfileAppService.cs
@@ -12,11 +12,16 @@ namespace LINGYUN.Abp.Identity
///
Task SetClaimAsync(IdentityUserClaimSetDto input);
///
+ /// 获取二次认证状态
+ ///
+ ///
+ Task GetTwoFactorEnabledAsync();
+ ///
/// 改变二次认证
///
///
///
- Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input);
+ Task ChangeTwoFactorEnabledAsync(TwoFactorEnabledDto input);
///
/// 发送改变手机号验证码
///
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs
index 5736d7064..4c29a1df9 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs
@@ -138,7 +138,7 @@ namespace LINGYUN.Abp.Identity
}
[Authorize(Volo.Abp.Identity.IdentityPermissions.Users.Update)]
- public virtual async Task ChangeTwoFactorEnabledAsync(Guid id, ChangeTwoFactorEnabledDto input)
+ public virtual async Task ChangeTwoFactorEnabledAsync(Guid id, TwoFactorEnabledDto input)
{
var user = await GetUserAsync(id);
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 6693350f0..8fc48177b 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
@@ -59,7 +59,18 @@ namespace LINGYUN.Abp.Identity
await CurrentUnitOfWork.CompleteAsync();
}
- public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
+ public virtual async Task GetTwoFactorEnabledAsync()
+ {
+ await IdentityOptions.SetAsync();
+ var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
+
+ return new TwoFactorEnabledDto
+ {
+ Enabled = await UserManager.GetTwoFactorEnabledAsync(user),
+ };
+ }
+
+ public virtual async Task ChangeTwoFactorEnabledAsync(TwoFactorEnabledDto input)
{
// Removed See: https://github.com/abpframework/abp/pull/7719
//if (!await SettingProvider.IsTrueAsync(IdentitySettingNames.TwoFactor.UsersCanChange))
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IdentityUserController.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IdentityUserController.cs
index 783a64a84..84cca35d6 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IdentityUserController.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IdentityUserController.cs
@@ -87,7 +87,7 @@ namespace LINGYUN.Abp.Identity
[HttpPut]
[Route("change-two-factor")]
- public virtual async Task ChangeTwoFactorEnabledAsync(Guid id, ChangeTwoFactorEnabledDto input)
+ public virtual async Task ChangeTwoFactorEnabledAsync(Guid id, TwoFactorEnabledDto input)
{
await UserAppService.ChangeTwoFactorEnabledAsync(id, input);
}
diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs
index 4f4970500..1b6afe8e4 100644
--- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs
+++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/MyProfileController.cs
@@ -27,10 +27,16 @@ namespace LINGYUN.Abp.Identity
await MyProfileAppService.SetClaimAsync(input);
}
+ [HttpGet]
+ [Route("two-factor")]
+ public virtual async Task GetTwoFactorEnabledAsync()
+ {
+ return await MyProfileAppService.GetTwoFactorEnabledAsync();
+ }
[HttpPut]
[Route("change-two-factor")]
- public virtual async Task ChangeTwoFactorEnabledAsync(ChangeTwoFactorEnabledDto input)
+ public virtual async Task ChangeTwoFactorEnabledAsync(TwoFactorEnabledDto input)
{
await MyProfileAppService.ChangeTwoFactorEnabledAsync(input);
}