【发布时间】:2019-01-11 22:27:17
【问题描述】:
带有确认逻辑的默认身份更改用户名/电子邮件没有意义。
- 设置应用需要电子邮件确认。
- 设置需要确认的电子邮件才能登录。
- 用户然后更改电子邮件,输入错误的电子邮件,注销。
- 现在用户被锁定。电子邮件已更改但需要 确认登录,没有电子邮件确认链接,因为 地址输入错误。
是我错误地设置了我的应用程序还是 Microsoft 没有很好地设计 Identity?
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
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);
if (Input.Email != email)
{
var setEmailResult = await _userManager.SetEmailAsync(user, Input.Email);
if (!setEmailResult.Succeeded)
{
var userId = await _userManager.GetUserIdAsync(user);
throw new InvalidOperationException($"Unexpected error occurred setting email for user with ID '{userId}'.");
}
StatusMessage = "<strong>Verify your new email</strong><br/><br/>" +
"We sent an email to " + Input.Email +
" to verify your address. Please click the link in that email to continue.";
}
//...
await _signInManager.RefreshSignInAsync(user);
return RedirectToPage();
}
【问题讨论】:
-
您能否编辑您的问题并包含您用于更改电子邮件控制器的代码?在用户确认之前,您不应该实际保存更改的电子邮件地址。
-
@DaImTo 我已经更新了我的问题。它是 identity/pages/account/manage 中 index.cshtml 页面的默认脚手架。
-
默认从哪里来?我会说那是错误的,因为它甚至没有发送构造代码。
-
创建新的 asp.net core web 应用程序(asp.net core 2.2,mvc)。添加身份脚手架。在 Areas/identity/pages/account/manage/Index.cshtml.cs
-
这就是我的意思,它并没有按照您的预期去做。我知道模板只是项目的起点,但我希望用户管理/配置文件/身份代码更加完善。特别是考虑到 asp.net 已经 17 岁了...
标签: asp.net-core asp.net-identity