From 5e0bf84f5843e242dcf46472651d8402603d2273 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Tue, 28 Jul 2020 09:49:25 +0800 Subject: [PATCH] Use alerts to show the exception message in the register page. Fix #4896 --- .../Pages/Account/Register.cshtml.cs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs index f6d626dd63d..66e938d48d3 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs @@ -1,3 +1,4 @@ +using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; @@ -43,24 +44,30 @@ public virtual async Task OnPostAsync() { ValidateModel(); - await CheckSelfRegistrationAsync(); - - var registerDto = new RegisterDto + try { - AppName = "MVC", - EmailAddress = Input.EmailAddress, - Password = Input.Password, - UserName = Input.UserName - }; + await CheckSelfRegistrationAsync(); - var userDto = await AccountAppService.RegisterAsync(registerDto); - var user = await UserManager.GetByIdAsync(userDto.Id); + var registerDto = new RegisterDto + { + AppName = "MVC", + EmailAddress = Input.EmailAddress, + Password = Input.Password, + UserName = Input.UserName + }; - await UserManager.SetEmailAsync(user, Input.EmailAddress); + var userDto = await AccountAppService.RegisterAsync(registerDto); + var user = await UserManager.GetByIdAsync(userDto.Id); - await SignInManager.SignInAsync(user, isPersistent: false); + await SignInManager.SignInAsync(user, isPersistent: false); - return Redirect(ReturnUrl ?? "~/"); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow! + return Redirect(ReturnUrl ?? "~/"); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow! + } + catch (BusinessException e) + { + Alerts.Danger(e.Message); + return Page(); + } } protected virtual async Task CheckSelfRegistrationAsync()