From 5dfb923c68fe4cc86b5af296449da5c4427c9795 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 17 Oct 2019 13:04:13 -0700 Subject: [PATCH] Flow return url in register confirmation (#15075) --- .../UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp.cs | 4 ++-- .../src/Areas/Identity/Pages/V3/Account/Register.cshtml.cs | 4 ++-- .../Pages/V3/Account/RegisterConfirmation.cshtml.cs | 7 ++++--- .../src/Areas/Identity/Pages/V4/Account/Register.cshtml.cs | 4 ++-- .../Pages/V4/Account/RegisterConfirmation.cshtml.cs | 7 ++++--- .../Identity.FunctionalTests/Pages/Account/Register.cs | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Identity/UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp.cs b/src/Identity/UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp.cs index 946e9c778c..a6f27855f0 100644 --- a/src/Identity/UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp.cs +++ b/src/Identity/UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp.cs @@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal public bool DisplayConfirmAccountLink { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public string Email { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public string EmailConfirmationUrl { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public virtual System.Threading.Tasks.Task OnGetAsync(string email) { throw null; } + public virtual System.Threading.Tasks.Task OnGetAsync(string email, string returnUrl = null) { throw null; } } [Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute] public abstract partial class RegisterModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel @@ -627,7 +627,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal public bool DisplayConfirmAccountLink { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public string Email { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public string EmailConfirmationUrl { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public virtual System.Threading.Tasks.Task OnGetAsync(string email) { throw null; } + public virtual System.Threading.Tasks.Task OnGetAsync(string email, string returnUrl = null) { throw null; } } [Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute] public abstract partial class RegisterModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel diff --git a/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Register.cshtml.cs b/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Register.cshtml.cs index 4b2a418d8a..ade1e60d2a 100644 --- a/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Register.cshtml.cs +++ b/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Register.cshtml.cs @@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, - values: new { area = "Identity", userId = userId, code = code }, + values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal if (_userManager.Options.SignIn.RequireConfirmedAccount) { - return RedirectToPage("RegisterConfirmation", new { email = Input.Email }); + return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }); } else { diff --git a/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/RegisterConfirmation.cshtml.cs b/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/RegisterConfirmation.cshtml.cs index 39db719ff9..0220bb7bd1 100644 --- a/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/RegisterConfirmation.cshtml.cs +++ b/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/RegisterConfirmation.cshtml.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// - public virtual Task OnGetAsync(string email) => throw new NotImplementedException(); + public virtual Task OnGetAsync(string email, string returnUrl = null) => throw new NotImplementedException(); } internal class RegisterConfirmationModel : RegisterConfirmationModel where TUser : class @@ -57,12 +57,13 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal _sender = sender; } - public override async Task OnGetAsync(string email) + public override async Task OnGetAsync(string email, string returnUrl = null) { if (email == null) { return RedirectToPage("/Index"); } + returnUrl = returnUrl ?? Url.Content("~/"); var user = await _userManager.FindByEmailAsync(email); if (user == null) @@ -81,7 +82,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal EmailConfirmationUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, - values: new { area = "Identity", userId = userId, code = code }, + values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); } diff --git a/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Register.cshtml.cs b/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Register.cshtml.cs index 512adeb754..8e2a7e2faf 100644 --- a/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Register.cshtml.cs +++ b/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Register.cshtml.cs @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, - values: new { area = "Identity", userId = userId, code = code }, + values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal if (_userManager.Options.SignIn.RequireConfirmedAccount) { - return RedirectToPage("RegisterConfirmation", new { email = Input.Email }); + return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }); } else { diff --git a/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/RegisterConfirmation.cshtml.cs b/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/RegisterConfirmation.cshtml.cs index aa32c17361..7b88864fa0 100644 --- a/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/RegisterConfirmation.cshtml.cs +++ b/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/RegisterConfirmation.cshtml.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// - public virtual Task OnGetAsync(string email) => throw new NotImplementedException(); + public virtual Task OnGetAsync(string email, string returnUrl = null) => throw new NotImplementedException(); } internal class RegisterConfirmationModel : RegisterConfirmationModel where TUser : class @@ -57,12 +57,13 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal _sender = sender; } - public override async Task OnGetAsync(string email) + public override async Task OnGetAsync(string email, string returnUrl = null) { if (email == null) { return RedirectToPage("/Index"); } + returnUrl = returnUrl ?? Url.Content("~/"); var user = await _userManager.FindByEmailAsync(email); if (user == null) @@ -81,7 +82,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal EmailConfirmationUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, - values: new { area = "Identity", userId = userId, code = code }, + values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); } diff --git a/src/Identity/test/Identity.FunctionalTests/Pages/Account/Register.cs b/src/Identity/test/Identity.FunctionalTests/Pages/Account/Register.cs index cbddb15df4..52d883cbf1 100644 --- a/src/Identity/test/Identity.FunctionalTests/Pages/Account/Register.cs +++ b/src/Identity/test/Identity.FunctionalTests/Pages/Account/Register.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account }); var registeredLocation = ResponseAssert.IsRedirect(registered); - Assert.Equal(RegisterConfirmation.Path + "?email="+userName, registeredLocation.ToString()); + Assert.Equal(RegisterConfirmation.Path + "?email="+userName+"&returnUrl=%2F", registeredLocation.ToString()); var registerResponse = await Client.GetAsync(registeredLocation); var register = await ResponseAssert.IsHtmlDocumentAsync(registerResponse);