Identity UI fixes (#11768)
This commit is contained in:
parent
775314b142
commit
79283cf2de
|
|
@ -314,7 +314,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
[Microsoft.AspNetCore.Mvc.TempDataAttribute]
|
[Microsoft.AspNetCore.Mvc.TempDataAttribute]
|
||||||
public string StatusMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public string StatusMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync() { throw null; }
|
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync() { throw null; }
|
||||||
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostAsync() { throw null; }
|
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostChangeEmailAsync() { throw null; }
|
||||||
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostSendVerificationEmailAsync() { throw null; }
|
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostSendVerificationEmailAsync() { throw null; }
|
||||||
public partial class InputModel
|
public partial class InputModel
|
||||||
{
|
{
|
||||||
|
|
@ -764,7 +764,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
[Microsoft.AspNetCore.Mvc.TempDataAttribute]
|
[Microsoft.AspNetCore.Mvc.TempDataAttribute]
|
||||||
public string StatusMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public string StatusMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync() { throw null; }
|
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetAsync() { throw null; }
|
||||||
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostAsync() { throw null; }
|
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostChangeEmailAsync() { throw null; }
|
||||||
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostSendVerificationEmailAsync() { throw null; }
|
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult> OnPostSendVerificationEmailAsync() { throw null; }
|
||||||
public partial class InputModel
|
public partial class InputModel
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmail",
|
"/Account/ConfirmEmail",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, code = code },
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ResetPassword",
|
"/Account/ResetPassword",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { code },
|
values: new { area = "Identity", code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(
|
await _emailSender.SendEmailAsync(
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
<input asp-for="Input.NewEmail" class="form-control" />
|
<input asp-for="Input.NewEmail" class="form-control" />
|
||||||
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
|
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<button id="change-email-button" type="submit" class="btn btn-default">Change email</button>
|
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="btn btn-default">Change email</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
/// 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.
|
/// directly from your code. This API may change or be removed in future releases.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Task<IActionResult> OnPostAsync() => throw new NotImplementedException();
|
public virtual Task<IActionResult> OnPostChangeEmailAsync() => throw new NotImplementedException();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
||||||
|
|
@ -98,15 +98,9 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
_emailSender = emailSender;
|
_emailSender = emailSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnGetAsync()
|
private async Task LoadAsync(TUser user)
|
||||||
{
|
{
|
||||||
var user = await _userManager.GetUserAsync(User);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
}
|
|
||||||
var email = await _userManager.GetEmailAsync(user);
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
|
|
||||||
Email = email;
|
Email = email;
|
||||||
|
|
||||||
Input = new InputModel
|
Input = new InputModel
|
||||||
|
|
@ -115,23 +109,34 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
};
|
};
|
||||||
|
|
||||||
IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
|
IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnPostAsync()
|
public override async Task<IActionResult> OnGetAsync()
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _userManager.GetUserAsync(User);
|
var user = await _userManager.GetUserAsync(User);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<IActionResult> OnPostChangeEmailAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
var email = await _userManager.GetEmailAsync(user);
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
if (Input.NewEmail != email)
|
if (Input.NewEmail != email)
|
||||||
{
|
{
|
||||||
|
|
@ -141,7 +146,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmailChange",
|
"/Account/ConfirmEmailChange",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, email = Input.NewEmail, code = code },
|
values: new { area = "Identity", userId = userId, email = Input.NewEmail, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
await _emailSender.SendEmailAsync(
|
await _emailSender.SendEmailAsync(
|
||||||
Input.NewEmail,
|
Input.NewEmail,
|
||||||
|
|
@ -172,10 +177,14 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
var userId = await _userManager.GetUserIdAsync(user);
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
var email = await _userManager.GetEmailAsync(user);
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
while (code.Contains('+'))
|
||||||
|
{
|
||||||
|
code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
}
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmail",
|
"/Account/ConfirmEmail",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, code = code },
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
await _emailSender.SendEmailAsync(
|
await _emailSender.SendEmailAsync(
|
||||||
email,
|
email,
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,8 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
|
var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
var userId = await _userManager.GetUserIdAsync(user);
|
StatusMessage = "The external login was not removed.";
|
||||||
throw new InvalidOperationException($"Unexpected error occurred removing external login for user with ID '{userId}'.");
|
return RedirectToPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
|
@ -157,7 +157,8 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
var result = await _userManager.AddLoginAsync(user, info);
|
var result = await _userManager.AddLoginAsync(user, info);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Unexpected error occurred adding external login for user with ID '{userId}'.");
|
StatusMessage = "The external login was not added. External logins can only be associated with one account.";
|
||||||
|
return RedirectToPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the existing external cookie to ensure a clean login process
|
// Clear the existing external cookie to ensure a clean login process
|
||||||
|
|
|
||||||
|
|
@ -77,13 +77,8 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
_signInManager = signInManager;
|
_signInManager = signInManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnGetAsync()
|
private async Task LoadAsync(TUser user)
|
||||||
{
|
{
|
||||||
var user = await _userManager.GetUserAsync(User);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
}
|
|
||||||
var userName = await _userManager.GetUserNameAsync(user);
|
var userName = await _userManager.GetUserNameAsync(user);
|
||||||
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
||||||
|
|
||||||
|
|
@ -93,31 +88,42 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Manage.Internal
|
||||||
{
|
{
|
||||||
PhoneNumber = phoneNumber
|
PhoneNumber = phoneNumber
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await LoadAsync(user);
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnPostAsync()
|
public override async Task<IActionResult> OnPostAsync()
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _userManager.GetUserAsync(User);
|
var user = await _userManager.GetUserAsync(User);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
||||||
if (Input.PhoneNumber != phoneNumber)
|
if (Input.PhoneNumber != phoneNumber)
|
||||||
{
|
{
|
||||||
var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
|
var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
|
||||||
if (!setPhoneResult.Succeeded)
|
if (!setPhoneResult.Succeeded)
|
||||||
{
|
{
|
||||||
var userId = await _userManager.GetUserIdAsync(user);
|
StatusMessage = "Unexpected error when trying to set phone number.";
|
||||||
throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
|
return RedirectToPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmail",
|
"/Account/ConfirmEmail",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, code = code },
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmail",
|
"/Account/ConfirmEmail",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, code = code },
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ResetPassword",
|
"/Account/ResetPassword",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { code },
|
values: new { area = "Identity", code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(
|
await _emailSender.SendEmailAsync(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page
|
@page
|
||||||
@model DeletePersonalDataModel
|
@model DeletePersonalDataModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Delete Personal Data";
|
ViewData["Title"] = "Delete Personal Data";
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<p>
|
<p>
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
|
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@page
|
@page
|
||||||
@model Disable2faModel
|
@model Disable2faModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Disable two-factor authentication (2FA)";
|
ViewData["Title"] = "Disable two-factor authentication (2FA)";
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<p>
|
<p>
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>This action only disables 2FA.</strong>
|
<strong>This action only disables 2FA.</strong>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
{
|
{
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input asp-for="Email" class="form-control" disabled />
|
<input asp-for="Email" class="form-control" disabled />
|
||||||
<span class="input-group-addon" aria-hidden="true"><span class="glyphicon glyphicon-ok text-success"></span></span>
|
<div class="input-group-append">
|
||||||
|
<span class="input-group-text text-success font-weight-bold">✓</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -31,7 +33,7 @@
|
||||||
<input asp-for="Input.NewEmail" class="form-control" />
|
<input asp-for="Input.NewEmail" class="form-control" />
|
||||||
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
|
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<button id="change-email-button" type="submit" class="btn btn-primary">Change email</button>
|
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="btn btn-primary">Change email</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
/// 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.
|
/// directly from your code. This API may change or be removed in future releases.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Task<IActionResult> OnPostAsync() => throw new NotImplementedException();
|
public virtual Task<IActionResult> OnPostChangeEmailAsync() => throw new NotImplementedException();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
|
||||||
|
|
@ -97,15 +97,9 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
_emailSender = emailSender;
|
_emailSender = emailSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnGetAsync()
|
private async Task LoadAsync(TUser user)
|
||||||
{
|
{
|
||||||
var user = await _userManager.GetUserAsync(User);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
}
|
|
||||||
var email = await _userManager.GetEmailAsync(user);
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
|
|
||||||
Email = email;
|
Email = email;
|
||||||
|
|
||||||
Input = new InputModel
|
Input = new InputModel
|
||||||
|
|
@ -114,23 +108,34 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
};
|
};
|
||||||
|
|
||||||
IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
|
IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnPostAsync()
|
public override async Task<IActionResult> OnGetAsync()
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _userManager.GetUserAsync(User);
|
var user = await _userManager.GetUserAsync(User);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<IActionResult> OnPostChangeEmailAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
var email = await _userManager.GetEmailAsync(user);
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
if (Input.NewEmail != email)
|
if (Input.NewEmail != email)
|
||||||
{
|
{
|
||||||
|
|
@ -140,7 +145,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmailChange",
|
"/Account/ConfirmEmailChange",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, email = Input.NewEmail, code = code },
|
values: new { area = "Identity", userId = userId, email = Input.NewEmail, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
await _emailSender.SendEmailAsync(
|
await _emailSender.SendEmailAsync(
|
||||||
Input.NewEmail,
|
Input.NewEmail,
|
||||||
|
|
@ -157,24 +162,26 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
|
|
||||||
public override async Task<IActionResult> OnPostSendVerificationEmailAsync()
|
public override async Task<IActionResult> OnPostSendVerificationEmailAsync()
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _userManager.GetUserAsync(User);
|
var user = await _userManager.GetUserAsync(User);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
var userId = await _userManager.GetUserIdAsync(user);
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
var email = await _userManager.GetEmailAsync(user);
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmail",
|
"/Account/ConfirmEmail",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, code = code },
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
await _emailSender.SendEmailAsync(
|
await _emailSender.SendEmailAsync(
|
||||||
email,
|
email,
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,8 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
|
var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
var userId = await _userManager.GetUserIdAsync(user);
|
StatusMessage = "The external login was not removed.";
|
||||||
throw new InvalidOperationException($"Unexpected error occurred removing external login for user with ID '{userId}'.");
|
return RedirectToPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
|
@ -157,7 +157,8 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
var result = await _userManager.AddLoginAsync(user, info);
|
var result = await _userManager.AddLoginAsync(user, info);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Unexpected error occurred adding external login for user with ID '{userId}'.");
|
StatusMessage = "The external login was not added. External logins can only be associated with one account.";
|
||||||
|
return RedirectToPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the existing external cookie to ensure a clean login process
|
// Clear the existing external cookie to ensure a clean login process
|
||||||
|
|
|
||||||
|
|
@ -79,13 +79,8 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
_signInManager = signInManager;
|
_signInManager = signInManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnGetAsync()
|
private async Task LoadAsync(TUser user)
|
||||||
{
|
{
|
||||||
var user = await _userManager.GetUserAsync(User);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
}
|
|
||||||
var userName = await _userManager.GetUserNameAsync(user);
|
var userName = await _userManager.GetUserNameAsync(user);
|
||||||
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
||||||
|
|
||||||
|
|
@ -95,31 +90,42 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
||||||
{
|
{
|
||||||
PhoneNumber = phoneNumber
|
PhoneNumber = phoneNumber
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await LoadAsync(user);
|
||||||
return Page();
|
return Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IActionResult> OnPostAsync()
|
public override async Task<IActionResult> OnPostAsync()
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _userManager.GetUserAsync(User);
|
var user = await _userManager.GetUserAsync(User);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
||||||
if (Input.PhoneNumber != phoneNumber)
|
if (Input.PhoneNumber != phoneNumber)
|
||||||
{
|
{
|
||||||
var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
|
var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
|
||||||
if (!setPhoneResult.Succeeded)
|
if (!setPhoneResult.Succeeded)
|
||||||
{
|
{
|
||||||
var userId = await _userManager.GetUserIdAsync(user);
|
StatusMessage = "Unexpected error when trying to set phone number.";
|
||||||
throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
|
return RedirectToPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
<h4>@ViewData["Title"]</h4>
|
<h4>@ViewData["Title"]</h4>
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<p>
|
<p>
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>Put these codes in a safe place.</strong>
|
<strong>Put these codes in a safe place.</strong>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal
|
||||||
var callbackUrl = Url.Page(
|
var callbackUrl = Url.Page(
|
||||||
"/Account/ConfirmEmail",
|
"/Account/ConfirmEmail",
|
||||||
pageHandler: null,
|
pageHandler: null,
|
||||||
values: new { userId = userId, code = code },
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
protocol: Request.Scheme);
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue