From c2f958d0105c9f06c9a4384cae86a7a2d5bc847f Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 9 Jun 2021 17:05:55 +0800 Subject: [PATCH 1/2] Change current tenant when reset password --- .../Pages/Account/ResetPassword.cshtml.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs index c961fe7e14..c0cd463924 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs @@ -58,8 +58,6 @@ namespace Volo.Abp.Account.Web.Pages.Account public virtual Task OnGetAsync() { - //TODO: It would be good to try to switch tenant if needed - CheckCurrentTenant(TenantId); return Task.FromResult(Page()); } @@ -69,14 +67,17 @@ namespace Volo.Abp.Account.Web.Pages.Account try { - await AccountAppService.ResetPasswordAsync( - new ResetPasswordDto - { - UserId = UserId, - ResetToken = ResetToken, - Password = Password - } - ); + using (CurrentTenant.Change(TenantId)) + { + await AccountAppService.ResetPasswordAsync( + new ResetPasswordDto + { + UserId = UserId, + ResetToken = ResetToken, + Password = Password + } + ); + } } catch (AbpIdentityResultException e) { @@ -101,7 +102,8 @@ namespace Volo.Abp.Account.Web.Pages.Account { if (!Equals(Password, ConfirmPassword)) { - ModelState.AddModelError("ConfirmPassword", L["'{0}' and '{1}' do not match.", "ConfirmPassword", "Password"]); + ModelState.AddModelError("ConfirmPassword", + L["'{0}' and '{1}' do not match.", "ConfirmPassword", "Password"]); } base.ValidateModel(); From f843a679b25c2c4fce19195a5292b23c1eefe5d6 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 9 Jun 2021 17:43:52 +0800 Subject: [PATCH 2/2] Add TenantId to ResetPasswordDto --- .../Volo/Abp/Account/ResetPasswordDto.cs | 2 ++ .../Volo/Abp/Account/AccountAppService.cs | 19 ++++++++++-------- .../Pages/Account/ResetPassword.cshtml.cs | 20 +++++++++---------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/ResetPasswordDto.cs b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/ResetPasswordDto.cs index 2423e6c778..695fcfca91 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/ResetPasswordDto.cs +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/ResetPasswordDto.cs @@ -8,6 +8,8 @@ namespace Volo.Abp.Account { public Guid UserId { get; set; } + public Guid? TenantId { get; set; } + [Required] public string ResetToken { get; set; } diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs index 05ff98b35b..22c7e20b54 100644 --- a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs @@ -62,16 +62,19 @@ namespace Volo.Abp.Account public virtual async Task ResetPasswordAsync(ResetPasswordDto input) { - await IdentityOptions.SetAsync(); + using (CurrentTenant.Change(input.TenantId)) + { + await IdentityOptions.SetAsync(); - var user = await UserManager.GetByIdAsync(input.UserId); - (await UserManager.ResetPasswordAsync(user, input.ResetToken, input.Password)).CheckErrors(); + var user = await UserManager.GetByIdAsync(input.UserId); + (await UserManager.ResetPasswordAsync(user, input.ResetToken, input.Password)).CheckErrors(); - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext - { - Identity = IdentitySecurityLogIdentityConsts.Identity, - Action = IdentitySecurityLogActionConsts.ChangePassword - }); + await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext + { + Identity = IdentitySecurityLogIdentityConsts.Identity, + Action = IdentitySecurityLogActionConsts.ChangePassword + }); + } } protected virtual async Task GetUserByEmail(string email) diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs index c0cd463924..6aed769f76 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs @@ -67,17 +67,15 @@ namespace Volo.Abp.Account.Web.Pages.Account try { - using (CurrentTenant.Change(TenantId)) - { - await AccountAppService.ResetPasswordAsync( - new ResetPasswordDto - { - UserId = UserId, - ResetToken = ResetToken, - Password = Password - } - ); - } + await AccountAppService.ResetPasswordAsync( + new ResetPasswordDto + { + UserId = UserId, + ResetToken = ResetToken, + Password = Password, + TenantId = TenantId + } + ); } catch (AbpIdentityResultException e) {