Browse Source

feat: 增加重置用户密码api

pull/613/head
cKey 4 years ago
parent
commit
0114b31fe0
  1. 42
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs
  2. 12
      aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/AccountController.cs
  3. 14
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserSetPasswordInput.cs
  4. 3
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs
  5. 1
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissionDefinitionProvider.cs
  6. 1
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissions.cs
  7. 13
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs
  8. 1
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain.Shared/LINGYUN/Abp/Identity/Localization/en.json
  9. 1
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain.Shared/LINGYUN/Abp/Identity/Localization/zh-Hans.json
  10. 6
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IdentityUserController.cs

42
aspnet-core/modules/account/LINGYUN.Abp.Account.Application/LINGYUN/Abp/Account/AccountAppService.cs

@ -6,13 +6,16 @@ using LINGYUN.Abp.WeChat.MiniProgram;
using LINGYUN.Abp.WeChat.OpenId;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Account;
using Volo.Abp.Caching;
using Volo.Abp.Clients;
using Volo.Abp.Identity;
using Volo.Abp.Settings;
using Volo.Abp.Validation;
@ -26,6 +29,7 @@ namespace LINGYUN.Abp.Account
protected IIdentityUserRepository UserRepository { get; }
protected IUserSecurityCodeSender SecurityCodeSender { get; }
protected IWeChatOpenIdFinder WeChatOpenIdFinder { get; }
protected IdentitySecurityLogManager IdentitySecurityLogManager { get; }
protected AbpWeChatMiniProgramOptionsFactory MiniProgramOptionsFactory { get; }
protected IDistributedCache<SmsSecurityTokenCacheItem> SecurityTokenCache { get; }
@ -35,7 +39,8 @@ namespace LINGYUN.Abp.Account
IIdentityUserRepository userRepository,
IUserSecurityCodeSender securityCodeSender,
IDistributedCache<SmsSecurityTokenCacheItem> securityTokenCache,
AbpWeChatMiniProgramOptionsFactory miniProgramOptionsFactory)
AbpWeChatMiniProgramOptionsFactory miniProgramOptionsFactory,
IdentitySecurityLogManager identitySecurityLogManager)
{
TotpService = totpService;
UserRepository = userRepository;
@ -43,6 +48,7 @@ namespace LINGYUN.Abp.Account
SecurityCodeSender = securityCodeSender;
SecurityTokenCache = securityTokenCache;
MiniProgramOptionsFactory = miniProgramOptionsFactory;
IdentitySecurityLogManager = identitySecurityLogManager;
}
public virtual async Task RegisterAsync(WeChatRegisterDto input)
@ -82,6 +88,15 @@ namespace LINGYUN.Abp.Account
var userLogin = new UserLoginInfo(AbpWeChatMiniProgramConsts.ProviderName, wehchatOpenId.OpenId, AbpWeChatGlobalConsts.DisplayName);
(await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();
await IdentitySecurityLogManager.SaveAsync(
new IdentitySecurityLogContext
{
Action = "WeChatRegister",
ClientId = await FindClientIdAsync(),
Identity = "Account",
UserName = user.UserName
});
await CurrentUnitOfWork.SaveChangesAsync();
}
@ -155,6 +170,15 @@ namespace LINGYUN.Abp.Account
await SecurityTokenCache.RemoveAsync(securityTokenCacheKey);
await IdentitySecurityLogManager.SaveAsync(
new IdentitySecurityLogContext
{
Action = "PhoneNumberRegister",
ClientId = await FindClientIdAsync(),
Identity = "Account",
UserName = user.UserName
});
await CurrentUnitOfWork.SaveChangesAsync();
return;
@ -231,6 +255,15 @@ namespace LINGYUN.Abp.Account
// 移除缓存项
await SecurityTokenCache.RemoveAsync(securityTokenCacheKey);
await IdentitySecurityLogManager.SaveAsync(
new IdentitySecurityLogContext
{
Action = "ResetPassword",
ClientId = await FindClientIdAsync(),
Identity = "Account",
UserName = user.UserName
});
await CurrentUnitOfWork.SaveChangesAsync();
}
@ -290,6 +323,13 @@ namespace LINGYUN.Abp.Account
}
}
protected virtual Task<string> FindClientIdAsync()
{
var client = LazyServiceProvider.LazyGetRequiredService<ICurrentClient>();
return Task.FromResult(client.Id);
}
private void ThowIfInvalidEmailAddress(string inputEmail)
{
if (!inputEmail.IsNullOrWhiteSpace() &&

12
aspnet-core/modules/account/LINGYUN.Abp.Account.HttpApi/LINGYUN/Abp/Account/AccountController.cs

@ -20,42 +20,42 @@ namespace LINGYUN.Abp.Account
[HttpPost]
[Route("wechat/register")]
public virtual async Task RegisterAsync(WeChatRegisterDto input)
public async virtual Task RegisterAsync(WeChatRegisterDto input)
{
await AccountAppService.RegisterAsync(input);
}
[HttpPost]
[Route("phone/register")]
public virtual async Task RegisterAsync(PhoneRegisterDto input)
public async virtual Task RegisterAsync(PhoneRegisterDto input)
{
await AccountAppService.RegisterAsync(input);
}
[HttpPut]
[Route("phone/reset-password")]
public virtual async Task ResetPasswordAsync(PhoneResetPasswordDto input)
public async virtual Task ResetPasswordAsync(PhoneResetPasswordDto input)
{
await AccountAppService.ResetPasswordAsync(input);
}
[HttpPost]
[Route("phone/send-signin-code")]
public virtual async Task SendPhoneSigninCodeAsync(SendPhoneSigninCodeDto input)
public async virtual Task SendPhoneSigninCodeAsync(SendPhoneSigninCodeDto input)
{
await AccountAppService.SendPhoneSigninCodeAsync(input);
}
[HttpPost]
[Route("phone/send-register-code")]
public virtual async Task SendPhoneRegisterCodeAsync(SendPhoneRegisterCodeDto input)
public async virtual Task SendPhoneRegisterCodeAsync(SendPhoneRegisterCodeDto input)
{
await AccountAppService.SendPhoneRegisterCodeAsync(input);
}
[HttpPost]
[Route("phone/send-password-reset-code")]
public virtual async Task SendPhoneResetPasswordCodeAsync(SendPhoneResetPasswordCodeDto input)
public async virtual Task SendPhoneResetPasswordCodeAsync(SendPhoneResetPasswordCodeDto input)
{
await AccountAppService.SendPhoneResetPasswordCodeAsync(input);
}

14
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserSetPasswordInput.cs

@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Identity;
public class IdentityUserSetPasswordInput
{
[Required]
[DisableAuditing]
[DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxPasswordLength))]
public string Password { get; set; }
}

3
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs

@ -44,8 +44,7 @@ namespace LINGYUN.Abp.Identity
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
/// TODO: 移除api,改为重置用户密码
// Task ChangePasswordAsync(Guid id, ChangePasswordInput input);
Task ChangePasswordAsync(Guid id, IdentityUserSetPasswordInput input);
/// <summary>
/// 锁定
/// </summary>

1
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissionDefinitionProvider.cs

@ -15,6 +15,7 @@ namespace LINGYUN.Abp.Identity
var userPermission = identityGroup.GetPermissionOrNull(Volo.Abp.Identity.IdentityPermissions.Users.Default);
if (userPermission != null)
{
userPermission.AddChild(IdentityPermissions.Users.ResetPassword, L("Permission:ResetPassword"));
userPermission.AddChild(IdentityPermissions.Users.ManageClaims, L("Permission:ManageClaims"));
userPermission.AddChild(IdentityPermissions.Users.ManageOrganizationUnits, L("Permission:ManageOrganizationUnits"));
}

1
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissions.cs

@ -12,6 +12,7 @@ namespace LINGYUN.Abp.Identity
public static class Users
{
public const string ResetPassword = Volo.Abp.Identity.IdentityPermissions.Users.Default + ".ResetPassword";
public const string ManageClaims = Volo.Abp.Identity.IdentityPermissions.Users.Default + ".ManageClaims";
public const string ManageOrganizationUnits = Volo.Abp.Identity.IdentityPermissions.Users.Default + ".ManageOrganizationUnits";
}

13
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs

@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Volo.Abp;
@ -107,6 +106,18 @@ namespace LINGYUN.Abp.Identity
#endregion
[Authorize(IdentityPermissions.Users.ResetPassword)]
public async virtual Task ChangePasswordAsync(Guid id, IdentityUserSetPasswordInput input)
{
var user = await GetUserAsync(id);
var token = await UserManager.GeneratePasswordResetTokenAsync(user);
(await UserManager.ResetPasswordAsync(user, token, input.Password)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
}
[Authorize(Volo.Abp.Identity.IdentityPermissions.Users.Update)]
public virtual async Task ChangeTwoFactorEnabledAsync(Guid id, TwoFactorEnabledDto input)
{

1
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain.Shared/LINGYUN/Abp/Identity/Localization/en.json

@ -2,6 +2,7 @@
"culture": "en",
"texts": {
"Permission:OrganizationUnitManagement": "Organization unit management",
"Permission:ResetPassword": "Reset Password",
"Permission:ManageRoles": "Management roles",
"Permission:ManageUsers": "Management users",
"Permission:ManageClaims": "Management claims",

1
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain.Shared/LINGYUN/Abp/Identity/Localization/zh-Hans.json

@ -2,6 +2,7 @@
"culture": "zh-Hans",
"texts": {
"Permission:OrganizationUnitManagement": "组织机构管理",
"Permission:ResetPassword": "重置密码",
"Permission:ManageRoles": "管理角色",
"Permission:ManageUsers": "管理用户",
"Permission:ManageClaims": "管理声明",

6
aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IdentityUserController.cs

@ -78,6 +78,12 @@ namespace LINGYUN.Abp.Identity
#endregion
[HttpPut]
[Route("change-password")]
public async virtual Task ChangePasswordAsync(Guid id, IdentityUserSetPasswordInput input)
{
await UserAppService.ChangePasswordAsync(id, input);
}
[HttpPut]
[Route("change-two-factor")]

Loading…
Cancel
Save