Skip to content

Commit 0c68be0

Browse files
committed
PR tweaks
1 parent 6555be2 commit 0c68be0

File tree

9 files changed

+28
-24
lines changed

9 files changed

+28
-24
lines changed

src/Identity/UI/ref/Microsoft.AspNetCore.Identity.UI.netcoreapp3.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public partial class RegisterConfirmationModel : Microsoft.AspNetCore.Mvc.RazorP
177177
public RegisterConfirmationModel() { }
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 bool IsDevelopment { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
180+
public bool DisplayConfirmAccountLink { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
181181
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync(string email) { throw null; }
182182
}
183183
[Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute]
@@ -623,7 +623,7 @@ public partial class RegisterConfirmationModel : Microsoft.AspNetCore.Mvc.RazorP
623623
public RegisterConfirmationModel() { }
624624
public string Email { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
625625
public string EmailConfirmationUrl { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
626-
public bool IsDevelopment { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
626+
public bool DisplayConfirmAccountLink { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
627627
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync(string email) { throw null; }
628628
}
629629
[Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute]

src/Identity/UI/src/Areas/Identity/Pages/V3/Account/Manage/Email.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ await _emailSender.SendEmailAsync(
144144
"Confirm your email",
145145
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
146146

147-
StatusMessage = "Confirmation link to change email sent. Please check your email." + callbackUrl;
147+
StatusMessage = "Confirmation link to change email sent. Please check your email.";
148148
return RedirectToPage();
149149
}
150150

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<h2>@ViewData["Title"]</h2>
88
@{
9-
if (@Model.IsDevelopment)
9+
if (@Model.DisplayConfirmAccountLink)
1010
{
1111
<p>
12-
In development we provide an inline email confirmation link, see <a href="https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm">these docs</a> for how to configure a real email provider.
13-
<a href="@Model.EmailConfirmationUrl">Click here to confirm your account</a>
12+
This app does not currently have a real email sender registered, see <a href="https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm">these docs</a> for how to configure a real email sender.
13+
Normally this would be emailed: <a href="@Model.EmailConfirmationUrl">Click here to confirm your account</a>
1414
</p>
1515
}
1616
else

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Authorization;
77
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Identity.UI.Services;
89
using Microsoft.AspNetCore.Mvc;
910
using Microsoft.AspNetCore.Mvc.RazorPages;
1011
using Microsoft.Extensions.Hosting;
@@ -30,7 +31,7 @@ public class RegisterConfirmationModel : PageModel
3031
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
3132
/// directly from your code. This API may change or be removed in future releases.
3233
/// </summary>
33-
public bool IsDevelopment { get; set; }
34+
public bool DisplayConfirmAccountLink { get; set; }
3435

3536
/// <summary>
3637
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
@@ -49,11 +50,13 @@ internal class RegisterConfirmationModel<TUser> : RegisterConfirmationModel wher
4950
{
5051
private readonly UserManager<TUser> _userManager;
5152
private readonly IWebHostEnvironment _hostingEnv;
53+
private readonly IEmailSender _sender;
5254

53-
public RegisterConfirmationModel(UserManager<TUser> userManager, IWebHostEnvironment hostingEnv)
55+
public RegisterConfirmationModel(UserManager<TUser> userManager, IWebHostEnvironment hostingEnv, IEmailSender sender)
5456
{
5557
_userManager = userManager;
5658
_hostingEnv = hostingEnv;
59+
_sender = sender;
5760
}
5861

5962
public override async Task<IActionResult> OnGetAsync(string email)
@@ -70,9 +73,9 @@ public override async Task<IActionResult> OnGetAsync(string email)
7073
}
7174

7275
Email = email;
73-
IsDevelopment = _hostingEnv.IsDevelopment();
74-
75-
if (IsDevelopment)
76+
// This sender is a no-op, so we should auto confirm the account
77+
DisplayConfirmAccountLink = _sender is EmailSender;
78+
if (DisplayConfirmAccountLink)
7679
{
7780
var userId = await _userManager.GetUserIdAsync(user);
7881
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.AspNetCore.Mvc.RazorPages;
99

1010
namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal
11-
1211
{
1312
/// <summary>
1413
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
@@ -52,7 +51,8 @@ public override async Task<IActionResult> OnGetAsync(string userId, string email
5251
var result = await _userManager.ChangeEmailAsync(user, email, code);
5352
if (!result.Succeeded)
5453
{
55-
throw new InvalidOperationException($"Error changing email for user with ID '{userId}':");
54+
ModelState.AddModelError(string.Empty, "Change email failed.");
55+
return Page();
5656
}
5757

5858
// In our UI email and user name are one and the same, so when we update the email

src/Identity/UI/src/Areas/Identity/Pages/V4/Account/Manage/Email.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ await _emailSender.SendEmailAsync(
144144
"Confirm your email",
145145
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
146146

147-
StatusMessage = "Confirmation link to change email sent. Please check your email." + callbackUrl;
147+
StatusMessage = "Confirmation link to change email sent. Please check your email.";
148148
return RedirectToPage();
149149
}
150150

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
<h2>@ViewData["Title"]</h2>
88
@{
9-
if (@Model.IsDevelopment)
9+
if (@Model.DisplayConfirmAccountLink)
1010
{
1111
<p>
12-
In development we provide an inline email confirmation link, see <a href="https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm">these docs</a> for how to configure a real email provider.
13-
<a href="@Model.EmailConfirmationUrl">Click here to confirm your account</a>
12+
This app does not currently have a real email sender registered, see <a href="https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm">these docs</a> for how to configure a real email sender.
13+
Normally this would be emailed: <a href="@Model.EmailConfirmationUrl">Click here to confirm your account</a>
1414
</p>
1515
}
1616
else

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Authorization;
77
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Identity.UI.Services;
89
using Microsoft.AspNetCore.Mvc;
910
using Microsoft.AspNetCore.Mvc.RazorPages;
1011
using Microsoft.Extensions.Hosting;
@@ -30,7 +31,7 @@ public class RegisterConfirmationModel : PageModel
3031
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
3132
/// directly from your code. This API may change or be removed in future releases.
3233
/// </summary>
33-
public bool IsDevelopment { get; set; }
34+
public bool DisplayConfirmAccountLink { get; set; }
3435

3536
/// <summary>
3637
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
@@ -49,11 +50,13 @@ internal class RegisterConfirmationModel<TUser> : RegisterConfirmationModel wher
4950
{
5051
private readonly UserManager<TUser> _userManager;
5152
private readonly IWebHostEnvironment _hostingEnv;
53+
private readonly IEmailSender _sender;
5254

53-
public RegisterConfirmationModel(UserManager<TUser> userManager, IWebHostEnvironment hostingEnv)
55+
public RegisterConfirmationModel(UserManager<TUser> userManager, IWebHostEnvironment hostingEnv, IEmailSender sender)
5456
{
5557
_userManager = userManager;
5658
_hostingEnv = hostingEnv;
59+
_sender = sender;
5760
}
5861

5962
public override async Task<IActionResult> OnGetAsync(string email)
@@ -70,9 +73,9 @@ public override async Task<IActionResult> OnGetAsync(string email)
7073
}
7174

7275
Email = email;
73-
IsDevelopment = _hostingEnv.IsDevelopment();
74-
75-
if (IsDevelopment)
76+
// This sender is a no-op, so we should auto confirm the account
77+
DisplayConfirmAccountLink = _sender is EmailSender;
78+
if (DisplayConfirmAccountLink)
7679
{
7780
var userId = await _userManager.GetUserIdAsync(user);
7881
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

src/Identity/samples/IdentitySample.DefaultUI/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public void ConfigureServices(IServiceCollection services)
4949
services.AddDefaultIdentity<ApplicationUser>(o => o.SignIn.RequireConfirmedAccount = true)
5050
.AddRoles<IdentityRole>()
5151
.AddEntityFrameworkStores<ApplicationDbContext>();
52-
53-
//services.AddSingleton<IUserConfirmation<ApplicationUser>, BadDude>();
5452
}
5553

5654

0 commit comments

Comments
 (0)