Browse Source

Localized exception message in pages.

pull/7321/head
maliming 6 years ago
parent
commit
cc1c1d3cd1
  1. 4
      modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs
  2. 14
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs
  3. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/ForgotPassword.cshtml.cs
  4. 4
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
  5. 2
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs

4
modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs

@ -8,6 +8,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation;
@ -19,7 +20,8 @@ namespace Volo.Abp.Account.Web
typeof(AbpAccountHttpApiModule), typeof(AbpAccountHttpApiModule),
typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityAspNetCoreModule),
typeof(AbpAutoMapperModule), typeof(AbpAutoMapperModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule) typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpExceptionHandlingModule)
)] )]
public class AbpAccountWebModule : AbpModule public class AbpAccountWebModule : AbpModule
{ {

14
modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs

@ -2,10 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Account.Localization; using Volo.Abp.Account.Localization;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using IdentityUser = Volo.Abp.Identity.IdentityUser; using IdentityUser = Volo.Abp.Identity.IdentityUser;
@ -18,6 +19,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
public IdentityUserManager UserManager { get; set; } public IdentityUserManager UserManager { get; set; }
public IdentitySecurityLogManager IdentitySecurityLogManager { get; set; } public IdentitySecurityLogManager IdentitySecurityLogManager { get; set; }
public IOptions<IdentityOptions> IdentityOptions { get; set; } public IOptions<IdentityOptions> IdentityOptions { get; set; }
public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; set; }
protected AccountPageModel() protected AccountPageModel()
{ {
@ -42,5 +44,15 @@ namespace Volo.Abp.Account.Web.Pages.Account
throw new ApplicationException($"Current tenant is different than given tenant. CurrentTenant.Id: {CurrentTenant.Id}, given tenantId: {tenantId}"); throw new ApplicationException($"Current tenant is different than given tenant. CurrentTenant.Id: {CurrentTenant.Id}, given tenantId: {tenantId}");
} }
} }
protected virtual string GetLocalizeExceptionMessage(Exception exception)
{
if (exception is ILocalizeErrorMessage || exception is IHasErrorCode)
{
return ExceptionToErrorInfoConverter.Convert(exception, false).Message;
}
return exception.Message;
}
} }
} }

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/ForgotPassword.cshtml.cs

@ -43,7 +43,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
} }
catch (UserFriendlyException e) catch (UserFriendlyException e)
{ {
Alerts.Danger(e.Message); Alerts.Danger(GetLocalizeExceptionMessage(e));
return Page(); return Page();
} }

4
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs

@ -1,8 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -100,7 +98,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
} }
catch (BusinessException e) catch (BusinessException e)
{ {
Alerts.Danger(e.Message); Alerts.Danger(GetLocalizeExceptionMessage(e));
return Page(); return Page();
} }
} }

2
modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs

@ -82,7 +82,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
{ {
if (!string.IsNullOrWhiteSpace(e.Message)) if (!string.IsNullOrWhiteSpace(e.Message))
{ {
Alerts.Warning(e.Message); Alerts.Warning(GetLocalizeExceptionMessage(e));
return Page(); return Page();
} }

Loading…
Cancel
Save