From d20d34585213aecf13ac1fc60736fb0a0eca7a1e Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 12 Oct 2020 16:10:43 +0800 Subject: [PATCH] Show the error message when typing the wrong email --- .../Account/Localization/Resources/en.json | 3 ++- .../Account/Localization/Resources/sl.json | 3 ++- .../Account/Localization/Resources/tr.json | 3 ++- .../Localization/Resources/zh-Hans.json | 5 +++- .../Volo/Abp/Account/AccountAppService.cs | 8 +++--- .../Pages/Account/ForgotPassword.cshtml.cs | 27 ++++++++++++------- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json index 51abf72a1e..db38b70309 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json @@ -56,6 +56,7 @@ "BackToLogin": "Back to login", "ProfileTab:Password": "Change password", "ProfileTab:PersonalInfo": "Personal info", - "ReturnToApplication": "Return to application" + "ReturnToApplication": "Return to application", + "Volo.Account:InvalidEmailAddress": "Can not find the given email address: {0}" } } diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/sl.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/sl.json index 747cc752c7..4cd3d801fc 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/sl.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/sl.json @@ -48,6 +48,7 @@ "ConfirmPassword": "Potrditev (ponovitev) gesla", "ResetPassword_Information": "Prosimo vnesite vaše novo geslo.", "YourPasswordIsSuccessfullyReset": "Vaše geslo je uspešno ponastavljeno.", - "BackToLogin": "Nazaj na prijavo" + "BackToLogin": "Nazaj na prijavo", + "Volo.Account:InvalidEmailAddress": "Navedenega e-poštnega naslova ni mogoče najti: {0}" } } diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/tr.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/tr.json index 48e43fd6cc..9f8e765759 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/tr.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/tr.json @@ -56,6 +56,7 @@ "BackToLogin": "Girişe dön", "ProfileTab:Password": "Şifre değiştir", "ProfileTab:PersonalInfo": "Kişisel bilgiler", - "ReturnToApplication": "Uygulamaya geri dön" + "ReturnToApplication": "Uygulamaya geri dön", + "Volo.Account:InvalidEmailAddress": "Email adresi bulunamadı: {0}" } } diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json index 340fe95f74..93174b979d 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json @@ -55,6 +55,9 @@ "BackToLogin": "返回登录", "ProfileTab:Password": "更改密码", "ProfileTab:PersonalInfo": "个人信息", - "ReturnToApplication": "返回到应用程序" + "ReturnToApplication": "返回到应用程序", + "Volo.Account:InvalidEmailAddress": "找不到给定的电子邮件地址:{0}", + "Volo.Account:SelfRegistrationDisabled": "自我注册已禁用!", + } } 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 066ce47f64..ac3c6c2735 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 @@ -1,7 +1,7 @@ -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Volo.Abp.Account.Emailing; +using Volo.Abp.Account.Localization; using Volo.Abp.Account.Settings; using Volo.Abp.Application.Services; using Volo.Abp.Identity; @@ -26,6 +26,7 @@ namespace Volo.Abp.Account AccountEmailer = accountEmailer; IdentitySecurityLogManager = identitySecurityLogManager; UserManager = userManager; + LocalizationResource = typeof(AccountResource); } public virtual async Task RegisterAsync(RegisterDto input) @@ -66,8 +67,7 @@ namespace Volo.Abp.Account var user = await UserManager.FindByEmailAsync(email); if (user == null) { - throw new BusinessException("Volo.Account:InvalidEmailAddress") - .WithData("Email", email); + throw new UserFriendlyException(L["Volo.Account:InvalidEmailAddress", email]); } return user; diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ForgotPassword.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ForgotPassword.cshtml.cs index 1f426fa80f..b66b53c913 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ForgotPassword.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/ForgotPassword.cshtml.cs @@ -29,15 +29,24 @@ namespace Volo.Abp.Account.Web.Pages.Account public virtual async Task OnPostAsync() { - await AccountAppService.SendPasswordResetCodeAsync( - new SendPasswordResetCodeDto - { - Email = Email, - AppName = "MVC", //TODO: Const! - ReturnUrl = ReturnUrl, - ReturnUrlHash = ReturnUrlHash - } - ); + try + { + await AccountAppService.SendPasswordResetCodeAsync( + new SendPasswordResetCodeDto + { + Email = Email, + AppName = "MVC", //TODO: Const! + ReturnUrl = ReturnUrl, + ReturnUrlHash = ReturnUrlHash + } + ); + } + catch (UserFriendlyException e) + { + Alerts.Danger(e.Message); + return Page(); + } + return RedirectToPage( "./PasswordResetLinkSent",