Skip to content

Commit 5dfb923

Browse files
authored
Flow return url in register confirmation (#15075)
1 parent 60ace9d commit 5dfb923

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

src/Identity/UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public RegisterConfirmationModel() { }
177177
public bool DisplayConfirmAccountLink { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
178178
public string Email { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
179179
public string EmailConfirmationUrl { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
180-
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync(string email) { throw null; }
180+
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync(string email, string returnUrl = null) { throw null; }
181181
}
182182
[Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute]
183183
public abstract partial class RegisterModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel
@@ -627,7 +627,7 @@ public RegisterConfirmationModel() { }
627627
public bool DisplayConfirmAccountLink { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
628628
public string Email { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
629629
public string EmailConfirmationUrl { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
630-
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync(string email) { throw null; }
630+
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync(string email, string returnUrl = null) { throw null; }
631631
}
632632
[Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute]
633633
public abstract partial class RegisterModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel

src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Register.cshtml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ public override async Task<IActionResult> OnPostAsync(string returnUrl = null)
147147
var callbackUrl = Url.Page(
148148
"/Account/ConfirmEmail",
149149
pageHandler: null,
150-
values: new { area = "Identity", userId = userId, code = code },
150+
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
151151
protocol: Request.Scheme);
152152

153153
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
154154
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
155155

156156
if (_userManager.Options.SignIn.RequireConfirmedAccount)
157157
{
158-
return RedirectToPage("RegisterConfirmation", new { email = Input.Email });
158+
return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
159159
}
160160
else
161161
{

src/Identity/UI/src/Areas/Identity/Pages/V3/Account/RegisterConfirmation.cshtml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RegisterConfirmationModel : PageModel
4343
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
4444
/// directly from your code. This API may change or be removed in future releases.
4545
/// </summary>
46-
public virtual Task<IActionResult> OnGetAsync(string email) => throw new NotImplementedException();
46+
public virtual Task<IActionResult> OnGetAsync(string email, string returnUrl = null) => throw new NotImplementedException();
4747
}
4848

4949
internal class RegisterConfirmationModel<TUser> : RegisterConfirmationModel where TUser : class
@@ -57,12 +57,13 @@ public RegisterConfirmationModel(UserManager<TUser> userManager, IEmailSender se
5757
_sender = sender;
5858
}
5959

60-
public override async Task<IActionResult> OnGetAsync(string email)
60+
public override async Task<IActionResult> OnGetAsync(string email, string returnUrl = null)
6161
{
6262
if (email == null)
6363
{
6464
return RedirectToPage("/Index");
6565
}
66+
returnUrl = returnUrl ?? Url.Content("~/");
6667

6768
var user = await _userManager.FindByEmailAsync(email);
6869
if (user == null)
@@ -81,7 +82,7 @@ public override async Task<IActionResult> OnGetAsync(string email)
8182
EmailConfirmationUrl = Url.Page(
8283
"/Account/ConfirmEmail",
8384
pageHandler: null,
84-
values: new { area = "Identity", userId = userId, code = code },
85+
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
8586
protocol: Request.Scheme);
8687
}
8788

src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Register.cshtml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ public override async Task<IActionResult> OnPostAsync(string returnUrl = null)
146146
var callbackUrl = Url.Page(
147147
"/Account/ConfirmEmail",
148148
pageHandler: null,
149-
values: new { area = "Identity", userId = userId, code = code },
149+
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
150150
protocol: Request.Scheme);
151151

152152
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
153153
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
154154

155155
if (_userManager.Options.SignIn.RequireConfirmedAccount)
156156
{
157-
return RedirectToPage("RegisterConfirmation", new { email = Input.Email });
157+
return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
158158
}
159159
else
160160
{

src/Identity/UI/src/Areas/Identity/Pages/V4/Account/RegisterConfirmation.cshtml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RegisterConfirmationModel : PageModel
4343
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
4444
/// directly from your code. This API may change or be removed in future releases.
4545
/// </summary>
46-
public virtual Task<IActionResult> OnGetAsync(string email) => throw new NotImplementedException();
46+
public virtual Task<IActionResult> OnGetAsync(string email, string returnUrl = null) => throw new NotImplementedException();
4747
}
4848

4949
internal class RegisterConfirmationModel<TUser> : RegisterConfirmationModel where TUser : class
@@ -57,12 +57,13 @@ public RegisterConfirmationModel(UserManager<TUser> userManager, IEmailSender se
5757
_sender = sender;
5858
}
5959

60-
public override async Task<IActionResult> OnGetAsync(string email)
60+
public override async Task<IActionResult> OnGetAsync(string email, string returnUrl = null)
6161
{
6262
if (email == null)
6363
{
6464
return RedirectToPage("/Index");
6565
}
66+
returnUrl = returnUrl ?? Url.Content("~/");
6667

6768
var user = await _userManager.FindByEmailAsync(email);
6869
if (user == null)
@@ -81,7 +82,7 @@ public override async Task<IActionResult> OnGetAsync(string email)
8182
EmailConfirmationUrl = Url.Page(
8283
"/Account/ConfirmEmail",
8384
pageHandler: null,
84-
values: new { area = "Identity", userId = userId, code = code },
85+
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
8586
protocol: Request.Scheme);
8687
}
8788

src/Identity/test/Identity.FunctionalTests/Pages/Account/Register.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public async Task<RegisterConfirmation> SubmitRegisterFormWithConfirmation(strin
6464
});
6565

6666
var registeredLocation = ResponseAssert.IsRedirect(registered);
67-
Assert.Equal(RegisterConfirmation.Path + "?email="+userName, registeredLocation.ToString());
67+
Assert.Equal(RegisterConfirmation.Path + "?email="+userName+"&returnUrl=%2F", registeredLocation.ToString());
6868
var registerResponse = await Client.GetAsync(registeredLocation);
6969
var register = await ResponseAssert.IsHtmlDocumentAsync(registerResponse);
7070

0 commit comments

Comments
 (0)